Static and Dynamic Environment Mapping

CPE 572 - Dr. Zoe Wood

by Paul Sullivan

Introduction

For my final project I implemented static and dynamic environment mapping using cube maps.

Description

Environment mapping is a relatively computationally cheap way of creating the illusion of reflections and refractions. The idea is that you use a texture laid out like a cube to represent the world you want an object to reflet. This texture could either be a premade file (static) or a rendering of the scene around the object (dynamic). In the picture above, I applied static environment mapping to the bunny using as texture of mountians and iceburgs. I also set up a cube surrounding the bunny with and textured each face with the same texture. This gives the illusion that the buny is relfecting this world. To be more specific, OpenGL offers a special type of texture called a cube map. When you set up this kind of texture in C++ code you must designate a texture for each of the 6 faces of the cube. The cube map isthen passed to the shaders, where one can read from it similarly to regular textures using a vector as the input. In the shaders I calculate the proper reflections based off of the viewer's location then used to sample the cube map. Once I got this working it was pretty easy to add refractions by tweaking the vector used to sample the cube map. I added a toggle key and the ability to adjust the ratio of the indicies of refraction.

Above are two screenshots of refraction with different indices of refraction. The ratio is 1.3 on the first picture and 1.1 on the second one. The difference is subtle, but the second picture has less intense refraction.

I then decided to take things a step farther and try dynamic environment mapping. Rather than sampling the same texture, moved the camera around the secene, rendered the scene, and saved it to a framebuffer. I then attached the results of this process to the cubemap and sampeled it normally. Unfortunately, I have a bug where only one face of the cubemap actually gets data from the framebuffer. I looked extencively into the problem and was unable to determine why it was doing this. Regardless, the picture below clearly shows that the environment is being used to make the texture.

Finally, here are two images of a sphere with environment mapping. The first picture shows reflection while the second one shows refraction.

Video

Controls

Sources