SLIDE 1 2
Algorithmen für die Echtzeitgrafik Algorithmen für die Echtzeitgrafik
Daniel Scherzer
scherzer@cg.tuwien.ac.at
LBI Virtual Archeology
SLIDE 2
Hard Shadows
SLIDE 3 4
Light
Render scene from light-view and save depth values
Shadow map
Shadow Mapping: First Pass
SLIDE 4 5
Shadow Mapping: Second Pass
Eye Light
Render scene from light-view and save depth values Render scene from eye-view
Transform each fragment to light source space Compare zeye with zlight value stored in shadow map zeye > zlight
→
fragment is in shadow
Shadow map
Eye-view
SLIDE 5 6
Why Shadow Maps?
Independent of scene complexity
Not as fill-rate limited as shadow volumes
Only one additional (depth only) render pass Handle self-shadowing correctly Handle arbitrary shadow caster/receiver constellations Problems?
SLIDE 6
Hard Shadows
Shadow Map Aliasing
SLIDE 7 8
Initial sampling: shadow map rendering Reconstruction: nearest neighbor, PCF, … Resampling: combined with reconstruction
polygons shadow map (regular grid) shadowed fragments
Shadow Map as Signal Reconstruction
SLIDE 8 9
not enough sampling information in shadow map wrong results
Shadow map samples only correct at center
Shadow Map as Signal Reconstruction
SLIDE 9 10
Main Types of Error
Undersampling
Too low initial
sampling frequency
Oversampling
No bandlimiting
Reconstruction error
Staircase
artifacts
SLIDE 10 11
Undersampling - Perspective Aliasing
Sufficient resolution far from the
Insufficient resolution near the
aliased
SLIDE 11 12
Undersampling - Projection Aliasing
Shadow receiver ~ orthogonal to shadow map
SLIDE 12
Hard Shadows
Fighting Undersampling - Fitting
SLIDE 13 14
Fitting: Focus the Shadow Map
[Brabec et al. 2002]
Only include relevant objects
Shadow casters Light source frustum View frustum
Better use of shadow map resolution
SLIDE 14 15
Point light Directional light
Fitting: Focus the Shadow Map
SLIDE 15 16
Fitting: Focus the Shadow Map
SLIDE 16 17
Focused Unfocused
Fitting: Focus the Shadow Map
SLIDE 17 18
Fitting: Temporal Aliasing
SLIDE 18 19
Fitting: Temporal Aliasing
SLIDE 19 20
Fitting: Temporal Aliasing
SLIDE 20 21
Fitting: Temporal Aliasing
SLIDE 21 22
Fitting vs Temporal Aliasing
Commonly used Better use of shadow map resolution One cause for temporal aliasing Temporal aliasing noticeable because of insufficient resolution → warping
SLIDE 22
Hard Shadows
Fighting Undersampling - Warping
SLIDE 23 24
Solution for Perspective Aliasing
Insufficient resolution near eye
aliased
SLIDE 24 25
Insufficient resolution near eye Redistribute values in
shadow map
Solution for Perspective Aliasing
SLIDE 25 26
Sufficient resolution near eye Redistribute values in
shadow map
Solution for Perspective Aliasing
still okay
SLIDE 26 27
Shadow Map Warping
Use an additional perspective frustum
uniform shadow map warped shadow map
SLIDE 27 28
Perspective Shadow Maps (PSM)
[Stamminger & Drettakis 2002]
Warp frustum = view frustum
Light Space Perspective Shadow Maps (LiSPSM)
[Wimmer et al. 2004]
Warp frustum view plane orthogonal to light view plane Optimal parameter choice
Trapezoidal Shadow Maps (TSM)
[Martin & Tan 2004]
Similar to LiSPSM Parameter choice based on heuristic
Shadow Map Warping
SLIDE 28 29
Perspective Shadow Maps
[Stamminger & Drettakis 2002]
Want to account for perspective warping of eye Shadow map in post-perspective eye space Reduce perspective aliasing world space post-perspective space
SLIDE 29 30
PSM Problems
world space post-perspective space
Shadows from behind
SLIDE 30 31
PSM Problems
world space post-perspective space
Shadows from behind
Require move back due to singularity Changes resulting quality of shadow
SLIDE 31 32
Post Perspective Space - Depth
SLIDE 32 33
Post Perspective Space – x or y
SLIDE 33 34
Parallel Light Transformation
post-perspective world space
SLIDE 34 35
Point Light Transformation
post-perspective world space
SLIDE 35 36
Shadows from behind
Require move back due to singularity Changes resulting quality of shadow
Lights change their type (point/directional)
Many special cases Non-intuitive post-perspective space
View-dependent shadow quality
PSM Problems
SLIDE 36 37
PSM Problems
Most severe: uneven z-distribution
Good near viewer, very bad far away! Can be reduced by pushing near plane away
post-perspective space world space
SLIDE 37 38
Observation
Want to redistribute samples in shadow map Perspective transform is a good option
Supported by hardware
BUT: why choose perspective based on observer transform???
SLIDE 38 39
Light Space Perspective Shadow Maps
Use an additional perspective frustum in light space
uniform shadow map LiSPSM shadow map
SLIDE 39 40
Light Space
light space
SLIDE 40 41
Advantages of LiSPSM
No singularities in relevant part of the scene
… by construction
Directional lights remain directional lights
… and direction remains the same
Points lights are converted to directional lights
… perspective point light transformation already done in light space
Easy construction, general and robust Smooth quality changes Most important: control over shadow quality
… by choice of free parameter
SLIDE 41 42
LiSPSM Overview
Focus shadow map Construct light space Create perspective transform Apply
SLIDE 42 43
Light and view vector define yz-plane
y z x light view
LiSPSM Fitting and Warp Construction
SLIDE 43 44
Find a tight perspective frustum on focused region
In light space!
LiSPSM Fitting and Warp Construction
SLIDE 44 45
LiSPSM Construction
SLIDE 45 46
Free Parameter n
Controls warping effect
n
n infinity : uniform shadow maps n = zn : PSM
n zn
SLIDE 46 47
Free Parameter n
very small n very big n
SLIDE 47 48
Free Parameter n
SLIDE 49 50
Sampling Error Analysis
Aliasing error:
Parameterization Perspective Projection eye dz ds dp β α z zn
SLIDE 50 51
How to Choose the Free Parameter n?
Recall error analysis
- > 1 shadow map undersampling
Projection aliasing cannot be changed Counter perspective aliasing with new shadow map
parameterization s
Goal: ~ 1
SLIDE 51 52
Error Analysis
Uniform shadow maps Perspective shadow maps
Linear increase in error!
Perfect: logarithmic re-parameterization
Hardware support? [Lloyd 2007, 2008]
s´ s´ s´
1
SLIDE 52 53
Error Analysis: LiSPSM Optimal Choice
For LiSPSM, depends on n
Gives between uniform and perspective
Optimal choice:
ds dp ds dp
n
SLIDE 53 54
Error Comparison
LiSPSM optimal choice Measured along view dir LiSPSM vs PSM for same depth range, LiSPSM error much lower More advanced analysis was done in [Lloyd 2006]
znear zfar
SLIDE 54 55
Error Comparison
Caveat: only measured along view direction What about ?
- for PSM, slightly worse for LiSPSM
More advanced analysis was done in [Lloyd 2006]
Result: “storage factor” constant for n in [1, nopt] But: best error distribution for nopt
t ~ x s ~ z
dt dp 1 ~ dt dp
SLIDE 55 56
Comparison
Uniform LiSPSM PSM
SLIDE 56 57
Warping: Problems
Only works if large z-range visible from light
Outdoor scenes
Bad: Dueling frusta case But: Fitting often alleviates this
SLIDE 57
Hard Shadows
Fighting Undersampling - Partitioning
SLIDE 58 59
Z-Partitioning: Idea
Parallel Split Shadow Maps [Zhang 2007] Cascaded Shadow Maps [Engel 2007][Zhang2009] x z
SLIDE 59 60
Z-Partitioning: Idea
Parallel Split Shadow Maps [Zhang 2007] Cascaded Shadow Maps [Engel 2007][Zhang2009] x z
SLIDE 60 61
Partition view frustum into
n sub-frusta
Calculate separate shadow
map for each
Z-Partitioning
SLIDE 61 62
Works even in cases where warping
fails
Light from behind, dueling frusta
Z-Partitioning
SLIDE 62 63
Z-Partitioning vs LiSPSM
SLIDE 63 64
Z-Partitioning
How to choose partition sizes?
Uniform Logarithmic/self-similar Linear blend between the two
SLIDE 64 65
Z-Partitioning and Warping
x
SLIDE 65 66
Z-Partitioning and Warping
Partitioning Partitioning + warping
SLIDE 66 67
Optimal shadow map texel spacing Spacing from a 4x4 projective transform Partitioning gives a better fit image beam shadow map
z
Z-Partitioning
SLIDE 67 68
Face partitioning
Problem: warping not good for all light directions
Especially from behind
Solution: Partition frustum according to faces Can be combined with z-partitioning
view frustum from behind face partitioning + z-partitioning
SLIDE 68 69
Full Error Analysis
[Lloyd 2006]
SLIDE 69 70
Adaptive Partitioning
Warping and z-partitioning are global resampling schemes
Deal with perspective aliasing Projection aliasing needs local scene adaptive resampling!
Adaptive partitioning adaptively splits shadow map
Usually quad-tree subdivision
Algorithms mainly differ in
termination criteria
SLIDE 70 71
Tiled shadow maps
[Arvo 2004]
Split according to heuristics Based on depth discontinuities, distances, …. Allows to trade speed against quality
SLIDE 71 72
Adaptive shadow maps
[Fernando et al. 2001; Lefohn et al. 2006]
High resolution only needed at edges Search for edge (slow)
If edge split
SLIDE 72 73
Queried/Fitted Virtual Shadow Maps
Queried Virtual Shadow Maps [Giegl 2006]
Render 4 shadow maps of a quad-tree node Check if this was necessary (occlusion query)
Fitted Virtual Shadow Maps [Giegl 2007] Resolution Matched Shadow Maps [Lefohn 2007]
Project pixel footprints into shadow map Generate quad-tree FVSM: CPU, RMSM: GPU
SLIDE 73 74
Fitted Virtual Shadow Maps
[Giegl & Wimmer 2007]
SLIDE 74 75
Fitted Virtual Shadow Maps
[Giegl & Wimmer 2007]
SLIDE 75
Hard Shadows
Fighting Undersampling - Irregular Sampling
SLIDE 76 77
Shadow Mapping Sampling
SLIDE 77 78
What Samples Do We Want?
Idea: use eye space samples to generate shadow map samples
SLIDE 78 79
Regular vs Irregular Sampling
SLIDE 79 80
Irregular z-Buffer
[Johnson et al. 2004]
Proposes hardware extension
SLIDE 80 81
Irregular z-Buffer
SLIDE 81 82
Alias Free Shadow Maps
[Aila and Laine 2004]
= Irregular Z-Buffer [Johnson 2004] in software Transform and project view-samples into light-space Rasterize blocker geometry using them as sampling points
Test if sampling point covered Hierarchical processing of sampling points (axis-aligned 2D BSP) In software
SLIDE 82 83
Alias Free Hard Shadows
[Sintorn et al. 2008]
Transform and project view-samples into light-space Store in a compact data structure with a list per light-space texel
SLIDE 83 84
Alias Free Hard Shadows
[Sintorn et al. 2008]
Render all geometry (conservatively) from lights point of view For each generated fragment, test all view-samples in list against triangle Set corresponding output bit
SLIDE 84 85
Alias Free Hard Shadows
[Sintorn et al. 2008]
Final screen-space pass Use bitmask from previous pass for shadowing
SLIDE 85
Hard Shadows
Fighting Undersampling - Temporal Reprojection
SLIDE 86 87
Fighting Temporal Aliasing
Quick fix: texel snapping
Fix coordinate system in world space Shadow maps move at integral multiples of a texel width Gives up warping Popping when zooming
SLIDE 87 95
Confidence and Temporal Smoothing
Confidence is weight for temporal smoothing cache(n):= conf∗ s(n) + (1−conf )∗ cache(n−1)
SLIDE 88
Hard Shadows
Fighting Undersampling - Conclusion
SLIDE 89 97
Conclusions
Fastest speed, single shadow map: warping
Good for outdoor
Fast speed, better quality, multiple shadow maps:
z-partitioning
High quality, lower speed: adaptive partitioning Reference quality, even slower: irregular sampling
SLIDE 90
Hard Shadows
Depth Biasing
SLIDE 91 99
Depth Biasing – Incorrect Self Shadowing
Polygon
SLIDE 92 100
Depth Biasing – Incorrect Self Shadowing
Numerical instabilities caused by undersampling
Polygon
zeye > zlight Incorrect self-shadowing
SLIDE 93 101
Depth Biasing
Polygon
zeye > zlight Incorrect self-shadowing zeye < zlight No self-shadowing
SLIDE 94 102
How to Choose the Bias?
Slope-scale biasing Constant biasing No biasing
SLIDE 95 103
Depends…
Too little bias, everything begins to shadow Too much bias, shadow starts too far back
How Much Bias?
Just right
SLIDE 96 104
Second-Depth Shadow Mapping
[Wang and Molnar 94]
Normally: render front-side
polygons into SM
Now: render back-side
polygons
SLIDE 97 105
Undersampling
Improve initial sampling Depth Biasing
Reconstruction error
Use different reconstruction algorithm
(Silhouette Shadow Maps)
Use better reconstruction filters
(PCF, PCF with Poisson disk sampling)
Oversampling
Use bandlimiting filters
(Convolution Shadow Maps etc., see later)
Error Overview
SLIDE 98
Hard Shadows
Reconstruction
SLIDE 99 107
Forward Shadow Mapping
[Zhang 1998]
SLIDE 100 108
Shadow Silhouette Maps
[Sen et al. 2003]
Use a better silhouette approximation Store additional information of shadow edge
SLIDE 101 109
Shadow Silhouette Maps
[Sen et al. 2003]
- 1. Create shadow map
- 2. Find silhouette edges
- 3. Rasterize silhouettes
- a. Find points that lie on silhouette edges
- b. Store such points into silhouette map
SLIDE 102 110
Shadow Silhouette Maps
[Sen et al. 2003]
- 1. Create shadow map
- 2. Find silhouette edges
- 3. Rasterize silhouettes
- a. Find points that lie on silhouette edges
- b. Store such points into silhouette map
- 4. Compute shadows
- a. Non-silhouette pixels use standard
shadow map
- b. Silhouette pixels use silhouette map
SLIDE 103 111
Shadow Silhouette Maps
[Sen et al. 2003] Fragment Silhouette points
I interior + 4 external
Create quadrants Shade fragment according to shadow test result at corner point
SLIDE 104 112
Shadow Silhouette Maps
[Sen et al. 2003]
silhouette map shadow map
SLIDE 105 113
Shadow Silhouette Maps
[Sen et al. 2003]
113
SLIDE 106 114 114
Shadow Silhouette Maps
[Sen et al. 2003]
SLIDE 107 115
Deep Shadow Maps
[Lokovic and Veach 2000]
High quality shadows Smoke, hair, fur, … Stores function for each texel
115
SLIDE 108 116
Deep Shadow Maps
[Lokovic and Veach 2000]
Transmittance function
Calculate reduction of light
Store compressed version
Piecewise linear Fixed number of function samples – store in array
116
SLIDE 109 117
Deep Shadow Maps
[Lokovic and Veach 2000]
with self-shadowing without self-shadowing