shadows shadows what for shadows tell us about the
play

Shadows Shadows What for? Shadows tell us about the relative - PDF document

Shadows Shadows What for? Shadows tell us about the relative locations and motions of objects and motions of objects Vienna University of Technology 2 What for? Shadows tell us about the relative locations and motions of objects and


  1. Shadows Shadows

  2. What for? Shadows tell us about the relative locations and motions of objects and motions of objects Vienna University of Technology 2

  3. What for? Shadows tell us about the relative locations and motions of objects and motions of objects And about light positions Vienna University of Technology 3

  4. What for? Objects look like they are “floating” � Shadows can fix that! � Shadows can fix that! Vienna University of Technology 4

  5. Motivation Shadows contribute significantly to realism of rendered images rendered images Anchors objects in scene Global effect � expensive! Global effect � expensive! Light source behaves very similar to camera Is a point visible from the light source? � shadows are “hidden” regions g Shadow is a projection of caster on receiver � projection methods � projection methods Best done completely in hardware through shaders Vienna University of Technology 5

  6. Shadow Algorithms Static shadow algorithms (lights + objects) Radiosity ray tracing � lightmaps Radiosity, ray tracing � lightmaps Approximate shadows Projected shadows (Blinn 88) Shadow volumes (Crow 77) Object-space algorithm Shadow maps (Williams 78) Shadow maps (Williams 78) Projective image-space algorithm Soft shadow extensions for all above algorithms S f h d i f ll b l i h Still hot research topic (500+ shadow publications) Vienna University of Technology 6

  7. Shadow Terms li ht light source creator (occluder, blocker, caster) ( ) creator and receiver receiver (occludee) ( ) Vienna University of Technology 7

  8. Hard vs. Soft Shadows point source point source area source area source umbra umbra hard shadow hard shadow +fast +fast p penumbra penumbra penumbra penumbra p -only good for localized lights only good for localized lights + very realistic + very realistic (sun, projectors) (sun, projectors) - very expensive very expensive +fake soft shadow through +fake soft shadow through +fake soft shadow through +fake soft shadow through + becomes more and more + becomes more and more filtering filtering usable usable Vienna University of Technology 8

  9. Static Shadows Glue to surface whatever we want Id Idea: incorporate shadows into light maps i t h d i t li ht For each texel, cast ray to each light source Bake soft shadows in light maps Not by texture filtering alone but: Not by texture filtering alone, but: Sample area light sources Vienna University of Technology 9

  10. Static Soft Shadow Example no filtering no filtering filtering filtering 1 1 1 sample 1 sample l l n samples n samples Vienna University of Technology 10

  11. Approximate Shadows Hand-drawn approximate geometry Perceptual studies suggest: Perceptual studies suggest: shape not so important Minimal cost Vienna University of Technology 11

  12. Approximate Shadows Dark polygon (maybe with texture) Cast ray from light source through object center Cast ray from light source through object center Blend polygon into frame buffer at location of hit May apply additional rotation/scale/translation May apply additional rotation/scale/translation Incorporate distance and receiver orientation Problem with z-quantization: P bl ith ti ti light light viewer viewer Blend at hit polygon Blend at hit polygon p yg p yg Z- -test equal test equal � z-buffer quantization errors! buffer quantization errors! Vienna University of Technology 12

  13. Approximate Shadows light light light light viewer viewer viewer viewer Elevate above hit polygon Elevate above hit polygon Z- -test less or equal test less or equal � h d � shadow too big shadow too big h d t t bi bi � may appear floating may appear floating No z No z- -test, only one eye ray test, only one eye ray � shadow too big � shadow too big, shadow too big shadow too big, maybe in wrong place maybe in wrong place Vienna University of Technology 13

  14. Projection Shadows (Blinn 88) Shadows for selected large planar receivers Ground plane Ground plane Walls Projective geometry: flatten 3D model onto flatten 3D model onto plane and “darken” using “ ” framebuffer blend Vienna University of Technology 14

  15. Projection for Ground Plane Use similar-triangle tricks − l l l l y p p l l y = y x x − − v l l v x x x x y y y y − l l v l l v = y x x y p − v x l v y y y y − l v l v = y=0 y=0 y z z y p p − z p l v y y = p p 0 0 y Vienna University of Technology 15

  16. Projection Matrix l Projective 4x4 matrix: − ⎛ ⎛ ⎞ ⎞ l l l l 0 0 0 0 ⎜ ⎟ y x ⎜ ⎟ 0 0 0 0 v = ⎜ ⎜ M M − 0 l l 0 ⎜ ⎟ z y p ⎜ − l y ⎠ ⎝ ⎝ ⎠ 0 0 1 1 0 0 l Arbitrary plane: y p n Intersect line p = l – α ( v – l ) with plane n x + d = 0 ith l d 0 Express result as a 4x4 matrix p Append this matrix to view transform Vienna University of Technology 16

  17. Projection Shadow Algorithm Render scene (full lighting) F For each receiver polygon h i l Compute projection matrix M Append to view matrix Render selected shadow caster Render selected shadow caster With framebuffer blending enabled Vienna University of Technology 17

  18. Projection Shadow Artifacts Bad Bad Good Good extends off t d ff ground region Z fighting double blending Vienna University of Technology 18

  19. Stencil Buffer Projection Shadows Stencil can solve all of these problems Separate 8 bit frame buffer for numeric ops Separate 8-bit frame buffer for numeric ops Stencil buffer algorithm (requires 1 bit): Clear stencil to 0 Draw ground polygon last and with Draw ground polygon last and with glStencilOp(GL_KEEP, GL_KEEP, GL_ONE); fail f il f il fail zfail zfail f il f il pass pass Draw shadow caster with no depth test but glStencilFunc(GL_EQUAL, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); Every plane pixel is touched at most once Vienna University of Technology 19

  20. Stencil Buffer Planar Reflections Draw object twice, second time with: glScalef(1, -1, 1) glScalef(1, 1, 1) Reflects through floor Bad Bad Good stencil Good, stencil used to limit reflection. Vienna University of Technology 20

  21. Projection Shadow Summary Easy to implement GLQuake first game to implement it GLQuake first game to implement it Only practical for very few, large receivers No self shadowing Possible remaining artifacts: wrong shadows g g Objects behind light source Objects behind recei er Objects behind receiver Vienna University of Technology 21

  22. Shadow Volumes (Crow 1977) Occluders and light source cast out a 3D shadow volume shadow volume Shadow through new geometry Results in Pixel correct shadows Light source Visualization of Visualization of Visualization of Visualization of Shadowed scene Shadowed scene Shadowed scene Shadowed scene shadow volume shadow volume Vienna University of Technology 22

  23. Shadow Volumes (Crow 1977) Heavily used in Doom3 23 Vienna University of Technology

  24. 2D Cutaway of Shadow Volume Occluder polygons extruded to semi-infinite volumes volumes surface outside shadow volume shadowing object (illuminated) light source source shadow shadow volume ( infinite extent ) eye eye position surface inside partially shadowed shadow volume object object (shadowed) Vienna University of Technology 24

  25. Shadow Volume Algorithm 3D point-in-polyhedron indide-outside test Principle similar to 2D point-in-polygon test Principle similar to 2D point-in-polygon test Choose a point known to be outside the volume C Count intersection on ray from test point to known t i t ti f t t i t t k point with polyhedron faces Front face +1 F t f 1 Back face -1 Lik i di l ! Like non-zero winding rule! Known point will distinguish algorithms: Infinity: “Z-fail” algorithm Eye-point: “Z-pass” algorithm y p p g Vienna University of Technology 25

  26. Enter/Leave Approach Increment on enter, decrement on leave Si Simultaneously test all visible pixels lt l t t ll i ibl i l � Stop when hitting object nearest to viewer light shadowing object source zero +1 zero +2 +2 eye y +1 +3 +3 position Vienna University of Technology 26

  27. Shadow Volume Algorithm Shadow volumes in object precision Calculated by CPU/Vertex Shaders Calculated by CPU/Vertex Shaders Shadow test in image precision Using stencil buffer as counter! Vienna University of Technology 27

  28. Shadow Volume Algorithm Step 1: Render scene ⇒ Z-values Vienna University of Technology 28

  29. Shadow Volume Algorithm Front face: +1 Back face: -1 Step 2: Render shadow volume faces Vienna University of Technology 29

  30. Shadow Volume Algorithm Front face: Front face: ±0 (Depth test) ±0 (Depth test) Back face: ±0 (Depth test) Σ = ±0 Vienna University of Technology 30

  31. Shadow Volume Algorithm ±0 Front face: Front face: +1 +1 Back face: ±0 (Depth test) Σ = +1 Vienna University of Technology 31

  32. Shadow Volume Algorithm +1 ±0 Front face: Front face: +1 +1 Back face: -1 Σ = ±0 Vienna University of Technology 32

  33. Shadow Volume Algorithm ±0 +1 ±0 Step 3: Apply shadow mask to scene Vienna University of Technology 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend