ShadowVol Sample

Description

The ShadowVol sample demonstrates how to create and use stencil buffers to implement shadow volumes. With shadow volumes, an arbitrarily shaped object can cast a shadow onto another arbitrarily shaped object.

Path

Source: (SDK root)\Samples\Multimedia\D3dim\Src\ShadowVol

Executable: (SDK root)\Samples\Multimedia\D3dim\Bin

User's Guide

This sample will run only on devices that support stencil buffers.

Press F1 to see available commands.

Programming Notes

Shadow volumes are a fairly advanced technique. To start, take an object that you'd like to have cast a shadow. From that object, build a set of polygonal faces that encompass the volume of its shadow. Next, use the stencil buffer to render the front facing planes of the shadow volume. Then, set up the stencil buffer to render the back-facing planes, this time subtracting values from the stencil buffer. Afterwards, the stencil buffer contains a mask of the cast shadow. Just draw a large gray or black rectangle using the stencil buffer as a mask, and the frame buffer will get updated with the shadow.