Chapter 9

Stenciling

The stencil buffer is an off-screen buffer we can use to achieve special effects. The stencil buffer has the same resolution as the back buffer and depth buffer, such that the ijth pixel in the stencil buffer corresponds with the ijth pixel in the back buffer and depth buffer. Recall from the note in §4.1.5 that when a stencil buffer is specified, the stencil buffer always shares the depth buffer. As the name suggests, the stencil buffer works as a stencil and allows us to block the rendering of certain pixel fragments to the back buffer.

For instance, when implementing a mirror we need to reflect an object across the plane of the mirror; however, we only want to draw the reflection into the mirror. We can use the stencil ...

Get Introduction to 3D Game Programming with DirectX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.