Shadow Volume History (1)
Total Page:16
File Type:pdf, Size:1020Kb
Shadow Volume History (1) • Invented by Frank Crow [’77] – Software rendering scan-line approach Shadow Volumes • Brotman and Badler [’84] – Software-based depth-buffered approach – Used lots of point lights to simulate soft shadows • Pixel-Planes [Fuchs, et.al. ’85] hardware – First hardware approach – Point within a volume, rather than ray intersection • Bergeron [’96] generalizations – Explains how to handle open models – And non-planar polygons Shadow Volume History (2) Shadow Volume History (3) • Fournier & Fussell [’88] theory • Dietrich slides [March ’99] at GDC – Provides theory for shadow volume counting approach within a – Proposes zfail based stenciled shadow volumes frame buffer • Kilgard whitepaper [March ’99] at GDC • Akeley & Foran invent the stencil buffer – Invert approach for planar cut-outs – IRIS GL functionality, later made part of OpenGL 1.0 • Bilodeau slides [May ’99] at Creative seminar – Patent filed in ’92 – Proposes way around near plane clipping problems • Heidmann [IRIS Universe article, ’91] – Reverses depth test function to reverse stencil volume ray – IRIS GL stencil buffer-based approach intersection sense • Deifenbach’s thesis [’96] • Carmack [unpublished, early 2000] – Used stenciled volumes in multi-pass framework – First detailed discussion of the equivalence of zpass and zfail stenciled shadow volume methods Shadow Volume History (4) Shadow Volume Basics • Kilgard [2001] at GDC and CEDEC Japan Shadowing – Proposes zpass capping scheme object • Project back-facing (w.r.t. light) geometry to the near clip plane Light for capping source Shadow • Establishes near plane ledge for crack-free volume near plane capping (infinite extent) – Applies homogeneous coordinates (w=0) for rendering infinite shadow volume geometry – Requires much CPU effort for capping – Not totally robust because CPU and GPU computations will not match exactly, resulting in cracks A shadow volume is simply the half-space defined by a light source and a shadowing object. 1 Shadow Volume Basics (2) Shadow Quality: Shadow Maps Surface outside shadow volume (illuminated) Simple rule: samples within a shadow volume are in shadow. Partially Surface inside shadowed shadow volume object (shadowed) Shadow Quality: Stencil Shadow Volumes Shadow Volumes • Draw polygons along boundary of region in shadow (occluders) • Along ray from eye to first visible surface: – Count up for in event – Count down for out events – If result zero when surface hit, is lit • Can be implemented with stencil buffer • Near/far plane clip causes problems Shadow Volume Advantages Point Inside 2D Polygon • Omni-directional approach – Not just spotlight frustums as with shadow maps • Automatic self-shadowing – Everything can shadow everything, including self – Without shadow acne artifacts as with shadow maps • Window-space shadow determination – Shadows accurate to a pixel – Or sub-pixel if multisampling is available • Required stencil buffer broadly supported today – OpenGL support since version 1.0 (1991) – Direct3D support since DX6 (1998) 2 Point Inside 2D Polygon Point Inside 2D Polygon Point Inside 2D Polygon Point Inside 2D Polygon • Infinite “polygon” • Union of polygons • Line segment Optimizing shadow volumes Shadow volumes [Crow77] • Use silhouette edges only • Shadow volumes define closed volumes of space that are in shadow L A infinitesimal light source shadow caster = light cap dark cap extruded side quads 3 Shadow Volumes [Crow 77] Shadow Volumes [Crow 77] Front face: +1 Back face: -1 Step 1: Render scene Z-values Step 2: Render shadow volume faces Shadow Volumes [Crow 77] Shadow Volumes [Crow 77] ±0 Front face: ±0 (Depth test) Front face: +1 Back face: ±0 (Depth test) Back face: ±0 (Depth test) =±0 =+1 Shadow Volumes [Crow 77] Shadow Volumes [Crow 77] ±0 +1 +1 ±0 ±0 Front face: +1 Back face: -1 =±0 Step 3: Apply shadow mask to scene 4 Illuminated, Shadow Volumes w/ Stencils (Zpass) Behind Shadow Volumes (Zpass) • Details of the basic algorithm: – Compute shadow volumes • View-independent! Light Shadowing object – Clear stencil buffer source – Render the scene without (diffuse) specular lighting (ambient only) • Sets the Depth Buffer and color buffer – “Render” front faces of shadow volumes zero +1 • Turn off color, depth updates (but leave depth test on) • Visible polygons increment pixel stencil buffer count zero • increment when depth test passes – “Render” back faces of shadow volumes • Turn off color, depth updates (but leave depth test on) • Visible polygons decrement pixel stencil buffer count • decrement when depth test passes +2 +2 – Render scene with only diffuse/spec lighting Eye +1 • Only update pixels where stencil = 0 +3 • Others are in shadow (ambient only)! position Illuminated, Shadowed, Nested in Shadow Behind Shadow Volumes (Zpass) Volumes (Zpass) Light Shadowing object Light Shadowing object source source zero +1 zero +1 zero zero + + + - - - Unshadowed + + + - object +2 +2 +2 +2 Shadowed Eye +1 Eye +1 object +3 +3 position position Shadow Volume Count = +1+1+1-1-1-1 = 0 Shadow Volume Count = +1+1+1-1 = 2 Illuminated, In Front of Shadow Problems Created by Volumes (Zpass) Near Clip Plane (Zpass) Missed shadow volume intersection due to near clip plane clipping; leads Light Shadowing object to mistaken count Far clip source plane zero zero +1 +1 +1 zero +2 zero +3 +2 +2 +2 Unshadowed Eye +1 object +3 Near clip position plane Shadow Volume Count = 0 (no depth tests pass) 5 Shadow Volumes (Zfail) Zfail versus Zpass Comparison • Details of the basic algorithm: • When stencil increment/decrements occur – Compute shadow volumes • View-independent! – Zpass: on depth test pass – Clear stencil buffer – Zfail: on depth test fail – Render the scene without diffuse/spec lighting • Sets the Depth Buffer and Color Buffer • Increment on – “Render” back faces of shadow volumes – Zpass: front faces • Turn off color, depth updates (but leave depth test on) • Visible polygons increment pixel stencil buffer count – Zfail: back faces • increment when depth test fails • Decrement on – “Render” front faces of shadow volumes • Turn off color, depth updates (but leave depth test on) – Zpass: back faces • Visible polygons decrement pixel stencil buffer count – Zfail: front faces • decrement when depth test fails – Render scene with only diffuse/spec lighting • Only update pixels where stencil = 0 • Others are in shadow (ambient only)! Illuminated, Shadowed, Nested in Behind Shadow Volumes (Zfail) Shadow Volumes (Zfail) Light Light Shadowing object Shadowing object source source zero +1 zero +1 zero zero Unshadowed + + object +2 +2 +2 +2 Shadowed Eye +1 Eye +1 object +3 +3 position position Shadow Volume Count = 0 (zero depth tests fail) Shadow Volume Count = +1+1 = 2 Illuminated, In Front of Shadow Volumes (Zfail) Zfail versus Zpass Comparison • Both cases order passes based stencil operation – First, render increment pass Light Shadowing object source – Second, render decrement pass – Why? zero +1 . Because standard stencil operations saturate . Wrapping stencil operations can avoid this zero • Which clip plane creates a problem - - - + + + – Zpass: near clip plane – Zfail: far clip plane +2 +2 Unshadowed Eye +1 object • Either way is foiled by view frustum clipping +3 position – Which clip plane (front or back) changes Shadow Volume Count = -1-1-1+1+1+1 = 0 6 Nested Shadow Volumes Stencil Counts Beyond One Amount of pixel processing Shadowed scene Stencil buffer contents green = stencil value of 0 red = stencil value of 1 Adapted from [Chan and Durand 2004] darker reds = stencil value > 1 Scene’s Visible Shadows in a Real Game Scene Geometric Complexity Wireframe shows geometric complexity of Abducted game visible geometry images courtesy Joe Riedel at Contraband Entertainment Primary light source location Scene’s Shadow Volume Blow-up of Shadow Detail Geometric Complexity Wireframe shows Notice cable geometric shadows on complexity of player model shadow volume geometry Shadow volume geometry projects Notice player’s away from the own shadow on light source floor 7 Visible Geometry vs. Shadow Volume Geometry Other Example Scenes (1 of 2) << Visible geometry Visible geometry Shadow volume geometry Typically, shadow volumes generate Dramatic chase scene with shadows Shadow volume considerably more pixel updates than geometry visible geometry Abducted game images courtesy Joe Riedel at Contraband Entertainment Other Example Scenes (2 of 2) Shadow Volumes Too Expensive Visible geometry Chain-link fence is shadow volume nightmare! Chain-link fence’s shadow appears on Shadow volume truck & ground with Scene with multiple light sources shadow maps geometry Abducted game images courtesy Joe Riedel at Contraband Entertainment Fuel game image courtesy Nathan d’Obrenan at Firetoad Software Shadow Volume Advantages Shadow Volume Disadvantages • Omni-directional approach • Ideal light sources only – Not just spotlight frustums as with shadow maps – Limited to local point and directional lights • Automatic self-shadowing – No area light sources for soft shadows • Requires polygonal models with connectivity – Everything can shadow everything, including self – Models must be closed (2-manifold) – Without shadow acne artifacts as with shadow maps – Models must be free of non-planar polygons • Window-space shadow determination • Silhouette computations are required – Shadows accurate to a pixel – Can burden CPU – Or sub-pixel if multisampling is available – Particularly for dynamic scenes • Required stencil buffer broadly supported today • Inherently