![Page 1: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/1.jpg)
Shadows
![Page 2: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/2.jpg)
What for?
Shadows tell us about the relative locations and motions of objects
Vienna University of Technology 2
![Page 3: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/3.jpg)
What for?
Shadows tell us about the relative locations and motions of objects
And about light positions
Vienna University of Technology 3
![Page 4: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/4.jpg)
What for?
Objects look like they are “floating”
Shadows can fix that!
Vienna University of Technology 4
![Page 5: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/5.jpg)
Motivation
Shadows contribute significantly to realism of rendered images
Anchors objects in scene
Global effect expensive!
Light source behaves very similar to camera
Is a point visible from the light source?
shadows are “hidden” regions
Shadow is a projection of caster on receiver
projection methods
Best done completely in hardware through shaders
Vienna University of Technology 5
![Page 6: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/6.jpg)
Shadow Algorithms
Static shadow algorithms (lights + objects)
Radiosity, ray tracing lightmaps
Approximate shadows
Projected shadows (Blinn 88)
Shadow volumes (Crow 77)
Object-space algorithm
Shadow maps (Williams 78)
Projective image-space algorithm
Soft shadow extensions for all above algorithms
Still hot research topic (500+ shadow publications)
Vienna University of Technology 6
![Page 7: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/7.jpg)
Shadow Terms
Vienna University of Technology 7
receiver
(occludee)
light source
creator
(occluder, blocker, caster) creator and
receiver
![Page 8: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/8.jpg)
Hard vs. Soft Shadows
Vienna University of Technology 8
point source
hard shadow
area source
umbra
penumbra penumbra+fast
-only good for localized lights
(sun, projectors)
+fake soft shadow through
filtering
+ very realistic
- very expensive
+ becomes more and more
usable
![Page 9: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/9.jpg)
Static Shadows
Glue to surface whatever we want
Idea: incorporate shadows into light maps
For each texel, cast ray to each light source
Bake soft shadows in light maps
Not by texture filtering alone, but:
Sample area light sources
Vienna University of Technology 9
![Page 10: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/10.jpg)
Static Soft Shadow Example
Vienna University of Technology 10
no filtering filtering
1 sample
n samples
![Page 11: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/11.jpg)
Approximate Shadows
Handdrawn approximate geometry
Perceptual studies suggest:shape not so important
Minimal cost
Vienna University of Technology 11
![Page 12: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/12.jpg)
Approximate Shadows
Dark polygon (maybe with texture)
Cast ray from light source through object center
Blend polygon into frame buffer at location of hit
May apply additional rotation/scale/translation
Incorporate distance and receiver orientation
Problem with zquantization:
Vienna University of Technology 12
Blend at hit polygon
Z-test equal
z-buffer quantization errors!
viewerlight
![Page 13: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/13.jpg)
Approximate Shadows
Vienna University of Technology 13
viewerlightElevate above hit polygon
Z-test less or equal
shadow too big
may appear floating
No z-test, only one eye ray
shadow too big,
maybe in wrong place
![Page 14: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/14.jpg)
Projection Shadows (Blinn 88)
Shadows for selected large planar receivers
Ground plane
Walls
Projective geometry:flatten 3D model ontoplane
and “darken” using framebuffer blend
Vienna University of Technology 14
![Page 15: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/15.jpg)
Projection for Ground Plane
Use similar-triangle tricks
Vienna University of Technology 15
p
ly
y=0
v
0=
-
-=
-
-=
-=
-
-
y
yy
yzzy
z
yy
yxxy
x
yy
y
xx
xx
p
vl
vlvlp
vl
vlvlp
vl
l
lv
lp
![Page 16: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/16.jpg)
Projection Matrix
Projective 4x4 matrix:
Arbitrary plane:
Intersect line p = l – (v – l)
with plane n x + d = 0
Express result as a 4x4 matrix
Append this matrix to view transformVienna University of Technology 16
l
ll
ll
M
y
yz
xy
-
-
-
=
010
00
0000
00
l
p
v
n
![Page 17: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/17.jpg)
Projection Shadow Algorithm
Render scene (full lighting)
For each receiver polygon
Compute projection matrix M
Append to view matrix
Render selected shadow caster
With framebuffer blending enabled
Vienna University of Technology 17
![Page 18: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/18.jpg)
Projection Shadow Artifacts
Vienna University of Technology 18
Bad Good
extends off
ground region
Z fighting double blending
![Page 19: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/19.jpg)
Stencil Buffer Projection Shadows
Stencil can solve all of these problems
Separate 8-bit frame buffer for numeric ops
Stencil buffer algorithm (requires 1 bit):
Clear stencil to 0
Draw ground polygon last and withglStencilOp(GL_KEEP, GL_KEEP, GL_ONE);
Draw shadow caster with no depth test butglStencilFunc(GL_EQUAL, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
Every plane pixel is touched at most onceVienna University of Technology 19
fail zfail pass
![Page 20: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/20.jpg)
Stencil Buffer Planar Reflections
Draw object twice, second time with:
glScalef(1, -1, 1)
Reflects through floor
Vienna University of Technology 20
Good, stencil
used to limit reflection.
Bad
![Page 21: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/21.jpg)
Projection Shadow Summary
Easy to implement
GLQuake first game to implement it
Only practical for very few, large receivers
No self shadowing
Possible remaining artifacts: wrong shadows
Objects behind light source
Objects behind receiver
Vienna University of Technology 21
![Page 22: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/22.jpg)
Shadow Volumes (Crow 1977)
Occluders and light source cast out a 3D shadow volume
Shadow through new geometry
Results in Pixel correct shadows
Vienna University of Technology 22
Light
source
Visualization of
shadow volumeShadowed scene
![Page 23: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/23.jpg)
Shadow Volumes (Crow 1977)
Heavily used in Doom3
Vienna University of Technology 23
![Page 24: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/24.jpg)
2D Cutaway of Shadow Volume
Occluder polygons extruded to semi-infinite volumes
Vienna University of Technology 24
shadowing
object
shadow
volume
(infinite extent)
partiallyshadowed object
light
source
eye
position surface inside
shadow volume
(shadowed)
surface outside
shadow volume
(illuminated)
![Page 25: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/25.jpg)
Shadow Volume Algorithm
3D point-in-polyhedron inside-outside test
Principle similar to 2D point-in-polygon test
Choose a point known to be outside the volume
Count intersection on ray from test point to known point with polyhedron faces
Front face +1
Back face -1
Like non-zero winding rule!
Known point will distinguish algorithms:
Infinity: “Z-fail” algorithm
Eye-point: “Z-pass” algorithm
Vienna University of Technology 25
![Page 26: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/26.jpg)
Enter/Leave Approach
Increment on enter, decrement on leave
Simultaneously test all visible pixels
Stop when hitting object nearest to viewer
Vienna University of Technology 26
shadowing objectlight
source
eye
position
zero
zero
+1
+1+2 +2
+3
![Page 27: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/27.jpg)
Shadow Volume Algorithm
Shadow volumes in object precision
Calculated by CPU/Vertex Shaders
Shadow test in image precision
Using stencil buffer as counter!
Vienna University of Technology 27
![Page 28: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/28.jpg)
Shadow Volume Algorithm
Vienna University of Technology 28
Step 1: Render scene Z-values
![Page 29: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/29.jpg)
Shadow Volume Algorithm
Vienna University of Technology 29
Front face: +1
Step 2: Render shadow volume faces
Back face: -1
![Page 30: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/30.jpg)
Shadow Volume Algorithm
Vienna University of Technology 30
Front face: ±0 (Depth test)Back face: ±0 (Depth test)
= ±0
![Page 31: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/31.jpg)
Shadow Volume Algorithm
Vienna University of Technology 31
Front face: +1Back face: ±0 (Depth test)
= +1
±0
![Page 32: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/32.jpg)
Shadow Volume Algorithm
Vienna University of Technology 32
Front face: +1Back face: -1
= ±0
±0+1
![Page 33: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/33.jpg)
Shadow Volume Algorithm
Vienna University of Technology 33
±0
+1
±0
Step 3: Apply shadow mask to scene
![Page 34: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/34.jpg)
Shadow Volume Algorithm (Zpass)
Render scene to establish z-buffer
Can also do ambient illumination
For each light
Clear stencil
Draw shadow volume twice using culling
Render front faces and increment stencil
Render back faces and decrement stencil
Illuminate all pixels not in shadow volume
Render testing stencil = 0
Use additive blend
Vienna University of Technology 34
![Page 35: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/35.jpg)
Zpass Technique (Before Shadow)
Vienna University of Technology 35
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Unshadowed
object
Shadow Volume Count = 0 (no depth tests passes)
![Page 36: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/36.jpg)
Zpass Technique (In Shadow)
Vienna University of Technology 36
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Shadowed
object
+ -+ +
Shadow Volume Count = +1+1+1-1 = 2
![Page 37: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/37.jpg)
Zpass Technique (Behind Shadow)
Vienna University of Technology 37
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Unshadowed
object
+ ---+ +
Shadow Volume Count = +1+1+1-1-1-1 = 0
![Page 38: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/38.jpg)
Zpass Near Plane Problem
Vienna University of Technology 38
zero
zero
+1+1
+2
+2
+3
Near clip
plane
Far clip
plane
Missed shadow volume
intersection due to
near clip plane
clipping; leads to
mistaken count
![Page 39: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/39.jpg)
Alternative: Zfail Technique
Zpass near plane problem difficult to solve
Have to “cap” shadow volume at near plane
Expensive and not robust, many special cases
Try reversing test order Zfail technique(also known as Carmack’s reverse)
Start from infinity and stop at nearest intersection
Render shadow volume fragments only whendepth test fails
Render back faces first and increment
Then front faces and decrement
Need to cap shadow volume at infinity or light extent
Vienna University of Technology 39
![Page 40: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/40.jpg)
Zfail, Behind Shadow
Vienna University of Technology 40
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Unshadowed
object
Shadow Volume Count = 0 (zero depth tests fail)
![Page 41: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/41.jpg)
Zfail, in Shadow
Vienna University of Technology 41
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Shadow Volume Count = +1+1 = 2
+ +
Shadowed
object
![Page 42: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/42.jpg)
Zfail, before Shadow
Vienna University of Technology 42
Shadowing objectLight
source
Eye
position
zero
zero
+1
+1
+2 +2
+3
Unshadowed
object
Shadow Volume Count = -1-1-1+1+1+1 = 0
- +- - + +
![Page 43: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/43.jpg)
Shadow Volumes
Shadow volume = closed polyhedron
Actually 3 sets of polygons!
1. Object polygons facing the light (“light cap”)
2. Object polygons facing away from the light and projected to infinity (with w = 0) (“dark cap”)
3. Actual shadow volume polygons (extruded object edges) (“sides”) but which edges?
Vienna University of Technology 43
![Page 44: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/44.jpg)
Zpass vs. Zfail
Equivalent, but reversed
Zpass
Faster (light cap and dark cap not needed)
Light cap inside object always fails z-test
Dark cap infinitely far away either fails or falls on background
Problem at near clip plane (no robust solution)
Zfail
Slower (need to render dark and light caps!)
Problem at far clip plane when light extends farther than far clip plane
Robust solution with infinite shadow volumes!
Vienna University of Technology 44
![Page 45: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/45.jpg)
Zpass vs. Zfail
Idea: Combine techniques!
Test whether viewport in shadow Zfail
Otherwise Zpass
Idea: avoid far plane clipping in Zfail!
Send far plane to infinity in projection matrix
Easy, but loses some depth buffer precision
Draw infinite vertices using homogeneous coordinates: project to infinity w = 0
robust solution!
Vienna University of Technology 45
![Page 46: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/46.jpg)
W=0 Rasterization
At infinity, vertices become vectors
Vienna University of Technology 46
(-3,-1,z1,1)
(2,-2,z2,1)
(2,-2,z2,0)(-1,-3,z1,0) (2,-2,z2,0)
![Page 47: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/47.jpg)
Computing Actual SV Polygons
Trivial but bad: one volume per triangle
3 shadow volume polygons per triangle
Better: find exact silhouette
Expensive on CPU
Even better: possible silhouette edges
Edge shared by a back-facing and front-facing polygon (with respect to light source!), extended to infinity
Actual extrusion can be done by vertex shader
Vienna University of Technology 47
![Page 48: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/48.jpg)
Possible Silhouette Edges
Vienna University of Technology 48
![Page 49: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/49.jpg)
Shadow Volumes Summary
AdvantagesArbitrary receivers
Fully dynamic
Omnidirectional lights (unlike shadow maps!)
Exact shadow boundaries (pixel-accurate)
Automatic self shadowing
Broad hardware support (stencil)
DisadvantagesFill-rate intensive
Difficult to get right (Zfail vs. Zpass)
Silhouette computation required
Doesn’t work for arbitrary casters (smoke, fog…)
Vienna University of Technology 49
![Page 50: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/50.jpg)
Shadow Volume Issues
Stencil buffering fast and present in all cards
With 8 bits of stencil, maximum shadow depth is 255
EXT_stencil_wrap overcomes this
Two-sided stencil tests can test front- and back triangles simultaneously
Saves one pass – available on NV30+
NV_depth_clamp (hardware capping)
Regain depth precision with normal projection
Requires watertight models with connectivity, and watertight rasterization
Vienna University of Technology 50
![Page 51: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/51.jpg)
Shadow Maps
Casting curved shadows on curved surfaces
Image-space algorithm, 2 passes
Vienna University of Technology 51
Shadow map
Final scene
![Page 52: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/52.jpg)
Shadow Map Algorithm
Vienna University of Technology 52
EyeLight
Render from light; save depth values
Render from eye
Transform all fragments to light space
Compare zeye and zlight (both in light space!!!)
zeye > zLicht fragment in shadow
Shadow mapEye view
![Page 53: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/53.jpg)
Shadow Maps in Hardware
Render scene to z-buffer (from light source)
Copy depth buffer to texture
Render to depth texture + pbuffer
Project shadow map into scene (remember projective texturing!)
Hardware shadow test (ARB_shadow)
Use homogeneous texture coordinates
Compare r/q with texel at (s/q, t/q)
Output 1 for lit and 0 for shadow
Blend fragment color with shadow test resultVienna University of Technology 53
![Page 54: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/54.jpg)
Shadow Maps in Hardware
Shadow extension available since GeForce3
Requires high precision texture format(ARB_depth_texture)
On modern hardware:
Render lightspace depth into texture
In vertex shader:
Calculate texture coordinates as in projective texturing
In fragment shader:
Depth compare
Vienna University of Technology 54
![Page 55: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/55.jpg)
Problem: Perspective Aliasing
Sufficient resolution far from eye
Insufficient resolution near eye
Vienna University of Technology 55 aliasedokay
![Page 56: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/56.jpg)
Problem: Projection Aliasing
Shadow receiver ~ orthogonal toShadow Map - viewplane
Vienna University of Technology 56
![Page 57: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/57.jpg)
Problem: Incorrect Self-Shadowing
Vienna University of Technology 57
Polygon
![Page 58: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/58.jpg)
Problem: Incorrect Self-Shadowing
Vienna University of Technology 58
Polygon
zeye > zlight Incorrect Self-shadowing
![Page 59: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/59.jpg)
Solution for Perspective Aliasing
Insufficient resolution near eye
Vienna University of Technology 59
aliasedokay
![Page 60: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/60.jpg)
Solution for Perspective Aliasing
Insufficient resolution near eye
Redistribute values in shadow map
Vienna University of Technology 60
![Page 61: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/61.jpg)
Solution for Perspective Aliasing
Sufficient resolution near eye
Redistribute values in shadow map
Vienna University of Technology 61
okay okay
![Page 62: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/62.jpg)
Solution for Perspective Aliasing
How to redistribute?
Use perspective transform
Additional perspective matrix, used in both:
Light pass
Eye pass
More details:
[WSP2004]
Vienna University of Technology 62
[WSP2004] M. Wimmer, D. Scherzer, and W. Purgathofer;
Light space perspective shadow maps; In Proceedings of
Eurographics Symposium on Rendering 2004
![Page 63: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/63.jpg)
Solution for Projection Aliasing
Shadow receiver ~ orthogonal to Shadow Map plane
Redistribution does not work
But...
Vienna University of Technology 63
![Page 64: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/64.jpg)
Solution for Projection Aliasing
Diffuse lighting: I = IL max( dot( L, N ), 0 )
Almost orthogonal receivers have small I
Dark artifacts not very visible!
Vienna University of Technology 64
LN
![Page 65: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/65.jpg)
Solution for Projection Aliasing
Recommendations
Small ambient term
Diffuse term hides artifacts
Specular term not problematic
Light and view direction almost identical
Shadow Map resolution sufficient
Vienna University of Technology 65
![Page 66: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/66.jpg)
Solution for Incorrect Self-Shadowing
Vienna University of Technology 67
Polygon
zAug > zLicht Incorrect Self-shadowing
Shifted Polygon
zAug < zLicht No Self-shadowing
![Page 67: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/67.jpg)
Solution for Incorrect Self-Shadowing
How to choose bias?
Vienna University of Technology 68
Slope-Scale Bias
Constant Bias
No Bias
![Page 68: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/68.jpg)
Depth Bias
glPolygonOffset(1.1,4.0) works well
Works in window coordinates
Vienna University of Technology 69
Too little bias,
everything begins to
shadow
Too much bias, shadow
starts too far back
![Page 69: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/69.jpg)
Problem: Aliasing Artifacts
Resolution mismatch image/shadow map!
Use perspective shadow maps
Use “percentage closer” filtering
Normal color filtering cannot be used
Filter lookup result, not depth map values!
2x2 PCF in hardware for NVIDIA
Better: Poisson-disk distributed samples (e.g., 6 averaged samples)
Vienna University of Technology 71
![Page 70: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/70.jpg)
Shadow Map Filtering
GL_NEAREST GL_LINEAR
Vienna University of Technology 72
![Page 71: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/71.jpg)
Shadow Map Summary
Advantages
Fast – only one additional pass
Independent of scene complexity (no additional shadow polygons!)
Self shadowing (but beware bias)
Can sometimes reuse depth map
Disadvantages
Problematic for omnidirectional lights
Biasing tweak (light leaks, surface acne)
Jagged edges (aliasing)
Vienna University of Technology 73
![Page 72: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/72.jpg)
Vienna University of Technology 74
OGRE shadow demo
![Page 73: Real-Time Rendering (Echtzeitgraphik) - TU WienRadiosity, ray tracing lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow](https://reader033.vdocument.in/reader033/viewer/2022042912/5f4593451faee97bfb61d3ee/html5/thumbnails/73.jpg)
Conclusions
Shadows are very important but still difficult
Many variations based on shadow volumes/shadow maps to do shadowing:
Variance shadow mapping (VSM)
Perspective shadow mapping (PSM)
Hierarchical shadow volume
Subdivided shadow maps
…
Vienna University of Technology 75