Download presentation
Presentation is loading. Please wait.
Published byRalph Newton Modified over 9 years ago
1
11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5
2
21/24/2016 16:45 Shadow Maps Eye Point Light Source Objects
3
31/24/2016 16:45 Shadow Maps: The algorithm 1. Transform the scene objects to the light source coordinates (x’,y’,z’). 2. Disable color buffer writing and render the scene objects into the z - buffer 3. Copy this buffer into a “shadow z - buffer” 4. Transform the scene back to the eye coordinates (x,y,z). 5. Render the scene. At each pixel, if a point on a surface is deemed to be visible, it is transformed into light source coordinates: (x,y,z) -> (x’,y’,z’). The x’ and y’ coordinates are used to index into the shadow z-buffer and z’ is compared with the z value in the buffer. If z’ is greater than this value, the point is in shadow and it is rendered as if the light is turned off. 6. Repeat for other light sources, and accumulate color
4
41/24/2016 16:45 Shadow Maps Tradeoffs 0 Excellent for situations when shadowing and shadowed objects are both complex 0 Some graphics systems do not provide necessary primitives or buffers 0 Aliasing is a problem -Possible solutions =Use high - resolution shadow z buffer =Jitter shadow texture to smooth out edges 0 Difficult to find appropriate projection when light source is in the middle of scene objects
5
51/24/2016 16:45 Finite light sources produce “soft shadows” Finite size light source Shadowing object
6
61/24/2016 16:45 Simulating finite size light source by Multiple point sources: “dithering” Light source moves in grid Shadowing Object (polygon) Plane of projection Shadows are “accumulated”
7
71/24/2016 16:45 The Accumulation Buffer Color Planes Accumulation Buffer Color data
8
81/24/2016 16:45 Accumulation buffer use: void glAccum(glenum op,glFloat value); op: GL_ACCUM reads each pixel from buffer currently selected for reading and multiplies RGBA values by value and adds the result to accumulation buffer. GL_LOAD reads each pixel from the buffer currently selected for reading, multiplies RGBA values by value and replaces values in accumulation buffer. GL_RETURN takes values from the accumulation buffer, mutiplies them by value, and places them in the color buffer. GL_ADD, GL_MULT adds or multiplies the value of each pixel in the accumulation buffer by value and returns it to the accumulation buffer.
9
91/24/2016 16:45 Accumulation Buffer op = GL_ACCUM Value X Color Planes Accumulation Buffer
10
101/24/2016 16:45 Accumulation Buffer op = GL_LOAD Value X Color Planes Accumulation Buffer
11
111/24/2016 16:45 Accumulation Buffer op = GL_RETURN Value X Color Planes Accumulation Buffer
12
121/24/2016 16:45 Accumulation Buffer op = GL_MULT Value X Accumulation Buffer
13
131/24/2016 16:45 Projection Shadows Code example. 120 goto 240
14
141/24/2016 16:45 Reflections Direct ray Reflected ray Eye point Plane of Reflection
15
151/24/2016 16:45 Reflection Transformations: across major planes of symmetry Y- Z PlaneX - Z PlaneX - Y Plane
16
161/24/2016 16:45 Reflection transformations: the general case X - Z plane Arbitrary plane
17
171/24/2016 16:45 Reflection Transformations: the general case - constructing the transformation Inverse transformationReflection across X - Z Plane Transformation to move reflecting plane to X - Z plane
18
181/24/2016 16:45 Reflections: Visibility Issues Finite Size Reflecting Object Eyepoint Real Cone Real Ball Reflected Cone Reflected Ball Not Visible
19
191/24/2016 16:45 Reflections: Visibility Issues Finite Size Reflecting Object Eyepoint Real Cone Should be obstructed by reflecting object “Reflected Cone” Should not be visible
20
201/24/2016 16:45 Solution to visibility issues: use stencil and z buffer The algorithm: 1. Disable the depth test 2. Set stencil operation to replace with 1 3. Draw the reflecting polygon 4. Set the stencil operation to only draw where stencil=1 5. Multiply reflecting transformation onto modelview matrix 6. Enable depth test, render objects. Clip objects that are on opposite side of the reflecting plane from eyepoint. 7. Disable stencil test 8. Remove reflection transformation from modelview 9. Disable writing to color buffer 10. Draw the reflecting polygon 11. Enable writing to color buffer 12. Render the scene (unreflected)
21
211/24/2016 16:45 Projection Shadows Code example. 120 goto 240
22
221/24/2016 16:45 Rendered with Ray Tracing
23
231/24/2016 16:45 Arbitrarily shaped reflective object. Eye point
24
241/24/2016 16:45 Sphere Map
25
251/24/2016 16:45
26
261/24/2016 16:45 Calculation of Texture Coordinates For each vertex, the reflected vector direction is given by: Let m be defined as: The texture coordinates are given by:
27
271/24/2016 16:45 Sphere Mapping: The OpenGL Algorithm 1. Bind the texture containing the sphere map. 2. Set sphere mapping texture coordinate generation: glTexGen(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGen(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 3. Enable texture coordinate generation: glEnable(TEXTURE_GEN_S) 4. Draw the object, providing correct normals on a per- face or per-vertex basis.
28
281/24/2016 16:45 Obtaining the Sphere Map Manually Camera Reflective Sphere at object location
29
291/24/2016 16:45 Generating a Sphere Map: Image Cube Algorithm
30
301/24/2016 16:45 Four of the six cube environment projections
31
311/24/2016 16:45 Sphere map generated by Image cube faces
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.