11/24/2016 16:45 graphics ii 91.547 shadow maps reflections session 5
DESCRIPTION
31/24/ :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 colorTRANSCRIPT
![Page 1: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/1.jpg)
105/03/23 16:28
Graphics II 91.547
Shadow MapsReflections
Session 5
![Page 2: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/2.jpg)
205/03/23 16:28
Shadow Maps
Eye Point
Light Source
Objects
![Page 3: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/3.jpg)
305/03/23 16:28
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 - buffer3. 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
![Page 4: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/4.jpg)
405/03/23 16:28
Shadow MapsTradeoffs
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
![Page 5: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/5.jpg)
505/03/23 16:28
Finite light sources produce“soft shadows”
Finite sizelight source
Shadowingobject
![Page 6: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/6.jpg)
605/03/23 16:28
Simulating finite size light source byMultiple point sources: “dithering”
Light source moves in grid
ShadowingObject (polygon)
Plane of projection
Shadows are “accumulated”
![Page 7: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/7.jpg)
705/03/23 16:28
The Accumulation Buffer
Color Planes
Accumulation Buffer
Color data
![Page 8: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/8.jpg)
805/03/23 16:28
Accumulation buffer use:
void glAccum(glenum op,glFloat value);op:GL_ACCUM reads each pixel from buffer currently selected forreading and multiplies RGBA values by value and addsthe result to accumulation buffer.
GL_LOAD reads each pixel from the buffer currently selected forreading, multiplies RGBA values by value and replaces valuesin accumulation buffer.
GL_RETURN takes values from the accumulation buffer, mutipliesthem by value, and places them in the color buffer.
GL_ADD, GL_MULT adds or multiplies the value of each pixel inthe accumulation buffer by value and returns it to the accumulation buffer.
![Page 9: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/9.jpg)
905/03/23 16:28
Accumulation Bufferop = GL_ACCUM
Value
X
Color PlanesAccumulation Buffer
![Page 10: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/10.jpg)
1005/03/23 16:28
Accumulation Bufferop = GL_LOAD
Value
X
Color PlanesAccumulation Buffer
![Page 11: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/11.jpg)
1105/03/23 16:28
Accumulation Bufferop = GL_RETURN
Value
X
Color PlanesAccumulation Buffer
![Page 12: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/12.jpg)
1205/03/23 16:28
Accumulation Bufferop = GL_MULT
Value
X
Accumulation Buffer
![Page 13: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/13.jpg)
1305/03/23 16:28
Projection ShadowsCode example.
120 goto 240
![Page 14: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/14.jpg)
1405/03/23 16:28
Reflections
Direct ray
Reflected ray
Eye point
Plane of Reflection
![Page 15: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/15.jpg)
1505/03/23 16:28
Reflection Transformations:across major planes of symmetry
1 0 0 00 1 0 00 0 1 00 0 0 1
1 0 0 00 1 0 00 0 1 00 0 0 1
1 0 0 00 1 0 00 0 1 00 0 0 1
Y- Z Plane X - Z Plane X - Y Plane
![Page 16: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/16.jpg)
1605/03/23 16:28
Reflection transformations:the general case
X - Z plane
Arbitrary plane
![Page 17: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/17.jpg)
1705/03/23 16:28
Reflection Transformations:the general case - constructing the transformation
1 0 0 00 1 0 00 0 1 00 0 0 1
Inverse transformation Reflection acrossX - Z Plane
Transformation tomove reflecting plane to X - Z plane
TT 1
![Page 18: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/18.jpg)
1805/03/23 16:28
Reflections:Visibility Issues
Finite SizeReflectingObject
Eyepoint
Real ConeReal Ball
Reflected ConeReflected BallNot Visible
![Page 19: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/19.jpg)
1905/03/23 16:28
Reflections:Visibility Issues
Finite SizeReflectingObject
Eyepoint
Real ConeShould be obstructed byreflecting object
“Reflected Cone”Should not be visible
![Page 20: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/20.jpg)
2005/03/23 16:28
Solution to visibility issues:use stencil and z buffer
The algorithm:
1. Disable the depth test2. Set stencil operation to replace with 13. Draw the reflecting polygon4. Set the stencil operation to only draw where stencil=15. Multiply reflecting transformation onto modelview matrix6. Enable depth test, render objects. Clip objects that are on opposite side of the reflecting plane from eyepoint.7. Disable stencil test8. Remove reflection transformation from modelview9. Disable writing to color buffer10. Draw the reflecting polygon11. Enable writing to color buffer12. Render the scene (unreflected)
![Page 21: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/21.jpg)
2105/03/23 16:28
Projection ShadowsCode example.
120 goto 240
![Page 22: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/22.jpg)
2205/03/23 16:28
Rendered with Ray Tracing
![Page 23: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/23.jpg)
2305/03/23 16:28
Arbitrarily shaped reflective object.
Eye point
![Page 24: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/24.jpg)
2405/03/23 16:28
Sphere Map
![Page 25: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/25.jpg)
2505/03/23 16:28
![Page 26: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/26.jpg)
2605/03/23 16:28
Calculation of Texture Coordinates
r (n' u' )n' u'
2
2 1
12
12
2 2 2m r r r
s rm
trm
x y z
x y
( )
For each vertex, the reflected vector direction is given by:
Let m be defined as:
The texture coordinates are given by:
![Page 27: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/27.jpg)
2705/03/23 16:28
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)glEnable(TEXTURE_GEN_S)
4. Draw the object, providing correct normals on a per- face or per-vertex basis.
![Page 28: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/28.jpg)
2805/03/23 16:28
Obtaining the Sphere Map Manually
Camera
Reflective Sphere atobject location
![Page 29: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/29.jpg)
2905/03/23 16:28
Generating a Sphere Map:Image Cube Algorithm
![Page 30: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/30.jpg)
3005/03/23 16:28
Four of the sixcube environment projections
![Page 31: 11/24/2016 16:45 Graphics II 91.547 Shadow Maps Reflections Session 5](https://reader036.vdocuments.site/reader036/viewer/2022062503/5a4d1afa7f8b9ab059983984/html5/thumbnails/31.jpg)
3105/03/23 16:28
Sphere map generated byImage cube faces