Game Development Reference
In-Depth Information
where stencil shadows became practical, but several unsolved problems still ex-
isted that prevented the algorithm from working correctly under various condi-
tions. These problems have now been solved, and stencil shadows can be robust-
ly implemented to handle arbitrarily positioned point lights and infinite direction-
al lights having any desired spatial relationship with the camera.
The basic concept of the stencil shadow algorithm is to use the stencil buffer
as a masking mechanism that prevents pixels in shadow from being drawn during
the rendering pass for a particular light source. This is accomplished by rendering
an invisible shadow volume for each shadow-casting object in a scene using
stencil operations that leave nonzero values in the stencil buffer wherever light is
blocked. Once the stencil buffer has been filled with the appropriate mask, a
lighting pass only illuminates pixels where the value in the stencil buffer is zero.
As shown in Figure 10.6, an object's shadow volume encloses the region of
space for which light is blocked by the object. This volume is constructed by
finding the edges in the object's triangle mesh representing the boundary be-
tween lit triangles and unlit triangles and extruding those edges away from the
light source. Such a collection of edges is called the object's silhouette with re-
spect to the light source. The shadow volume is rendered into the stencil buffer
using operations that modify the stencil value at each pixel depending on whether
the depth test passes or fails. Of course, this requires that the depth buffer has
already been initialized to the correct values by a previous rendering pass. Thus,
the scene is first rendered using a shader that applies surface attributes that do not
depend on any light source, such as ambient illumination, emission, and envi-
ronment mapping.
Figure 10.6. An object's shadow volume encloses the region of space for which light
emitted by the light source L is blocked by the object.
Search Nedrilad ::

Custom Search