Shadows cs 446 real time rendering game technology
1 / 28

Shadows CS 446: Real-Time Rendering & Game Technology - PowerPoint PPT Presentation

  • Uploaded on

Shadows CS 446: Real-Time Rendering & Game Technology. David Luebke University of Virginia. Demo. Today: Jiajun Zhu Tuesday: Ted Yokoyama . Assignments. Reminder: integrated version of assn 4 due today Group turns in whole project today

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Shadows CS 446: Real-Time Rendering & Game Technology' - lucius

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Shadows cs 446 real time rendering game technology l.jpg

Shadows CS 446: Real-Time Rendering & Game Technology

David Luebke

University of Virginia

Slide2 l.jpg

  • Today: Jiajun Zhu

  • Tuesday: Ted Yokoyama

Real-Time Rendering

Assignments l.jpg

  • Reminder: integrated version of assn 4 due today

    • Group turns in whole project today

    • Individuals taking late days turn in a new version of whole project when their changes are integrated

    • Remember, show up to class or assignment due in the morning…

Real-Time Rendering

Recap shadow notation l.jpg
Recap: Shadow Notation

  • Light source

    • Point vs area

  • Occluders & receivers

    • Identify ahead of time?

    • Self-shadowing?

  • Shadow

    • Umbra

    • Penumbra

  • Soft vs hard shadows

Real-Time Rendering

Recap planar shadows l.jpg
Recap: Planar Shadows

  • Old trick: project the occluder geometry to a plane and render over ground plane

    • Can do with a matrix

    • Z-bias issues

    • Semiopaque shadows harder

      • Stencil and Z-buffer tricks

    • Another option: generate textured rectangle

  • Problems

    • Light source inside object (Antishadows)

    • Only planar receivers  no self-shadowing

Real-Time Rendering

Planar soft shadows l.jpg
Planar Soft Shadows

  • Basic idea:

    • Sample light source multiple times, average results (accumulation buffer) into a texture

  • Gooch et al: move plane up and down

    • Nested shadows fewer passes

Real-Time Rendering

Projective shadows l.jpg
Projective Shadows

  • Render scene from light’s point of view

    • Render all occluders as black

    • Can turn off depth buffer etc

  • Project onto receiver polygons using projective texture mapping

  • Works for curved surfaces

  • Designer separates occluders and receivers  no self-shadowing

Real-Time Rendering

Shadow volumes l.jpg
Shadow Volumes

  • Basic idea:

    • Create polygonal objects to represent shadowed volumes

    • Make clever use of stencil buffer so that these objects affect what lighting is done

Real-Time Rendering

Stencil buffer l.jpg
Stencil Buffer

  • The stencil buffer has been around since OpenGL 1.0

    • Basic idea: provide a per-pixel flag to indicate whether pixels are drawn or not

    • But…

    • Let that flag be an integer (usually 8 bits)

      • Usually shared with depth buffer

    • And let drawing operations increment or decrement the stencil buffer based on different events

      • Always, depth-pass, depth-fail, etc.

Real-Time Rendering

Shadow volumes10 l.jpg
Shadow Volumes

  • Details of the basic algorithm:

    • Compute shadow volumes

      • View-independent!

    • Clear stencil buffer

    • Render the scene without diffuse/spec lighting

    • “Render” front faces of shadow volumes

      • Turn off color, depth updates (but leave depth test on)

      • Visible polygons increment pixel stencil buffer count

    • “Render” back faces of shadow volumes

      • Turn off color, depth updates (but leave depth test on)

      • Visible polygons decrement pixel stencil buffer count

    • Render scene with only diffuse/spec lighting

      • Only update pixels where stencil = 0

Shadow volumes11 l.jpg
Shadow Volumes

  • Refinements (see book, next slides)

    • NV30, XBox supports signed stencil addition

      • Two-sided lighting determines whether polygon adds or subtracts 1 from stencil buffer

      • One-pass algorithm! But a little slower in practice?

    • What if you’re inside a shadow volume?

      • Invert meaning of stencil test

    • What if near clip intersects shadow plane?

      • Carmack, others: use z-fail test

      • Clever extensions in NV2X help this idea out

    • Creating shadow volumes: vertex program!

      • ATI: clever degenerate-edge trick again

Shadow volumes12 l.jpg
Shadow Volumes

  • Advantages:

    • Robust

    • Self-shadowing

    • GPU

  • Disadvantages:

    • Can be geometry limited

      • Stencil polys

      • Multi-pass scene geometry

    • Can be fill limited

    • Stencil test – per pixel expense

    • Hard shadows

