Game Development Reference
In-Depth Information
8.1.4 Stencil Write Mask
In addition to the mentioned stencil render states, we can set a write
mask that will mask off bits of any value that we write to the stencil
buffer. We can set the write mask with the D3DRS_STENCILWRITE-
MASK render state. The default value is 0xffffffff. The following example
masks the top 16 bits:
Device->SetRenderState(D3DRS_STENCILWRITEMASK, 0x0000ffff);
8.2 Sample Application: Mirrors
Many surfaces in nature serve as mirrors and allow us to see object
reflections in those mirrors. This section describes how we can simu-
late mirrors for our 3D applications. Note that for simplicity we reduce
the task of implementing mirrors to planar surfaces only. For instance,
a shiny car can display a reflection; however, a car's body is smooth,
round, and not planar. Instead, we render reflections such as those that
are displayed in a shiny marble floor or those that are displayed in a
mirror hanging on a wall—in other words, mirrors that lie on a plane.
Implementing mirrors programmatically requires us to solve two
problems. First, we must learn how to reflect an object about an arbi-
trary plane so that we can draw the reflection correctly. Second, we
must only display the reflection in a mirror. That is, we must somehow
“mark” a surface as a mirror, and then as we are rendering we only
draw the reflected object if it is in a mirror. Refer to Figure 8.1, which
first introduced this concept.
The first problem is easily solved with some vector geometry. We
can solve the second problem with the stencil buffer. The next two sub-
sections explain the solutions to these problems individually. The third
subsection ties them together and reviews the relevant code for the
first sample application for this chapter—Mirrors.
8.2.1 The Mathematics of Reflection
We now show how to compute the reflection point v =(v x ,v y ,v z )ofa
point v =(v x ,v y ,v z ) about an arbitrary plane
np
+d
0. Refer to Fig-
ure 8.2 throughout this discussion.
Search WWH ::




Custom Search