View
219
Download
0
Tags:
Embed Size (px)
Citation preview
© 2004 Tomas Akenine-Möller 1
Shadow Generation Hardware
Vision day at DTU 2004
Tomas Akenine-MöllerLund University
© 2004 Tomas Akenine-Möller 2
Outline of my presentation
• Quick review of shadow volume algorithm– Zfail– Zpass
• A hierarchical shadow volume algorithm– Overall idea– Efficient hardware implementation
© 2004 Tomas Akenine-Möller 3
The shadow volume algorithm
• Crow's (1977) idea, shadow volumes define volumes of space in shadow.
From the School ofLeonardo Da Vinci
© 2004 Tomas Akenine-Möller 4
Shadow volume concept• Shadow volume concept
• Create volumes of space in shadow from each polygon in light.
• Each triangle creates 3 projecting quads
© 2004 Tomas Akenine-Möller 5
Using the volume
• To test a point, count the number of polygons between it and the eye.
• If we look through more frontfacing than backfacing polygons, then in shadow.
frontfacing
backfacing
© 2004 Tomas Akenine-Möller 6
Eye Location Problem
• If the eye location is inside one or more shadow volumes, count is wrong.
Eye problem fixed byclearing stencil buffer to
# of volumes eye is inside.
© 2004 Tomas Akenine-Möller 7
Frustum Location Problem
• Frustum’s near (hither) plane overlaps a shadow volume, frontface counts missed
Some form of capping is neededto make the shadow volume whole again (not trivial, nor robust)
© 2004 Tomas Akenine-Möller 8
Solution: Count Beyond Surface“Z-fail-algorithm”
• Render to stencil only when shadow volume Z >= stored Z!
must cap endsof shadow volumes
(or project to infinity, w=0 for vertices)
© 2004 Tomas Akenine-Möller 9
Why This Works
• (f - b) in front of plane = (b - f) in back
2-2 = 0
2 = 2
1 = 2-1
red - violet
violet - red
© 2004 Tomas Akenine-Möller 10
Merging shadow volumes• Edge shared by two polygons facing the
light creates front and backfacing quad.
This interior edge makestwo quads, which cancel out
Instead, useonly potentialsilhouetteedges as seenfrom the light:
© 2004 Tomas Akenine-Möller 13
Are there any work on accelerating shadow volume rendering?
• When we started with this project, NVIDIA’s UltraShadow technique was the only existing algorithm
• UltraShadows – two things:– Extra pipes...– Depth bounds
• Check out EGSR 2004 – several interesting shadow papers:– Lloyd et al, ”CC Shadow Volumes”– Chan and Durand: Hybrid Shadow map and volumes
© 2004 Tomas Akenine-Möller 14
A Hierarchical Shadow Volume Algorithm
• Motivation: fillrate problem with shadow volume rendering• Correct result:
© 2004 Tomas Akenine-Möller 19
How to detect boundary tiles?
8
8
Zmax
Zmin
Axis-aligned screen-space bounding box of a tile {
Fundamental observation: A tile can contain a shadow boundary, iff its bounding box is intersected by at least one shadow volume triangle.
© 2004 Tomas Akenine-Möller 20
Low-resolution rasterizer(for each tile)
Delay
Shadow volume
Temp boundaryTemp stencil
Per-pixelrasterization
Copy to2-level stencil
Low-resolution rasterizer
sv polys
sv polys
(wait until end of sv)
Boundary?
sv polys
Update2-level stencil
YesNo
© 2004 Tomas Akenine-Möller 21
Two-pass rasterization
1. Low-res rasterization & boundary test classifications ready only when entire
shadow volume processed
2. Wait by using a delay stream stores compressed vertices and render
states
3. Per-pixel rasterization of boundary tiles skip rasterization to tiles that are fully in
shadow or fully lit, because the results are already known
© 2004 Tomas Akenine-Möller 22
How to detect begin/end of shadow volume?
• You will have to tell the algorithm about this
• Send a marker down the pipeline– Beginning of shadow volume– End of shadow volume– Need new API calls
• E.g. glBeginShadowVolume()• glEndShadowVolume()
© 2004 Tomas Akenine-Möller 23
Stencil buffer updates
• Could write all 64 values per tile– Bandwidth problem
• Two-level stencil buffer saves the day– [Smin, Smax] per tile
– Always test the higher level first!– Often no need to validate per-pixel values
© 2004 Tomas Akenine-Möller 24
Speeding up Overlapping Shadow Volumes
• Several shadow volumes per light source
• The shadow area grows monotonically when more shadow volumes added– If tile already in shadow, skip rasterization
No need torasterize shadowtwice!
© 2004 Tomas Akenine-Möller 25
New hardware
• New on-chip buffers– Two-level stencil buffer
• beneficial for other computations too
– Tile classification buffer (cache)• need multiple buffers for pipelined operation• allocate from external memory, use through cache
• Delay stream (if not already in there)• New logic
– Low-res rasterization (trivial)– Bounding box intersection (must be robust!)
© 2004 Tomas Akenine-Möller 28
The end
• Questions?
• Publication: Timo Aila, and Tomas Akenine-Möller, “A Hierarchical Shadow Volume Algorithm”, accepted for Graphics Hardware 2004.