1 / 28

Shadows CS 446: Real-Time Rendering & Game Technology

Shadows CS 446: Real-Time Rendering & Game Technology. David Luebke University of Virginia. Demo. Today: Jiajun Zhu Tuesday: Ted Yokoyama . Assignments. Reminder: integrated version of assn 4 due today Group turns in whole project today

lucius
Download Presentation

Shadows CS 446: Real-Time Rendering & Game Technology

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. Shadows CS 446: Real-Time Rendering & Game Technology David Luebke University of Virginia

  2. Demo • Today: Jiajun Zhu • Tuesday: Ted Yokoyama Real-Time Rendering

  3. Assignments • Reminder: integrated version of assn 4 due today • Group turns in whole project today • Individuals taking late days turn in a new version of whole project when their changes are integrated • Remember, show up to class or assignment due in the morning… Real-Time Rendering

  4. Recap: Shadow Notation • Light source • Point vs area • Occluders & receivers • Identify ahead of time? • Self-shadowing? • Shadow • Umbra • Penumbra • Soft vs hard shadows Real-Time Rendering

  5. Recap: Planar Shadows • Old trick: project the occluder geometry to a plane and render over ground plane • Can do with a matrix • Z-bias issues • Semiopaque shadows harder • Stencil and Z-buffer tricks • Another option: generate textured rectangle • Problems • Light source inside object (Antishadows) • Only planar receivers  no self-shadowing Real-Time Rendering

  6. Planar Soft Shadows • Basic idea: • Sample light source multiple times, average results (accumulation buffer) into a texture • Gooch et al: move plane up and down • Nested shadows fewer passes Real-Time Rendering

  7. Projective Shadows • Render scene from light’s point of view • Render all occluders as black • Can turn off depth buffer etc • Project onto receiver polygons using projective texture mapping • Works for curved surfaces • Designer separates occluders and receivers  no self-shadowing Real-Time Rendering

  8. Shadow Volumes • Basic idea: • Create polygonal objects to represent shadowed volumes • Make clever use of stencil buffer so that these objects affect what lighting is done Real-Time Rendering

  9. Stencil Buffer • The stencil buffer has been around since OpenGL 1.0 • Basic idea: provide a per-pixel flag to indicate whether pixels are drawn or not • But… • Let that flag be an integer (usually 8 bits) • Usually shared with depth buffer • And let drawing operations increment or decrement the stencil buffer based on different events • Always, depth-pass, depth-fail, etc. Real-Time Rendering

  10. Shadow Volumes • Details of the basic algorithm: • Compute shadow volumes • View-independent! • Clear stencil buffer • Render the scene without diffuse/spec lighting • “Render” front faces of shadow volumes • Turn off color, depth updates (but leave depth test on) • Visible polygons increment pixel stencil buffer count • “Render” back faces of shadow volumes • Turn off color, depth updates (but leave depth test on) • Visible polygons decrement pixel stencil buffer count • Render scene with only diffuse/spec lighting • Only update pixels where stencil = 0

  11. Shadow Volumes • Refinements (see book, next slides) • NV30, XBox supports signed stencil addition • Two-sided lighting determines whether polygon adds or subtracts 1 from stencil buffer • One-pass algorithm! But a little slower in practice? • What if you’re inside a shadow volume? • Invert meaning of stencil test • What if near clip intersects shadow plane? • Carmack, others: use z-fail test • Clever extensions in NV2X help this idea out • Creating shadow volumes: vertex program! • ATI: clever degenerate-edge trick again

  12. Shadow Volumes • Advantages: • Robust • Self-shadowing • GPU • Disadvantages: • Can be geometry limited • Stencil polys • Multi-pass scene geometry • Can be fill limited • Stencil test – per pixel expense • Hard shadows

  13. Shadow Volumes • Will return to the gruesome details shortly Real-Time Rendering

  14. Shadow Maps • Idea: • Render scene from light source, read Z-buffer • Result: discretized image (shadow map) telling distance of objects to light source • Render scene normally • At each pixel, calculate distance D to light • Compare to distance S stored in shadow map • If D=S, surface lit by light, else in shadow Real-Time Rendering

  15. Shadow Maps • The basic algorithm (w/o hardware) • Render scene with ambient lighting only • Read Z-buffer, transform values into coordinate system of light • Use comparison to set alpha buffer • Render w/ diffuse and specular components, multiplying by alpha Real-Time Rendering

  16. Shadow Maps • Advantages: • Hardware-accelerated general shadow algorithm • Supports self-shadowing • Cost is linear in # lights and # polygons • Disadvantages: • Self-shadow aliasing • Biasing and other techniques can help, but not fix • Shadow map resolution critical! • Solution: perspective shadow maps Real-Time Rendering

  17. Taken from: Practical & RobustStenciled Shadow Volumes for Hardware-Accelerated Rendering Cass Everitt & Mark J. Kilgard, NVIDIA GDC 2003 See the accompanying paper at: http://developer.nvidia.com/object/robust_shadow_volumes.html Also see: http://developer.nvidia.com/object/fast_shadow_volumes.html

  18. 2D Cutaway of a Shadow Volume Surface outsideshadow volume (illuminated) Shadowingobject Lightsource Shadowvolume (infinite extent) Eye position (note that shadows are independent of the eye position) Surface insideshadow volume (shadowed) Partially shadowed object

  19. Shadow Volume Advantages • 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)

  20. Shadow Volume Disadvantages • Ideal light sources only • Limited to local point and directional lights • No area light sources for soft shadows • Requires polygonal models with connectivity • Models must be closed (2-manifold) • Models must be free of non-planar polygons • Silhouette computations are required • Can burden CPU • Particularly for dynamic scenes • Inherently multi-pass algorithm • Consumes lots of GPU fill rate

  21. Visualizing Shadow Volumes in 3D • Occluders and light source cast out a shadow volume • Objects within the volume should be shadowed Lightsource Scene with shadows from an NVIDIA logo casting a shadow volume Visualization of the shadow volume

  22. Visualizing the Stencil Buffer Counts Shadowed scene Stencil buffer contents Stencil counts beyond 1 are possible for multiple or complex occluders. red = stencil value of 1green = stencil value of 0 GLUT shadowvol example credit: Tom McReynolds

  23. Algorithm • Render scene to initialize depth buffer • Depth values indicate the closest visible fragments • Use a stencil enter/leave counting approach • Draw shadow volume twice using face culling • 1st pass: render front faces and increment when depth test passes • 2nd pass: render back faces and decrement when depth test passes • Don’t update depth or color • Afterward, pixel’s stencil is non-zero if pixel in shadow, and zero if illuminated

  24. Why Eye-to-Object Stencil Enter/ Leave Counting Approach Works Lightsource Shadowing object zero +1 zero +2 +2 Eyeposition +1 +3

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

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

  27. Illuminated,In Front of Shadow Volumes Lightsource Shadowing object zero +1 zero Shadowedobject +2 +2 Eyeposition +1 +3 Shadow Volume Count = 0

  28. Problems Created by Near Plane Clipping (Zpass approach) 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

More Related