Game Development Reference
In-Depth Information
1
0
0
0
1
0
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
1
0
0
R
R
R
yz
xz
xy
0
0
1
0
0
0
1
0
0
0
1
0
0
0
0
1
0
0
0
1
0
0
0
1
To reflect a point across the yz plane, we simply take the opposite of
the z-component. Similarly, to reflect a point across the xz plane, we
take the opposite of the y-component. Finally, to reflect a point across
the xy plane, we take the opposite of the z-component. These reflec-
tions are readily seen by observing the symmetry on each of the
standard coordinate planes.
8.2.2 Mirror Implementation Overview
When implementing a mirror, an object is only reflected if it is in front
of a mirror. However, we don't want to test spatially if an object is in
front of a mirror, as it could get complicated. Therefore, to simplify
things, we always reflect the object and render it no matter where it is.
But this introduces problems seen in Figure 8.1 at the beginning of this
chapter. Namely, the object's (a teapot in this case) reflection is ren-
dered into surfaces that are not mirrors (like the walls for example). We
can solve this problem using the stencil buffer because the stencil
buffer allows us to block rendering to certain areas on the back buffer.
Thus, we can use the stencil buffer to block the rendering of the
reflected teapot if it is not being rendered into the mirror. The following
outline briefly explains the steps of how this can be accomplished:
1.
Render the entire scene as normal—the floor, walls, mirror, and
teapot—but not the teapot's reflection. Note that this step does not
modify the stencil buffer.
2.
Clear the stencil buffer to 0. Figure 8.3 shows the back buffer and
stencil buffer up to this point.
Figure 8.3: The scene
rendered to the back
buffer and the stencil
buffer cleared to zero.
The light gray on the
stencil buffer denotes
pixels cleared to zero.
 
Search WWH ::




Custom Search