Sphere mapping is an implementation of environment mapping. Environment mapping is a computer graphics technique which uses a two-dimensional image (or images) containing the incident illumination from every direction at a given point. When rendering, the light from the point is computed as a function of the outgoing direction and the environment map. The outgoing direction is used to choose one or more incoming directions, or points in the environment map, which are used to compute the outgoing color.[35] In general, only one environment map point is used for each outgoing ray, resulting in a perfect specular reflection.
In rendering, we often use a single environment map for an entire object by assuming that the single environment map is a reasonable approximation of the environment map which would be computed at each point on the object. This approximation is correct if the object is a sphere and the viewer and other objects in the scene are infinitely far away. The approximation becomes less correct if the object has interreflections (i.e., it's not convex) and if the viewer and other objects are not at infinity. In interactive polygonal rendering, we make the additional assumption that the indices into the environment map may be computed at each vertex and linearly interpolated over each polygon. In spite of these simplifying assumptions, results in practice are generally quite good.
While rendering, we compute the outgoing direction as a function of the eyepoint and the normal at the surface. We can use environment maps to represent any effect that depends only upon the viewing direction and the surface normal. These effects include specular and directional diffuse reflection, refraction, and Phong lighting. We will discuss several of these effects in the context of OpenGL's sphere mapping capability.
Sphere mapping is a type of environment mapping in which the irradiance image is equivalent to that which would be seen in a perfectly reflective hemisphere when viewed using an orthographic projection.[35] This concept is illustrated in Figure 27. The sphere map is computed in the viewing plane. The width and height of the plane are equal to the diameter of the sphere. Rays fired using the orthographic projection are shown in blue (dark gray). In the center of the sphere, the ray reflects back to the viewer. Along the edges of the sphere, the rays are tangent and go behind the sphere.
Note that since the sphere map computes the irradiance at a single point, the sphere is infinitely small. Since the projection is orthographic, this implies that each texel in the image is also infinitely small. In effect, we take the limit as the size of the sphere (and the size of each texel) approaches 0. All of the rays along the outside of the sphere will map to the same point directly behind the sphere in the environment.