07.01.2013 Views

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Shadow volume 185<br />

as each object can cast its own shadow volume of any potential size onscreen. See optimization below for a<br />

discussion of techniques used to combat the fill time problem.<br />

Depth pass<br />

Heidmann proposed that if the front surfaces and back surfaces of the shadows were rendered in separate passes, the<br />

number of front faces and back faces in front of an object can be counted using the stencil buffer. If an object's<br />

surface is in shadow, there will be more front facing shadow surfaces between it and the eye than back facing<br />

shadow surfaces. If their numbers are equal, however, the surface of the object is not in shadow. The generation of<br />

the stencil mask works as follows:<br />

1. Disable writes to the depth and color buffers.<br />

2. Use back-face culling.<br />

3. Set the stencil operation to increment on depth pass (only count shadows in front of the object).<br />

4. Render the shadow volumes (because of culling, only their front faces are rendered).<br />

5. Use front-face culling.<br />

6. Set the stencil operation to decrement on depth pass.<br />

7. Render the shadow volumes (only their back faces are rendered).<br />

After this is accomplished, all lit surfaces will correspond to a 0 in the stencil buffer, where the numbers of front and<br />

back surfaces of all shadow volumes between the eye and that surface are equal.<br />

This approach has problems when the eye itself is inside a shadow volume (for example, when the light source<br />

moves behind an object). From this point of view, the eye sees the back face of this shadow volume before anything<br />

else, and this adds a −1 bias to the entire stencil buffer, effectively inverting the shadows. This can be remedied by<br />

adding a "cap" surface to the front of the shadow volume facing the eye, such as at the front clipping plane. There is<br />

another situation where the eye may be in the shadow of a volume cast by an object behind the camera, which also<br />

has to be capped somehow to prevent a similar problem. In most common implementations, because properly<br />

capping for depth-pass can be difficult to accomplish, the depth-fail method (see below) may be licensed for these<br />

special situations. Alternatively one can give the stencil buffer a +1 bias for every shadow volume the camera is<br />

inside, though doing the detection can be slow.<br />

There is another potential problem if the stencil buffer does not have enough bits to accommodate the number of<br />

shadows visible between the eye and the object surface, because it uses saturation arithmetic. (If they used arithmetic<br />

overflow instead, the problem would be insignificant.)<br />

Depth pass testing is also known as z-pass testing, as the depth buffer is often referred to as the z-buffer.<br />

Depth fail<br />

Around the year 2000, several people discovered that Heidmann's method can be made to work for all camera<br />

positions by reversing the depth. Instead of counting the shadow surfaces in front of the object's surface, the surfaces<br />

behind it can be counted just as easily, with the same end result. This solves the problem of the eye being in shadow,<br />

since shadow volumes between the eye and the object are not counted, but introduces the condition that the rear end<br />

of the shadow volume must be capped, or shadows will end up missing where the volume points backward to<br />

infinity.<br />

1. Disable writes to the depth and color buffers.<br />

2. Use front-face culling.<br />

3. Set the stencil operation to increment on depth fail (only count shadows behind the object).<br />

4. Render the shadow volumes.<br />

5. Use back-face culling.<br />

6. Set the stencil operation to decrement on depth fail.<br />

7. Render the shadow volumes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!