11/24/2016 16:45 graphics ii 91.547 shadow maps reflections session 5

Post on 17-Jan-2018

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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 color

TRANSCRIPT

105/03/23 16:28

Graphics II 91.547

Shadow MapsReflections

Session 5

205/03/23 16:28

Shadow Maps

Eye Point

Light Source

Objects

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

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

505/03/23 16:28

Finite light sources produce“soft shadows”

Finite sizelight source

Shadowingobject

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”

705/03/23 16:28

The Accumulation Buffer

Color Planes

Accumulation Buffer

Color data

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.

905/03/23 16:28

Accumulation Bufferop = GL_ACCUM

Value

X

Color PlanesAccumulation Buffer

1005/03/23 16:28

Accumulation Bufferop = GL_LOAD

Value

X

Color PlanesAccumulation Buffer

1105/03/23 16:28

Accumulation Bufferop = GL_RETURN

Value

X

Color PlanesAccumulation Buffer

1205/03/23 16:28

Accumulation Bufferop = GL_MULT

Value

X

Accumulation Buffer

1305/03/23 16:28

Projection ShadowsCode example.

120 goto 240

1405/03/23 16:28

Reflections

Direct ray

Reflected ray

Eye point

Plane of Reflection

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

1605/03/23 16:28

Reflection transformations:the general case

X - Z plane

Arbitrary plane

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

1805/03/23 16:28

Reflections:Visibility Issues

Finite SizeReflectingObject

Eyepoint

Real ConeReal Ball

Reflected ConeReflected BallNot Visible

1905/03/23 16:28

Reflections:Visibility Issues

Finite SizeReflectingObject

Eyepoint

Real ConeShould be obstructed byreflecting object

“Reflected Cone”Should not be visible

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)

2105/03/23 16:28

Projection ShadowsCode example.

120 goto 240

2205/03/23 16:28

Rendered with Ray Tracing

2305/03/23 16:28

Arbitrarily shaped reflective object.

Eye point

2405/03/23 16:28

Sphere Map

2505/03/23 16:28

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:

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.

2805/03/23 16:28

Obtaining the Sphere Map Manually

Camera

Reflective Sphere atobject location

2905/03/23 16:28

Generating a Sphere Map:Image Cube Algorithm

3005/03/23 16:28

Four of the sixcube environment projections

3105/03/23 16:28

Sphere map generated byImage cube faces

top related