Sphere Mapping

Description

Sphere Mapping is an environment mapping, or reflection mapping technique, that simulates environment reflections on an object's surface, using a texture map.

The texture map contains an image (light probe) of the surrounding environment reflected on a perfect mirror ball and captured, using an orthographic projection.
Such an image could also be generated during the rendering using a fish eye camera model.

An example of a light probe image and a scene using this image as environment map.

(Source: http://www.pauldebevec.com/Probes/)

For each pixel on the surface the reflected direction from the object to the environment (the reflection vector) is used to look up a reflection color in the environment map.
This color is then added to the final shading.

For more information about environment mapping techniques you can also read the Wikipedia articles about Reflection Mapping and Sphere Mapping.

Implementation

The idea of the sphere mapping shader is to produce two color values for each pixel, the diffuse lighting color and the reflection color, and to combine these into the final shading color.

Steps:

  • Calculate the reflection vector and diffuse lighting (Lambert illumination model) for each vertex (Gouraud shading) or for each fragment (Phong shading). The following formula is used for the reflection vector calculation. N is the unit surface normal, V is the unit view vector, and R is the reflection vector.

  • Calculate the texture coordinates for the lookup using the reflection vector.

  • Look up the reflection color in the environment texture.
  • Finally combine the reflection color and the diffuse lighting color into the final shading color.

Tips:

  • Define a uniform variable, in order to control in what ratio the diffuse lighting and the reflection colors are mixed.
  • Make sure that the V and N vectors are normalized.
  • The CG1 framework already has a method implementation for calculating the reflection vector (Vec3.reflect()).

Sample Output

Suzanne-hires.dae rendered with sphere mapping shader using Phong shading and the grace_probe.png texture.

Sources

grace_probe.png light probe

(Source: http://www.pauldebevec.com/Probes/)

References

Randi J. Rost, OpenGL Shading Language, Second Edition, Addison Wesley Professional, 2006

Wikipedia, Reflection Mapping, Sphere Mapping

Udo Bischof , Environment Mapping, BTU-Cottbus, 2006

Light Probe Image Gallery

Real-Time Computation of Dynamic Irradiance Environment Maps(GPU Gems)

 
students/sphere-mapping.txt · Last modified: 2011/12/21 20:06 by izagralova
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki