i
i
i
i
i
i
i
i
9.1. Shadows 343
The general algorithm has to be adjusted if the viewer is inside a shadow
volume, as this condition throws off the count. In this case, a value of 0
does not mean a point is in the light. For this condition, the stencil buffer
should be cleared to the number of shadow volumes the viewer starts inside
(instead of 0). Another more serious problem is that the near plane of
the viewer’s viewing frustum might intersect one or more shadow volume
planes. If uncorrected, this case invalidates the count for a portion of the
image. This problem cannot be cured by simple count adjustment. The
traditional method to solve this problem is to perform some form of capping
at the near plane [84, 653, 849]. Capping is where additional polygons are
drawn so as to make the object appear solid. However, such methods are
generally not robust and general.
Bilodeau and Songy [87] were the first to present (and patent) an al-
ternate approach to avoid this near plane clipping problem; Carmack also
independently discovered a similar technique [653] (see Hornus et al. [568]
for the differences). Nonintuitive as it sounds, the idea is to render the
shadow volumes that are obscured by visible surfaces. The first stencil
buffer pass becomes: Render the backfacing shadow volume polygons and
increment the stencil count when the polygon is equal to or farther than the
stored z-depth. In the next stencil pass, render the frontfacing shadow vol-
ume polygons and decrement the count when the polygon is, again, equal
to or farther than the stored z-depth. Because the shadow volumes are
drawn only when the Z-buffer test has failed, they are sometimes called
z-fail shadow volumes,versusz-pass. The other passes are done as be-
fore. In the original algorithm, a point is in shadow because the number
of frontfacing polygons crossed was larger than the number of backfacing
polygons; in this version, the object is in shadow if the number of back-
facing polygons not seen is larger than the number of frontfacing polygons
not seen, something of a logical equivalent. The difference is that now all
shadow volume polygons in front of surfaces, including those that could
encompass the viewer, are not rendered, so avoiding most viewer location
problems. See Figure 9.11.
For the z-pass algorithm, the original triangles generating the quadri-
laterals do not actually need to be rendered to the stencil buffer. These
polygons are always made invisible by the first pass, which will set z-depths
such that these polygons will match and so not be rendered. This is not the
case for the z-fail algorithm. To properly maintain the count, these origi-
nating polygons must be rendered. In addition, the shadow volumes must
be closed up at their far ends, and these far endcaps must be inside the far
plane. The z-fail algorithm has the inverse of the problem that the z-pass
has. In z-pass, it is possible for shadow volumes to penetrate the view
frustum’s near plane; in z-fail, shadow volumes can potentially penetrate
the far plane and cause serious shadowing errors. See Figure 9.12.