Hard Shadows Hard Shadows
Digital Image Synthesis 1/4/2007
With slides from Eric Chan, Pradeep Sen, Marc Stamminger, Ravi Ramamoorthi, Brandon Lloyd
Why shadows Why shadows
• Crucial for spatial and depth perception
blocker
receiver
Two Algorithms from the 1970’s Two Algorithms from the 1970’s
Shadow volumes (Crow 1977)
• Object-space
• Accelerated by hardware stencil buffer
• Large fillrate consumption Shadow maps (Williams 1978)
• Image-space
• Fast and simple
• Supported in hardware
• Undersampling artifacts
NVIDIA
Shadow volumes Shadow volumes
• Create volumes of
space in shadow from a point light
• Each triangle creates 3 projecting quads
Point light source
Shadow Volume object
light vertex
eye
Using the volume Using the volume
• To test a point, count the number of
polygons between it and eye
• If more front-facing than back-facing
polygons, then it is in shadow
Point light source
Shadow Volume object
light vertex
eye
Creating volumes Creating volumes
• Use the silhouette to speed up
• What is silhouette?
N
1N
2V
(N
1.V) . (N
2.V) < 0
Shadow volume algorithm Shadow volume algorithm
• Finding volumes
• Rendering
Render scene into z-buffer, freeze z-buffer
Draw front-facing quads, increment stencil buffer
Draw back-facing quads, decrement stencil buffer
If (cnt==0) lit else shadowed
Multiple shadow volumes Multiple shadow volumes
• To test a point, count the number of polygons
between it and eye
• If more front-facing than back-facing
polygons, then it is in shadow
Shadow Mapping Shadow Mapping
Lance Williams: Brute Force in image space (shadow maps in 1978, but other similar ideas like Z buffer, bump mapping using textures and so on)
Completely image-space algorithm
no knowledge of scene’s geometry is required
must deal with aliasing artifacts
Well known software rendering technique
Basic shadowing technique for Toy Story, etc.
Phase 1: Render from Light Phase 1: Render from Light
Depth image from light source
Phase 1: Render from Light Phase 1: Render from Light
Depth image from light source
Phase 2: Render from Eye Phase 2: Render from Eye
Standard image (with depth) from eye
Eye
Phase 2+: Project to light for shadows Phase 2+: Project to light for shadows
Project visible points in eye view back to light source
Eye
(Reprojected) depths match for light and eye. VISIBLE
Project visible points in eye view back to light source
Eye
(Reprojected) depths from light, eye not the same. BLOCKED!!
Phase 2+: Project to light for shadows
Phase 2+: Project to light for shadows
Visualizing Shadow Mapping Visualizing Shadow Mapping
A fairly complex scene with shadows
the point the point light source light source
Visualizing Shadow Mapping Visualizing Shadow Mapping
Compare with and without shadows
with shadows
with shadows without shadowswithout shadows
Visualizing Shadow Mapping Visualizing Shadow Mapping
The scene from the light’s point-of-view
FYI: from the FYI: from the
eyeeye’’s points point--ofof--viewview again
again
Visualizing Shadow Mapping Visualizing Shadow Mapping
The depth buffer from the light’s point-of-view
FYI: from the FYI: from the
light
light’’s points point--ofof--viewview again
again
Visualizing Shadow Mapping
Projecting the depth map onto the eye’s view
FYI: depth map for FYI: depth map for
light
light’’s points point--ofof--viewview again
again
Visualizing Shadow Mapping Visualizing Shadow Mapping
Comparing light distance to light depth map
Green is where Green is where the light planar the light planar distance and distance and the light depth the light depth map are
map are
approximately approximately equal
equal
NonNon--green is green is where
where shadows shadows should be should be
Visualizing Shadow Mapping Visualizing Shadow Mapping
Scene with shadows
Notice how Notice how specular specular highlights highlights never appear never appear in shadows in shadows
Notice how Notice how curved
curved
surfaces cast surfaces cast shadows on shadows on each other each other
Comparison Comparison
• Shadow volumes
Pros: accurate, high-quality
Cons: fill-rate limited, hard to implement robustly
• Shadow maps
Pros: fixed resolution, fast, simple
Cons: bias, aliasing
Percentage Closer filtering [Reeves 1987]
Percentage Closer filtering [Reeves 1987]
Percentage Closer filtering [Reeves 1987]
Percentage Closer filtering [Reeves 1987]
Provides anti-aliasing at shadow map edges, not soft shadows in the umbra/penumbra sense
Adaptive shadow maps [Fernando 2001]
Adaptive shadow maps [Fernando 2001]
high-resolution shadow map adaptive shadow map
Adaptive shadow maps Adaptive shadow maps
details rendering
Adaptive shadow maps Adaptive shadow maps
Pros:
• Progressive and view-dependent
• Confined to a user-specified memory limit, use LRU policy to delete nodes
Cons:
• Not easy to map to GPU; [Lefohn et. al. 2005]
has mapped it to GPU recently
Perspective Shadow Maps Perspective Shadow Maps
Marc Stamminger George Drettakis SIGGRAPH 2002
shadow map aliasing shadow map aliasing
prone to aliasing
when zooming into shadow boundaries
single shadow map pixel
Aliasing error Aliasing error
shadow plane
frustumview eye
light
light beam
' w
l' w
i'
w
iw '
iw '
iAliasing error
Aliasing error
' w
limage beam
w
iw
llight beam
image beam
θ
lθ
i' w
iAliasing error
Aliasing error
' w
lm= w '
l'
w
icos θ
lcos θ
iw
lw
i Perspective aliasingcos θ
lcos θ
i Projectionaliasing
w
lw
i≈
w
i≈ d
i‧ r
ishadow buffer pixel size distance to light
w
l≈ d
l‧ r
lw
iw
lθ
lθ
i' w
iAliasing error
Aliasing error
' w
lm= w '
l' w
iw
lw
i Perspective aliasingw
lw
i≈
light beam
image beam
cos θ
lcos θ
icos θ
lcos θ
i Projectionaliasing
To eliminate perspective aliasing:
w
l≤ w
iLight beam width depends on:
Shadow map resolution
Parameterization
We have freedom to choose where and how to set up shadow buffer
It should be adaptive to view;
this means that shadow
buffer has to be recomputed for view changes
w
iw
llight beam
image beam
Controlling aliasing error
Controlling aliasing error
perspective transformation perspective transformation
world space post-perspective space
fixed wi normalizing transformation
[Foley] p.258-271
Parameterization Parameterization
Standard Perspective warped
light image plane
shadow map shadow map
light light
perspective shadow map perspective shadow map
standard shadow map perspective shadow map
shadow map
image
perspective shadow map perspective shadow map
standard shadow map perspective shadow map
aliased oversampled
parallel light transformation parallel light transformation
post-perspective world space
point light transformation point light transformation
post-perspective world space
discussion discussion
best case: fixed wl
parallel light in post-perspective space
no new perspective distortion
post-perspective world space
discussion discussion
non-optimal case:
point light close to frustum
worst case:
becomes uniform
shadow map
post-perspective world space
Perspective shadow map Perspective shadow map
map view map depth result
Shadow map
Perspec- tive
Shadow map
Shadow maps
Shadow maps
Perspective Shadow maps
Perspective Shadow maps
conclusion conclusion
perspective shadow maps
shadow map in post-perspective space
just another shadow map matrix
non-uniform shadow map resolution
not always possible to find a good solution
needs recomputation per frame
minimal overhead for dynamic scenes
Shadow Silhouette Maps Shadow Silhouette Maps
Pradeep Sen
Mike Cammarano Pat Hanrahan
SIGGRAPH 2003
(slides from Eric Chan)
Motivation Motivation
Why another shadow algorithm?
Why not use perspective shadow maps?
Stamminger and Drettakis, SIGGRAPH 2002
Perspective Shadow Maps Perspective Shadow Maps
Addresses perspective aliasing
Optimizes distribution of depth samples Difficulties:
Does not handle projection aliasing Dueling frusta problem
Dueling Frusta Problem
Dueling Frusta Problem
Observation Observation
Shadow maps
undersampling can occur anywhere artifacts visible only at shadow edges
How To Fix Silhouettes?
How To Fix Silhouettes?
depth map silhouette map
One solution:
use a better silhouette approximation
Shadow Map (Review) Shadow Map (Review)
light source
blocker
receiver
Shadow Map (Review) Shadow Map (Review)
depth map
Shadow Map (Review) Shadow Map (Review)
depth map
Shadow Map (Review) Shadow Map (Review)
depth map
Depth Mesh Depth Mesh
depth mesh (sampling grid)
Depth Mesh Depth Mesh
depth mesh + dual mesh original grid (blue)
dual grid (red)
Depth Mesh Depth Mesh
original grid (blue) dual grid (red)
discrete silhouette boundary
depth mesh + dual mesh
Depth Mesh Depth Mesh
original grid (blue) dual grid (red)
discrete silhouette boundary
continuous silhouette boundary (green)
depth mesh + dual mesh
Depth Mesh Depth Mesh
original grid (blue) dual grid (red)
discrete silhouette boundary
continuous silhouette boundary (green)
silhouette map pixels
depth mesh + dual mesh
Depth Mesh Deformation Depth Mesh Deformation
deformed depth mesh Move depth samples
to lie on silhouette curve
Depth Mesh Deformation Depth Mesh Deformation
adjusted depth samples
deformed depth mesh
Depth Mesh Deformation Depth Mesh Deformation
adjusted depth samples
deformed depth mesh
Better Approximation Better Approximation
piecewise-linear approximation
Silhouette Map Silhouette Map
silhouette map depth map
deformed depth map
Decomposition of
deformed depth map
What is a Silhouette Map?
What is a Silhouette Map?
Many ways to think about it:
Edge representation
2D image, same resolution as depth map
Offset from depth map by ½ pixel in x, y
Stores xy-coordinates of silhouette points
Stores only one silhouette point per texel
Piecewise-linear approximation
Algorithm
Algorithm Properties Algorithm Properties
Scalable
Treats perspective and projection aliasing
Supports dynamic scenes Maps to graphics hardware
Algorithm Overview Algorithm Overview
Image-space algorithm
Algorithm Overview Algorithm Overview
Create depth map
Step 1
Algorithm Overview Algorithm Overview
Create silhouette map
Step 2
Algorithm Overview Algorithm Overview
Render scene and shadows
Step 3
Create Depth Map Create Depth Map
Same as in regular shadow maps
Identify Silhouette Edges Identify Silhouette Edges
Find object-space silhouettes (light’s view)
Create Silhouette Map Create Silhouette Map
Rasterize silhouette edges (light’s view) Find points that lie on silhouette edges Store one such point per texel
silhouette edges silhouette points
Compute Silhouette Points Compute Silhouette Points
Example:
silhouette edges
point of view of light
Compute Silhouette Points Compute Silhouette Points
silhouette map (dual grid)
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
pick an edge
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
rasterize edge conservatively:
be sure to generate fragments for silhouette pixels
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
for each fragment:
pick a point on the edge
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
silhouette points
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
do the same for other edges
Compute Silhouette Points Compute Silhouette Points
rasterization of silhouettes
completed silhouette map subtle issues:
• only one point per texel
• new values overwrite old ones
how to pick silhouette points?
Picking Silhouette Points Picking Silhouette Points
Pick a point on the line that lies inside the texel
?
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
pick the vertex itself
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
test for intersection against two diagonals
one
intersection
Case 2:
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
pick the intersection point itself
Case 2:
one
intersection
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
Case 2:
one
intersection
Case 3:
two
intersections
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
Case 2:
one
intersection
Case 3:
two
intersections
use midpoint
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
Case 2:
one
intersection
Case 3:
two
intersections
Case 4:
no
intersections
Silhouette Point Algorithm Silhouette Point Algorithm
Case 1:
vertex inside
Case 2:
one
intersection
Case 3:
two
intersections
Case 4:
no
intersections
Render scene Render scene
How to compute shadows?
Split problem into two parts:
non-silhouette pixels: use shadow map silhouette pixels: use silhouette map
Find Silhouette Pixels Find Silhouette Pixels
Project sample into light space
Compare depth against 4 nearest samples in shadow map
shadow map samples sample to be shaded
(projected to light space)
L
L S
S Find Silhouette Pixels
Find Silhouette Pixels
S
S S
S
results agree:
non-silhouette pixel
results disagree:
silhouette pixel
Case #1 Case #2
L
L L
L Treat Non-Silhouette Pixels Treat Non-Silhouette Pixels
S
S S
S
in shadow illuminated
Easy: use depth comparison result
Treat Silhouette Pixels Treat Silhouette Pixels
fetch five silhouette points
Reconstruct edge using silhouette map
L
L S
S
Treat Silhouette Pixels Treat Silhouette Pixels
Reconstruct edge using silhouette map
L
L S
splits cell into four quadrants
S
Treat Silhouette Pixels Treat Silhouette Pixels
Shade sample according to quadrant
L
L S
example: sample in shadow
S
Six Combinations Six Combinations
S
S S
S
L
S S
S
L
L S
S
L
S S
L
L
L S
L
L
L L
L
Algorithm Recap Algorithm Recap
Image-space algorithm
Algorithm Recap (1 of 3) Algorithm Recap (1 of 3)
Create depth map
Easy: just like regular shadow map
Algorithm Recap (2 of 3) Algorithm Recap (2 of 3)
Pick silhouette points, 1 per texel
Create silhouette map
Rasterize silhouette edges
Algorithm Recap (3 of 3) Algorithm Recap (3 of 3)
Render scene and shadows
Reconstruct shadow edge Fetch local silhouette points
Examples and Analysis
Example 1 Example 1
shadow maps shadow volumes silhouette maps
Example 1 (closeup) Example 1 (closeup)
shadow maps shadow volumes silhouette maps
Example 2 Example 2
shadow maps
Example 2 Example 2
projected silhouette map
Example 2 Example 2
shadows using silhouette map
Quality Comparison Quality Comparison
silhouette map shadow map
Artifacts Artifacts
Silhouette map: one point per texel Multiple edges inside a texel
Artifacts Artifacts
shadow maps shadow volumes silhouette maps
Artifacts (closeup) Artifacts (closeup)
shadow maps shadow volumes silhouette maps
Artifacts due to multiple edges More noticeable when animated
Algorithm Comparison Algorithm Comparison
Perspective Shadow Maps:
same generality as shadow maps
minimal overhead (2 passes)
doesn’t address aliasing in all cases
Shadow Silhouette Maps:
addresses aliasing more generally
more overhead (3 passes + big shaders)
less general than shadow maps
Combination of Algorithms Combination of Algorithms
Why not combine techniques?
Perspective shadow map:
Optimizes depth sample distribution More samples closer to viewer
Shadow silhouette map:
Optimizes depth sample information Exact silhouette edge locations
Summary Summary
Image-space algorithm
Silhouette map: deformed depth map Piecewise-linear approximation
Scalable
Compared to (perspective) shadow maps:
Removes aliasing in more cases
Additional overhead and requirements
An Efficient Hybrid Shadow Rendering Algorithm
An Efficient Hybrid Shadow Rendering Algorithm
Eric Chan
Fedro Durand EGSR 2004
Not Another Talk on Shadows?!
Not Another Talk on Shadows?!
Main ideas:
• combination of shadow maps + shadow volumes
• computation masks
+
Fillrate Problem Fillrate Problem
Lots and lots of fillrate!
• rasterization
• stencil updates
Why?
• polygons have large screen area
• polygons overlap
Fillrate Problem Fillrate Problem
Lots and lots of fillrate!
• rasterization
• stencil updates
Why?
• polygons have large screen area
• polygons overlap
But is this really a problem?
But Is This Really A Problem?
But Is This Really A Problem?
Case study: Doom 3 engine (id Software)
• bump mapping
• per-pixel surface shading
• dynamic and projected lights
• atmospheric effects
• particle effects
• shadow volumes
50%
50%
“Shadowing accounts for about half of the game’s rendering time.”
— John Carmack
Two Observations (shadow maps) Two Observations (shadow maps)
Shadow-map aliasing is ugly
But — only noticeable at shadow silhouettes
shadow silhouette
Two Observations (shadow volumes) Two Observations (shadow volumes)
Shadow volumes are accurate everywhere But — accuracy is only needed at silhouettes
few silhouette pixels
Hybrid Approach Hybrid Approach
Decompose the problem:
• use shadow volumes at silhouettes
• use shadow maps everywhere else
shadow map + shadow volume
Algorithm Algorithm
1. 3.
2. 4.
Algorithm Algorithm
1. 3.
2. 4.
create a shadow map
Algorithm Algorithm
1. 3.
2. 4.
find silhouette pixels
Algorithm Algorithm
1. 3.
2. 4.
apply shadow volumes only at silhouette pixels
Algorithm Algorithm
1. 3.
2. 4.
apply shadow maps everywhere else
Test Scenes
Test Scenes
Image Quality
Image Quality
Shadow maps
Silhouettes
Reconstruction
Hybrid Shadow maps
Time: 19 ms Time: 5 ms
Shadow volumes Hybrid
Time: 48 ms Time: 19 ms