Platform SDK: DirectX

ShadowVol Sample

[Visual Basic]

This topic pertains only to application development in C++. See Direct3D Immediate Mode Visual Basic Samples.

[C++]

Description

The ShadowVol sample shows how to create and use stencil buffers to implement shadow volumes. With shadow volumes, an object of any shape can cast a shadow onto another object of any shape.

Path

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

Executable: (SDK root)\Samples\Multimedia\D3dim\Shadowvol.exe

User's Guide

This sample runs only on devices that support stencil buffers.

Press F1 to see available commands, or choose from the menu.

Programming Notes

Shadow volumes are a fairly advanced technique.

To create shadow volumes

  1. Build a set of polygonal faces that encompass the volume of the shadow.
  2. Use the stencil buffer to render the front-facing planes of the shadow volume.
  3. Set up the stencil buffer to render the back-facing planes, this time subtracting values from the stencil buffer. The stencil buffer then contains a mask of the cast shadow.
  4. Draw a large gray or black rectangle, using the stencil buffer as a mask, and the frame buffer will be updated with the shadow.