Shadow volumes13 l.jpg
Shadow Volumes

  • Will return to the gruesome details shortly

Real-Time Rendering

Shadow maps l.jpg
Shadow Maps

  • Idea:

    • Render scene from light source, read Z-buffer

    • Result: discretized image (shadow map) telling distance of objects to light source

    • Render scene normally

      • At each pixel, calculate distance D to light

      • Compare to distance S stored in shadow map

      • If D=S, surface lit by light, else in shadow

Real-Time Rendering

Shadow maps15 l.jpg
Shadow Maps

  • The basic algorithm (w/o hardware)

    • Render scene with ambient lighting only

    • Read Z-buffer, transform values into coordinate system of light

    • Use comparison to set alpha buffer

    • Render w/ diffuse and specular components, multiplying by alpha

Real-Time Rendering

Shadow maps16 l.jpg
Shadow Maps

  • Advantages:

    • Hardware-accelerated general shadow algorithm

    • Supports self-shadowing

    • Cost is linear in # lights and # polygons

  • Disadvantages:

    • Self-shadow aliasing

      • Biasing and other techniques can help, but not fix

    • Shadow map resolution critical!

      • Solution: perspective shadow maps

Real-Time Rendering

Taken from l.jpg
Taken from:

Practical & RobustStenciled Shadow Volumes for Hardware-Accelerated Rendering

Cass Everitt & Mark J. Kilgard, NVIDIA

GDC 2003

See the accompanying paper at:

Also see:

2d cutaway of a shadow volume l.jpg
2D Cutaway of a Shadow Volume

Surface outsideshadow volume





(infinite extent)

Eye position

(note that shadows are independent of the eye position)

Surface insideshadow volume





Shadow volume advantages l.jpg
Shadow Volume Advantages

  • Omni-directional approach

    • Not just spotlight frustums as with shadow maps

  • Automatic self-shadowing

    • Everything can shadow everything, including self

    • Without shadow acne artifacts as with shadow maps

  • Window-space shadow determination

    • Shadows accurate to a pixel

    • Or sub-pixel if multisampling is available

  • Required stencil buffer broadly supported today

    • OpenGL support since version 1.0 (1991)

    • Direct3D support since DX6 (1998)

Shadow volume disadvantages l.jpg
Shadow Volume Disadvantages

  • Ideal light sources only

    • Limited to local point and directional lights

    • No area light sources for soft shadows

  • Requires polygonal models with connectivity

    • Models must be closed (2-manifold)

    • Models must be free of non-planar polygons

  • Silhouette computations are required

    • Can burden CPU

    • Particularly for dynamic scenes

  • Inherently multi-pass algorithm

  • Consumes lots of GPU fill rate

Visualizing shadow volumes in 3d l.jpg
Visualizing Shadow Volumes in 3D

  • Occluders and light source cast out a shadow volume

    • Objects within the volume should be shadowed


Scene with shadows from an NVIDIA logo casting a shadow volume

Visualization of the shadow volume

Visualizing the stencil buffer counts l.jpg
Visualizing the Stencil Buffer Counts

Shadowed scene

Stencil buffer contents

Stencil counts beyond 1 are possible for multiple or complex occluders.

red = stencil value of 1green = stencil value of 0

GLUT shadowvol example credit: Tom McReynolds

Algorithm l.jpg

  • Render scene to initialize depth buffer

    • Depth values indicate the closest visible fragments

  • Use a stencil enter/leave counting approach

    • Draw shadow volume twice using face culling

      • 1st pass: render front faces and increment when depth test passes

      • 2nd pass: render back faces and decrement when depth test passes

    • Don’t update depth or color

  • Afterward, pixel’s stencil is non-zero if pixel in shadow, and zero if illuminated

Why eye to object stencil enter leave counting approach works l.jpg
Why Eye-to-Object Stencil Enter/ Leave Counting Approach Works


Shadowing object









Illuminated behind shadow volumes l.jpg

+ Works






Illuminated,Behind Shadow Volumes


Shadowing object










Shadow Volume Count = +1+1+1-1-1-1 = 0

Shadowed nested in shadow volumes l.jpg

+ Works




Shadowed,Nested in Shadow Volumes


Shadowing object










Shadow Volume Count = +1+1+1-1 = 2

Illuminated in front of shadow volumes l.jpg
Illuminated, WorksIn Front of Shadow Volumes


Shadowing object










Shadow Volume Count = 0

Problems created by near plane clipping zpass approach l.jpg
Problems Created by Near Plane Clipping ( WorksZpass approach)

Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count

Far clipplane








Near clipplane