410 likes | 490 Views
Basic Shadow Methods. Jim X. Chen George Mason University. Light source. Light. Creator. Receiver. Shadow. Observation: Shadows are places light does not reach. Light source. Creator and receiver. Creator. Receiver. Definitions. Light sources Shadow creator(occluder)s and receivers.
E N D
Basic Shadow Methods Jim X. Chen George Mason University CS 752 Interactive Graphics Software
Light source Light Creator Receiver Shadow Observation: Shadows are places light does not reach. CS 752 Interactive Graphics Software
Light source Creator and receiver Creator Receiver Definitions • Light sources • Shadow creator(occluder)s and receivers CS 752 Interactive Graphics Software
Shadows 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 CS 752 Interactive Graphics Software
Light Cap Side Shadow Volume Dark Cap (at infinity) Shadow Volume • A point is shadowediff it is in at least one shadow volume 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 CS 752 Interactive Graphics Software
Soft Shadows 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? CS 752 Interactive Graphics Software
Anti-Aliasing • Supersampling • Jittering – Stochastic Method eye CS 752 Interactive Graphics Software
Supersampling • 1 sample per pixel CS 752 Interactive Graphics Software
Supersampling • 16 samples per pixel CS 752 Interactive Graphics Software
Supersampling • 256 samples per pixel 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 CS 752 Interactive Graphics Software
Result: Hard Shadow - Cube Without antialiasing With antialiasing CS 752 Interactive Graphics Software
Result: Soft Shadow - Ball Hard shadow Soft shadow CS 752 Interactive Graphics Software
More Shadow Algorithms • Fake Shadow • Vertex Projection • Shadow Z-Buffer • Shadow Volume • … 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 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 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 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 CS 752 Interactive Graphics Software
Shadow Z-buffer 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 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 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 CS 752 Interactive Graphics Software
Shadow Volume Techniques 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 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 CS 752 Interactive Graphics Software
Using Stencil Test • Three steps: • 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 (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 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 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 CS 752 Interactive Graphics Software
Shadow Volumes cont. • Step 2: Drawing of Shadow volume • rendered in stencil buffer 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 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 CS 752 Interactive Graphics Software
Shadow Volume BSP Trees • Instead of calculating shadows in imagecalculate in object space • Break up objects into shadowed and un-shadowed objects • Saves time shading pixels • More polygons (potentially many more) • Precision problems CS 752 Interactive Graphics Software
Starting the SVBSP Tree CS 752 Interactive Graphics Software
Continuing the SVBSP Tree 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 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. 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. CS 752 Interactive Graphics Software