Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 10/24/2015 13:01 UML Graphics II 91.547 Shadows Session 4.

Similar presentations


Presentation on theme: "1 10/24/2015 13:01 UML Graphics II 91.547 Shadows Session 4."— Presentation transcript:

1 1 10/24/2015 13:01 UML Graphics II 91.547 Shadows Session 4

2 2 10/24/2015 13:01 UML The General Lighting Situation Proj. Plane COP Light Source Objects

3 3 10/24/2015 13:01 UML The Simplified OpenGL Model Proj. Plane COP Light Source Objects For each object (or primitive) For each light source enabled Compute color at pixel based on: Source properties Angle, distance to source Angle to observer (COP) Material properties

4 4 10/24/2015 13:01 UML Vectors Used by Phong Lighting Model n l r v p is an arbitrary point on a surface. n is the unit normal to the surface at p. l is a unit vector in the direction of the light source. r is a unit vector in the direction of a perfectly (specular) reflection v is a unit vector in the direction of the viewer. p COP

5 5 10/24/2015 13:01 UML The Complete Phong Model Distance term Ambient term Diffuse term Specular term

6 6 10/24/2015 13:01 UML Rendered with Phong Model

7 7 10/24/2015 13:01 UML Rendered with Ray Tracing

8 8 10/24/2015 13:01 UML Information provided by shadows: Where are the balls?

9 9 10/24/2015 13:01 UML Where are the balls? Shadows show relative position.

10 10 10/24/2015 13:01 UML Shadows: How do we get them?* 1. Integration of shadow calculation with scan-line hidden surface removal 2. Projection and clipping 3. Shadow volumes 4. Shadow z-buffer 5. Recursive ray tracing 6. Radiosity *Classification due to Bergeron, 1986, quoted in Watt & Watt

11 11 10/24/2015 13:01 UML Projecting shadows Light Source Shadowing Object (polygon) Plane of projection

12 12 10/24/2015 13:01 UML Why is this model a simplification? Finite size light source Shadowing object Umbra Penumbra

13 13 10/24/2015 13:01 UML Projecting shadows Light Source Shadowing Object (polygon) Plane of projection: Projected point.

14 14 10/24/2015 13:01 UML Calculating the projection matrix Light source moved to origin.

15 15 10/24/2015 13:01 UML Calculating the projection matrix Substituting parametric expression for projection line into plane equation: Substituting  back into line equation gives the following transformation:

16 16 10/24/2015 13:01 UML Calculating the projection matrix: Performing the matrix multiplication gives: Transform to frame where light is at origin, then transform back:

17 17 10/24/2015 13:01 UML Projection shadow algorithm 1. Render all objects 2. For each light source For each shadowing object For each shadowed plane Project shadowing object onto plane Clip to dimension of shadowed polygon Render the shadow

18 18 10/24/2015 13:01 UML The Clipping Issue Light Shadow clipped at this boundary Plane 1 Plane 2

19 19 10/24/2015 13:01 UML Using the stencil buffer Color Planes Z-buffer Planes Stencil Planes glEnable(GL_STENCIL_TEST); Fragments will be drawn only if the stencil test passes.

20 20 10/24/2015 13:01 UML Using the stencil buffer, contd. void glStencilFunct(Glenum func, Glint ref, Gluint mask); func is one of: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL compares the stencil buffer value with the reference value. Void glStencilOp(Glenum fail, Glenum zfail, Glenum zpass); specifies the action to take when a fragment passes or fails the stencil test. Arguments are: GL_KEEP, G_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT

21 21 10/24/2015 13:01 UML Projection Shadows Code example. 120 goto 240

22 22 10/24/2015 13:01 UML Issues with projection shadows 0 N x N problem 0 Difficult to shadow onto anything other than flat surfaces -Polygonal objects ok, but have to project onto the plane of each polygon and clip to its edges. 0 Difficult to show shadow’s color -Shadow is a “squashed” version of object doing the shadowing, not the object being shadowed.

23 23 10/24/2015 13:01 UML Shadow Volumes Light Source Shadow volume

24 24 10/24/2015 13:01 UML Determining whether a fragment is from an object in a shadow volume. COP Shadow Volume Shadow Volume

25 25 10/24/2015 13:01 UML Determining whether a fragment is from an object in a shadow volume. COP Shadow Volume Shadow Volume For each fragment: Number of front facing shadow volume polygons minus number of back facing shadow volume polygons (that pass depth test) = zero if object is not in shadow.

26 26 10/24/2015 13:01 UML Shadow Volumes: The algorithm (for a single light source) 1. Enable color buffer and depth buffer for writing. Enable depth testing 2. Set attributes for drawing in shadow. Turn off light source. 3. Render the entire scene. 4. Compute the polygons enclosing the shadow volume. 5. Disable color and depth buffer for writing. Leave depth test. 6. Clear the stencil buffer to zero. 7. Set the stencil function to always pass

27 27 10/24/2015 13:01 UML Shadow Volumes: The algorithm (for a single light source) 8. Set the stencil operation to increment if depth passes 9. Turn on back face culling 10. Render the shadow volumes 11. Set the stencil operation to decrement if depth passes 12. Turn on front face culling 13. Render the shadow volumes 14. Set the stencil function to test for zero and the stencil operation to do nothing. 15. Enable the color and depth buffer for writing. 16. Turn on the light and render the entire scene.

28 28 10/24/2015 13:01 UML Shadow volume issues: 0 Difficult if the shadowing object is a complex shape. -Can project a separate shadow volume from each polygon but this is very inefficient -Ideally, shadow volume should be generated from vertices forming silhouette of the object. This is a non-trivial computation (see Watt & Watt for one algorithm). 0 If polygon renderer does not handle adjacent polygons correctly, the stencil count can get mixed up resulting in grossly incorrect shadows.

29 29 10/24/2015 13:01 UML Shadow Volume code example. 120 goto 240 240 goto 120 Let’s see if they are still awake


Download ppt "1 10/24/2015 13:01 UML Graphics II 91.547 Shadows Session 4."

Similar presentations


Ads by Google