article

Shadow mapping is a process, by which, shadows are added to 3D computer graphics. This concept was introduced by Lance Williams in 1978, in a paper entitled "Casting curved shadows on curved surfaces". Since then, it has been used both in pre-rendered scenes and in realtime. Shadow mapping is used by Pixar's RenderMan, and likewise, shadow mapping has been used in such films as Toy Story.

Shadows are created by testing whether a pixel is visible from the light source, by comparing it to a z-buffer or depth image, in the form of a texture. This technique involves three passes or re-renderings, although it can be accomplished with just two.

Principle of a shadow and a shadow map


A shadow can be considered thus: Imagine you have a spot light source, that is aimed at some objects. The shadow thus cast by this light source can be visualized by viewing through the light source at the objects and marking the visible areas, and disregarding every point not seen by the light source as "shadow".

The complexity of this simple operation becomes apparent when one considers the amount of photons that are incident on the surface of the objects. The sheer number of photons incident cannot be simulated at real-time even by current fastest computers. Hence to make this effect more accessible to people via games, 3D modelling tools, visualization tools, etc, programmers employ a number of techniques to fake this complex shadow operation. The following is a partial list of algorithms that most programmers use to approach this problem:

Though current computer games are leaning toward a mixture of shadow volume techniques and shadow volumes, the explosion of growth in the graphics card arena has favored more toward shadow mapping, since memory is the only limitation for shadow mapping.

Algorithm overview


As in any other graphics discussion, the standard camera, spot-light are assumed to exist. The camera (usually a perspective camera) points toward the scene, and the algorithm must paint the shadowed region using appropriate color — usually by dark color, although some might replace this dark color with a texture so as to achieve the effect of a projector head onto the object.

Pass one


Pass one involves rendering the scene from the light's point of view. Since this example uses a directional source of light (e.g., the Sun), it makes more sense to have orthographic projection, instead of perspective projection for the shadow map (inferring a point source of light).

Since only the needed information is used, the color buffer (and others) may be disabled, along with any color-altering schemes (e.g., lighting, shaders, texturing). It is important that only the shadow-casting objects are rendered, opposed to the objects that are shadowed. When shadow mapping is done in realtime, speed is important and therefore the less that is rendered, the better. A depth-offset is usually applied and enabled for the rendering of the shadow casters, since if this is not used, ugly stitching artifacts will result.

When the rendering of the shadow casters are complete, a texture map (image) of the depth buffer is made. This is the shadow map that will be used for the remainder of the process.

Pass two


The second pass involves drawing the scene from the eye's view. The shadow map is first projected over the whole scene, or at least, the shadow receivers, from the light's point of view. This is a mathematically intense part of the process, since multiple matrices are involved to generate the proper texture coordinates.

A test is applied to every pixel, to determine how far from the light the depth map says it is, and how far it really is. Usually, if its greater, the pixel fails the test, and is considered "shadowed".

Pass three


Pass three draws in the shadowed parts of the scene, since very rarely will shadows ever be totally black. This step can be done before or after pass two, but most often it is combined with pass two. A handful of ways exist, but it is most often combined by a shader that simply applies a different lighting scheme to the pixel. For this very reason alone, it is hard to find programs that use shadow mapping without shaders.

This example used the OpenGL extension GL_ARB_shadow_ambient to accomplish the process in two passes.

See also


External links


3D computer graphics

 

This article is licensed under the GNU Free Documentation License. It uses material from the "Shadow mapping".

Home Pageartsbusinesscomputersgameshealthhospitalshomekids & teensnewsphysiciansrecreationreferenceregionalscienceshoppingsocietysportsworld