Game Development Reference
In-Depth Information
Chapter 8
Stenciling
This chapter brings us to the study of the stencil buffer and is the con-
clusion of Part II of this text. The stencil buffer is an off-screen buffer
that we can use to achieve special effects. The stencil buffer has the
same resolution as the back buffer and depth buffer so that the ij th pixel
in the stencil buffer corresponds with the ij th pixel in the back buffer
and depth buffer. As the name suggests, the stencil buffer works as a
stencil and allows us to block rendering to certain parts of the back
buffer.
For instance, when implementing a mirror, we simply need to
reflect a particular object across the plane of the mirror; however, we
only want to draw the reflection into a mirror. We can use the stencil
buffer to block the rendering of the reflection unless it is in a mirror.
Figure 8.1 should make this clear.
Figure 8.1: Here we have a tea-
pot being reflected without using
the stencil buffer (a). We see that
the reflected teapot is always ren-
dered no matter if it is in front of
the mirror or a wall. Using the
stencil buffer, we can block the
reflected teapot from being ren-
dered unless it is being drawn in
the mirror (b).
The stencil buffer is a small part of Direct3D and is controlled through
a simple interface. Like blending, the simple interface offers a flexible
and powerful set of capabilities. Learning to use the stencil buffer
131
Search WWH ::




Custom Search