next up previous contents
Next: 11.1.3 Curved Reflectors Up: 11.1.2 Planar Reflectors Previous: Planar Reflections using 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:

tex2html_nowrap 18.
Draw the non-reflected objects in the scene.
tex2html_nowrap 19.
Bind the texture containing the reflected image.
tex2html_nowrap 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 12396
\vrule width 0pt height 0....
...ure \thefigure . Masking Reflections Using Projective Texture}\\

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.3 Curved Reflectors Up: 11.1.2 Planar Reflectors Previous: Planar Reflections using
David Blythe