1 / 96

Optimized Stencil Shadow Volumes

Optimized Stencil Shadow Volumes. Cass Everitt & Mark J. Kilgard. Outline : Complete Lecture. Review of Stenciled Shadow Volumes Stenciled Shadow Volumes Optimizations Other Shadow Volume Issues More Information. Outline : Review of Stenciled Shadow Volumes. Shadow Volume Basics

carnig
Download Presentation

Optimized Stencil Shadow Volumes

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Optimized StencilShadow Volumes Cass Everitt & Mark J. Kilgard

  2. Outline: Complete Lecture • Review of Stenciled Shadow Volumes • Stenciled Shadow Volumes Optimizations • Other Shadow Volume Issues • More Information

  3. Outline: Review ofStenciled Shadow Volumes • Shadow Volume Basics • Zpass vs. Zfail • Infinite Rendering Techniques

  4. Stenciled Shadow Volumes in Practice Notice the properself-shadowing!

  5. Shadow Volume Basics Shadowingobject Lightsource Shadowvolume (infinite extent) A shadow volume is simply the half-space defined by a light source and a shadowing object.

  6. Shadow Volume Basics (2) Surface outsideshadow volume (illuminated) Simple rule: samples within a shadow volume are in shadow. Surface insideshadow volume (shadowed) Partially shadowed object

  7. Why Eye-to-Object Stencil Counting Approach Works Lightsource Shadowing object zero +1 zero +2 +2 Eyeposition +1 +3

  8. + + + - - - Illuminated,Behind Shadow Volumes (Zpass) Lightsource Shadowing object zero +1 zero Unshadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = +1+1+1-1-1-1 = 0

  9. + + + - Shadowed, Nested in Shadow Volumes (Zpass) Lightsource Shadowing object zero +1 zero Shadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = +1+1+1-1 = 2

  10. Illuminated, In Front of Shadow Volumes (Zpass) Lightsource Shadowing object zero +1 zero Shadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = 0 (no depth tests pass)

  11. Problem Created byNear Clip Plane (Zpass) Missed shadow volume intersection due to near clip plane clipping; leads to mistaken count Far clipplane zero +1 +1 +2 zero +3 +2 Near clipplane

  12. Illuminated,Behind Shadow Volumes (Zfail) Lightsource Shadowing object zero +1 zero Unshadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = 0 (zero depth tests fail)

  13. + + Shadowed, Nested inShadow Volumes (Zfail) Lightsource Shadowing object zero +1 zero +2 +2 Shadowedobject Eyeposition +1 +3 Shadow Volume Count = +1+1 = 2

  14. + + - - - + Illuminated, In Front of Shadow Volumes (Zfail) Lightsource Shadowing object zero +1 zero Shadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = -1-1-1+1+1+1 = 0

  15. Problem Created byFar Clip Plane (Zfail) Far clipplane Missed shadow volume intersection due to far clip plane clipping; leads to mistaken count zero +1 zero +1 +2 +2 +3 Near clipplane

  16. Problem Solved byEliminating Far Clip zero +1 +1 +2 +2 +3 Near clipplane

  17. Nested Shadow VolumesStencil Counts Beyond One Shadowed scene Stencil buffer contents green = stencil value of 0 red = stencil value of 1 darker reds = stencil value > 1

  18. Fully shaded scene Final stencil state Animation of Stencil Buffer Updatesfor a Single Light’s Shadow Volumes Every frame is 5 additional stencil shadow volume polygon updates. Note how various intermediate stencil values do not reflect the final state.

  19. Shadows in a Real Game Scene Abducted game images courtesy Joe Riedel at Contraband Entertainment

  20. Scene’s VisibleGeometric Complexity Wireframe shows geometric complexity of visible geometry Primary light source location

  21. Blow-up of Shadow Detail Notice cable shadows on player model Notice player’s own shadow on floor

  22. Scene’s Shadow VolumeGeometric Complexity Wireframe shows geometric complexity of shadow volume geometry Shadow volume geometry projects away from the light source

  23. Visible Geometry vs.Shadow Volume Geometry << Visible geometry Shadow volume geometry Typically, shadow volumes generate considerably more pixel updates than visible geometry

  24. Other Example Scenes (1 of 2) Visible geometry Shadow volume geometry Dramatic chase scene with shadows Abducted game images courtesy Joe Riedel at Contraband Entertainment

  25. Other Example Scenes (2 of 2) Visible geometry Shadow volume geometry Scene with multiple light sources Abducted game images courtesy Joe Riedel at Contraband Entertainment

  26. Situations WhenShadow Volumes Are Too Expensive Chain-link fence is shadow volume nightmare! Chain-link fence’s shadow appears on truck & ground with shadow maps Fuel game image courtesy Nathan d’Obrenan at Firetoad Software

  27. Shadow Volumes vs. Shadow Maps • Shadow mapping via projective texturing • The other prominent hardware-accelerated shadow technique • Standard part of OpenGL 1.4 • Shadow mapping advantages • Requires no explicit knowledge of object geometry • No 2-manifold requirements, etc. • View independent • Shadow mapping disadvantages • Sampling artifacts • Not omni-directional

  28. Outline: Stenciled Shadow Volumes Optimizations • Fill Rate Optimizations • Dynamic Zpass vs. Zfail determination • Bounds • Culling Optimizations • Portal-based culling • Occluder and cap culling • Silhouette Determination Optimizations • Efficient data structures for static occluder & dynamic light • Cache SVs, update only when necessary • Simplified occluder geometry • Shadow Volume Rendering Optimizations • Vertex programs for shadow volume rendering • Two-sided stencil testing • Directional lights

  29. Fill Rate Optimizations • Dynamic Zpass vs. Zfail determination • Bounds • CSG-style intersections • Window-space bounds • Scissoring • Depth bounds test (sort of a z-based scissor)

  30. Zpass vs. Zfail (1) • Zpass counting requires no caps • Zpass is often more efficient (due to occlusion culling hw) zfail eye zpass

  31. Zpass vs Zfail (2) • When to not use zpass clipping throws the shadow count off for this whole region

  32. Zpass vs Zfail (3) • We can decide zpass vs zfail on a per-occluder basis • do zfail when we must • how do we decide? zpass(no caps) zfail(with caps)

  33. Zpass vs Zfail (4) • How do we decide? • one way: near plane – light pyramid This diagram shows three planes in the “near plane - light pyramid”. Any object that is completely outside one of the planes can be rendered with zpass. Use object bounding volume for speed. a c b object is at least partially inside of each plane (zfail) object is completelyoutside plane “c”(zpass is ok)

  34. Zpass vs Zfail (5) • closer near plane for more zpass • bad for depth resolution • NV_depth_clamp can help a b c objects completelyoutside plane “c”(zpass is ok)

  35. Exploit Bounds • Infinite shadow volumes can cover a lot of pixels • With some knowledge of bounds, we can reduce fill • compute window space 3D axis-aligned bounding box of “possible shadow” • (x,y) bounds are scissor rect • What about z? New depth bounds test. • Another strategy is to truncate the shadow volume using bounds • Example bounds • lights • attenuation • environment (walls/floor) • shadow volumes • depth range of shadow • redundant shadows

  36. Attenuated Light Bounds • For attenuated lights, we can use the scissor test to constrain the shadow volume • works great for occluders beside the light • This is the window-space bounding box (x,y) of “possible shadow” fill savings scissor rect

  37. Attenuated Light Bounds (2) • Per-light scissor rect does not always very helpful • Cap the shadow volume at light bounds? • expensive/complicated • reasonable for static shadow volumes • Per-occluder scissor? wasted fill scissor rect

  38. Attenuated Light Bounds (3) • Per-occluder scissor rect is nice • simple • allows effective truncation of SV without altering SV geometry • good for dynamic SVs per-occluderscissor rect reclaimed fill scissor rect

  39. Environmental Bounds • Some environments offer big opportunities for bounding optimizations scissor rect fill savings

  40. Environmental Bounds (2) • Further savings from per-occluder info • intersecting scissor rects is easy very small scissor rect! fill savings even more fill savings

  41. Depth Bounds • Some depth values cannot be in shadow, so why bother to INCR and DECR their stencil index? • This is just the Z component of the window-space bounding box for the region of “possible shadow” ! depth bounds fill savings zmax zmin no shadow possible depth range that can be in shadow

  42. Depth Bounds • Discard fragment if pixel depth is out of bounds • not a clip plane! • sort of a scissor for z • See NV_depth_bounds_test extension • Simple API • glDepthBoundsNV( GLclampd zmin, GLclampd zmax ); • glEnable( GL_DEPTH_BOUNDS_TEST_NV ); • glDisable( GL_DEPTH_BOUNDS_TEST_NV ); • Depths in window space • same [0,1] range as glDepthRange()

  43. Computing Window Space Bounds • Shadow volumes are infinite, but the depth bounds for possible shadows are constrained SV constrained by frustum depth bounds zmax zmin

  44. Computing Window Space Bounds depth bounds SV constrained by light bounds zmax zmin light bounds scissor Light bounds (scissor and depth) can be used as conservative bounds. Usually too conservative.

  45. Computing Window Space Bounds depth bounds SV constrained by environment zmax zmin environment (floor) scissor

  46. Computing Window Space Bounds • scissor rect and depth bounds really help constrain fill – use them agressively • use occluder bounding volume • conservative • inexpensive

  47. Window Space Bounds • Scissor + depth bounds • really just a window-space bounding box • Beware points behind eye! • clip space w < 0 • depth bounds: zmin == 0 • scissor rect tricky • See “Jim Blinn’s Corner: Calculating Screen Coverage” • In Notation, Notation, Notation, and • also May ’96 issue of IEEE CG&A

  48. Culling Optimizations • Shadow volume culling • Culling the shadow volume extrusion • Specialized shadow volume culling for Zfail • Culling the near caps • Culling the far caps • Portal-based culling

  49. Shadow Volume Culling • Conventional view frustum culling • Simple idea: If object is not within view frustum, don’t draw object • Use conservative bounding geometry to efficiently determine when object is outside the view frustum • Often done hierarchically • Shadow volume culling • Just because an object is not within the view frustum doesn’t mean it can’t cast a shadow that is visible within the view frustum!

  50. Shadow Volume Culling Example Light and occluder both outside the view frustum. But occluder still casts shadow into the view frustum. Must consider shadow volume of the occluder even though the occluder could be itself view frustum culled!

More Related