You are on page 1of 11

Trompe Loeil

The Triumph of St. Ignatius

Environment Mapping
We can also use texturing to simulate reflections imagine enclosing object in a box project the world onto the sides of the box for any point on the object, compute reflection by looking up appropriate reflected direction in the cube map Fairly easy to generate place camera at center of object render scene for each side of the box But not totally accurate reflections are only accurate for point at which the images were taken all other reflections are incorrect but people generally never notice

Projection of Reflection Vectors


Environment mapping maps reflection vectors to texture

viewing direction u
reflection vector r Need a projection function for reflection vector

r ( s, t )

Projecting Reflection Directions


The set of all unit direction vectors is the unit sphere

Thus, any parameterization of the unit sphere will do but some are better than others Example: compute latitude/longitude angles and scale to [0,1] introduces significant distortion especially at poles

Geometry of Sphere Maps

reflected rays

image plane

Spherical Projection of Reflection Vectors


r = ( x , y, z )
Reflection vector: r = u 2( n u)n

n u

Resulting texture coordinates: x 1 y 1 s= + t= + 2m 2 2m 2


m = x 2 + y 2 + ( z +1)2 = 2( z +1)

n : unit normal u : unit viewing direction r : unit reflected direction All in eye space!

Environment Mapping with OpenGL


OpenGL uses spherical projection sphere map is view dependent must regenerate when camera moves or else see the same thing

To use environment maps first create the map image then enable texture coordinate generation
glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T);

and instruct OpenGL to generate texture coordinates


glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

Sphere Maps and Cube Maps

unit sphere

unit cube

There is a natural mapping between these two

Sphere Maps for Texture Shading

Adding Silhouettes with Sphere Maps

Add black rim around the edge of the sphere map


(not shown)

Filtered Environment Maps

You might also like