next up previous contents
Next: 11.1.2.4 Simulating Reflection and Up: 11.1.2 Planar Reflectors Previous: 11.1.2.2 Planar Reflections using   Contents

11.1.2.3 Planar Reflections using Texture Mapping

Another technique uses texture mapping. The first pass is identical to the first pass of the previous technique: draw the reflected scene. After drawing the scene, copy the image into a texture. (For example, in OpenGL, use glCopyTexImage2D()). During the second pass, map this texture onto the reflective polygon. The sequence of steps for the second pass is as follows:

18.
Draw the non-reflected objects in the scene.
19.
Bind the texture containing the reflected image.
20.
Draw the reflective object with the appropriate texture coordinates.

The texture coordinates at the vertices of the reflective object must be in the same location as the vertices of the reflective object in the texture. These coordinates may be computed by figuring the projection of the corners of the object into the viewing plane used to compute the reflection map (the command gluProject() may prove helpful).

Another approach, using OpenGL's texture coordinate generation and GL_ TEXTURE matrix stack, is to load the texture matrix with the projection matrix and configure texture coordinate generation as GL_ EYE_LINEAR with the glTexGen() plane set to the XY plane. Texture coordinates are automatically generated that map the texture directly to pixels in the rendered image, as illustrated in Figure 58


% latex2html id marker 12426
\fbox{\begin{tabular}{c}
\vrule width 0pt height 0....
...ure \thefigure . Masking Reflections Using Projective Texture}\\
\end{tabular}}

The texture mapping technique may be more efficient on some systems than stencil buffering, but keep in mind that it uses up a texture stage, which may force the algorithm to use multiple passes to render the reflector if it also has a texture applied to it and the hardware supports only a single texture. On the other hand, you may be able to use a reflection texture during several frames, as described below.

The texture does not need to be the same size as the screen; it needs only to cover the screen-space projection of the reflector. If a smaller texture is used, however, the projected texture coordinates must be adjusted so the texture coordinates range from 0 to 1 within the smaller area.

Finally, it may be acceptable to render the image of the reflected scene at a lower resolution than the final scene and let texture filtering blur the texture when it is projected onto the reflector.


next up previous contents
Next: 11.1.2.4 Simulating Reflection and Up: 11.1.2 Planar Reflectors Previous: 11.1.2.2 Planar Reflections using   Contents
2001-01-10