Basic Shadow Methods Jim X. Chen George Mason University 11/7/2015 CS 752 Interactive Graphics Software.
Download ReportTranscript Basic Shadow Methods Jim X. Chen George Mason University 11/7/2015 CS 752 Interactive Graphics Software.
Basic Shadow Methods Jim X. Chen George Mason University 11/7/2015 CS 752 Interactive Graphics Software Light source Light Creator Receiver Shadow Observation: Shadows are places light does not reach. 11/7/2015 CS 752 Interactive Graphics Software Definitions Light sources Shadow creator(occluder)s and receivers Light source Creator and receiver Creator Receiver 11/7/2015 CS 752 Interactive Graphics Software Shadows 11/7/2015 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 11/7/2015 P o in t lig h t s o u rc e o b je c t CS 752 Interactive Graphics Software lig h t v e rte x S h a d o w V o lu m e Shadow Volume A point is shadowed iff it is in at least one shadow volume Light Cap Side Shadow Volume Dark Cap (at infinity) 11/7/2015 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 11/7/2015 Penumbra Umbra CS 752 Interactive Graphics Software Soft Shadows 11/7/2015 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? 11/7/2015 CS 752 Interactive Graphics Software Anti-Aliasing Supersampling Jittering – Stochastic Method 6 10 2 13 3 14 12 8 15 0 7 11 5 9 4 1 eye 11/7/2015 CS 752 Interactive Graphics Software Supersampling 1 sample per pixel 11/7/2015 CS 752 Interactive Graphics Software Supersampling 16 samples per pixel 11/7/2015 CS 752 Interactive Graphics Software Supersampling 256 samples per pixel 11/7/2015 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 11/7/2015 Using a randomly chosen ray at each hit point Average the value from each ray CS 752 Interactive Graphics Software Result: Hard Shadow - Cube Without antialiasing 11/7/2015 With antialiasing CS 752 Interactive Graphics Software Result: Soft Shadow - Ball Hard shadow 11/7/2015 Soft shadow CS 752 Interactive Graphics Software More Shadow Algorithms Fake Shadow Vertex Projection Shadow Z-Buffer Shadow Volume … 11/7/2015 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 11/7/2015 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 11/7/2015 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 11/7/2015 y=0 CS 752 Interactive Graphics Software p Projection Shadows Render projected polygons to an image (renderto-texture) Apply image as a texture onto the receivers Advantage: Compute texture coords on the fly Use projective texturing 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 11/7/2015 CS 752 Interactive Graphics Software Shadow Z-buffer 11/7/2015 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 11/7/2015 CS 752 Interactive Graphics Software Shadow Z-buffer Render the scene twice First from the light source Second from the camera Need z-buffer only 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 11/7/2015 CS 752 Interactive Graphics Software Shadow Z-buffer “Less than or equal” test is imprecise 11/7/2015 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 CS 752 Interactive Graphics Software Shadow Volume Techniques 11/7/2015 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 11/7/2015 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 11/7/2015 Determine shadow plane count per pixel Use a scan-line method OR stencil test CS 752 Interactive Graphics Software Using Stencil Test Three steps: 11/7/2015 silhouette generation drawing of shadow volume(s) rendering the shadow CS 752 Interactive Graphics Software Shadow Volume Stencil Test A stencil buffer is screen sized buffer (18bit) 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 11/7/2015 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 11/7/2015 CS 752 Interactive Graphics Software Shadow Volumes cont. Step 1: Silhouette generation 11/7/2015 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 CS 752 Interactive Graphics Software Shadow Volumes cont. Step 2: Drawing of Shadow volume rendered in stencil buffer P o in t lig h t s o u rc e O b je c ts C a m e ra 1 0 1 2 11/7/2015 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 11/7/2015 CS 752 Interactive Graphics Software Shadow Volumes cont. Pro: greatly improved realism hardware support of stencil buffer Contra: 11/7/2015 high requirement on fill-rate sharp shadow additional scene management 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 unshadowed objects 11/7/2015 Saves time shading pixels More polygons (potentially many more) Precision problems CS 752 Interactive Graphics Software Starting the SVBSP Tree 11/7/2015 CS 752 Interactive Graphics Software Continuing the SVBSP Tree 11/7/2015 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 11/7/2015 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. 11/7/2015 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 selfshadowing, and the shadows are crisp. Bad: shadow polygons must be generated and rendered (lots of polygons & fill), CPU intensive. 11/7/2015 CS 752 Interactive Graphics Software