Jim X. Chen George Mason University Basic Shadow Methods Jim X. Chen George Mason University Covers chapter 14.1 & 14.2 of Computer Graphics and Virtual Environments (Slater, Steed and Chrysanthou) . See www.booksites.net/slater 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Light source Light Creator Receiver Shadow Observation: Shadows are places light does not reach. 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Definitions Light sources Shadow creator(occluder)s and receivers Light source Creator and receiver Creator Note back facing primitives (as seen from the light source) are always in shadow So the sphere is self shadowing too (not shown) Receiver 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadows 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volume Shadow planes Volume formed from shadow planes Open and infinite Inside in shadow - outside in light Must be clipped and capped 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volume A point is shadowed iff it is in at least one shadow volume Light Cap Side Shadow Volume Dark Cap (at infinity) 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Ray Tracing Shadows Ray tracing casts shadow feelers to a point light source. Many light sources are illuminated over a finite area. The shadows between these are substantially different. Area light sources cast soft shadows Penumbra Umbra 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Soft Shadows 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Soft Shadows Umbra – No part of the light source is visible. Penumbra – Part of the light source is occluded and part is visible (to a varying degree). Which part? How much? What is the Light Intensity reaching the surface? 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Anti-Aliasing Supersampling Jittering – Stochastic Method 6 10 2 13 3 14 12 8 15 7 11 5 9 4 1 eye 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Supersampling 1 sample per pixel 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Supersampling 16 samples per pixel 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Supersampling 256 samples per pixel 9/21/2018 CS 752 Interactive Graphics Software
Monte Carlo Integration For each hit point, use a bundle of rays and take the average - Expensive Monte Carlo Approach Using a randomly chosen ray at each hit point Average the value from each ray 9/21/2018 CS 752 Interactive Graphics Software
Result: Hard Shadow - Cube Without antialiasing With antialiasing 9/21/2018 CS 752 Interactive Graphics Software
Result: Soft Shadow - Ball Hard shadow Soft shadow 9/21/2018 CS 752 Interactive Graphics Software
More Shadow Algorithms Fake Shadow Vertex Projection Shadow Z-Buffer Shadow Volume … 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Fake Shadow No exact calculation Approximation of shadow position and shape Estimated by center or anchor of object Pro: simple, fast Contra: flat ground, only ground shading, not exact, rotate limitations 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Vertex Projection Object projected to ground Exact mathematical calculation Pro: still simple, exact, no rotate limitations Contra: flat ground, only ground shading 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Projection Shadows Project creator geometry onto receiver plane [Blinn] Projection matrix M p=Mv l=(lx,ly,lz) y v p y=0 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Projection Shadows Render projected polygons to an image (render-to-texture) Apply image as a texture onto the receivers Compute texture coords on the fly Use projective texturing Advantage: Texture can be projected onto multiple shadow receivers Do not need to regenerate texture if static scene Limitation: objects can either cast or receive a shadow, not both 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Z-buffer 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Z-buffer Based on hidden surfaces Light’s point of view rendering into Z-Buffer Camera’s point of view rendering, lookup in Z-Buffer Transformation between camera and light view Z-value compare - shadowed or lit 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Z-buffer Render the scene twice First from the light source Need z-buffer only Second from the camera Each time we scan a pixel P (xv,yv,zv) transform P to light space (xs,yz,zs) and test zs against stored value in z-buffer from light If less than or equal to this value it is lit 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Z-buffer “Less than or equal” test is imprecise it is only accurate in the image space of the light self-shadowing: small fudge factor Imagine a shadow throw over complex objects or long distances point-sampling: area-sampling 9/21/2018 CS 752 Interactive Graphics Software
Shadow Volume Techniques 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes Just like a polygon - you are inside a volume if you need to cross a surface to exist it General idea of shadow volumes is count the number of shadow planes you cross +1 for front facing -1 for back facing If total is >0 you are in shadow Special case if the eye itself is in shadow 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes Two stages: 1) Preprocessing Find all planes of the shadow volume and their plane equations 2) At run-time Determine shadow plane count per pixel Use a scan-line method OR stencil test 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Using Stencil Test Three steps: silhouette generation drawing of shadow volume(s) rendering the shadow 9/21/2018 CS 752 Interactive Graphics Software
Shadow Volume Stencil Test A stencil buffer is screen sized buffer (1-8bit) that stores a flag about a rendering operation E.G. stencil[x,y] is negated if zbuffer[x,y] is less than current z value (i.e. stencil is set if and only if z buffer test passes) Many uses in graphics 9/21/2018 CS 752 Interactive Graphics Software
Shadow Volume Stencil Test Render the scene into the RGB and z-buffer Turn z-buffer writing off, then render all shadow polygons with the stencil buffer Increment stencil count for front-facing Decrement for back facing Re-render scene with lighting OFF and only render pixels where stencil is non-zero 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes cont. Step 1: Silhouette generation boundaries between adjacent front-facing and back-facing polygons silhouette adding light vertex to silhouette vertexes shadow planes shadow planes together with object shadow volume 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes cont. Step 2: Drawing of Shadow volume rendered in stencil buffer 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes cont. Step 3: Rendering the Shadow stencil buffer holds shadow render a polygon using stencil buffer bits shadow for one light created Repeat for next light from step 1 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Shadow Volumes cont. Pro: greatly improved realism hardware support of stencil buffer Contra: high requirement on fill-rate sharp shadow additional scene management 9/21/2018 CS 752 Interactive Graphics Software
Shadow Volume BSP Trees Instead of calculating shadows in image calculate in object space Break up objects into shadowed and un-shadowed objects Saves time shading pixels More polygons (potentially many more) Precision problems 9/21/2018 CS 752 Interactive Graphics Software
Starting the SVBSP Tree 9/21/2018 CS 752 Interactive Graphics Software
Continuing the SVBSP Tree 9/21/2018 CS 752 Interactive Graphics Software
Finishing the SVBSP Tree Can continue until ALL polygons are in the SVBSP tree Usually put shadow casting polygons in the tree first, and then filter remaining polygons down the tree to see if they are lit or un-lit A polygon that ends up at an in-node is stored there as shadowed but doesn’t force the tree to be expanded 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Summary Projected Polygons Good: Simple, quick, and all hardware can do it. Bad: Can only cast shadows to a plane. Project to Create a Texture Good: Semitransparent, can reuse texture created, and can project shadow onto any surfaces. Bad: Objects either cast or receive shadows, not both. 9/21/2018 CS 752 Interactive Graphics Software
CS 752 Interactive Graphics Software Summary, continued Shadow Maps Good: Anything to anything, constant cost regardless of complexity, map can sometimes be reused. Bad: Only feasible on some hardware, frustum limited. Shadow Volumes Good: Anything can shadow anything, including self- shadowing, and the shadows are crisp. Bad: shadow polygons must be generated and rendered (lots of polygons & fill), CPU intensive. 9/21/2018 CS 752 Interactive Graphics Software