i
i
i
i
i
i
i
i
9.3. Reflections 387
on the reflected object. The conclusion that can be drawn from this prin-
ciple is that a reflection can be rendered by creating a copy of the object,
transforming it into the reflected position, and rendering it from there. To
achieve correct lighting, light sources have to be reflected in the plane as
well, with respect to both position and direction [892, 957].
If for a moment we assume that the reflecting plane has a normal,
n =(0, 1, 0), and that it goes through the origin, then the matrix that
reflects in this plane is simply this mirror scaling matrix: S(1, 1, 1). For
the general case, we derive the reflection matrix M,giventhenormalof
the reflector n and some point p on the reflector plane. Since we know
how to reflect in the plane y = 0, the idea is to transform the plane into
y = 0, then perform the simple scaling, and finally transform back. The
concatenation of these matrices yields M.
First, we have to translate the plane so that it passes through the
origin, which is done with a translation matrix: T(p). Then the normal
of the reflector plane, n, is rotated so that it becomes parallel to the y-
axis: (0, 1, 0). This can be done with a rotation from n to (0, 1, 0) using
R(n, (0, 1, 0)) (see Section 4.3.2). The concatenation of these operations is
called F:
F = R(n, (0, 1, 0))T(p). (9.24)
After that, the reflector plane has become aligned with the plane y =0,
andthenscaling,S(1, 1, 1), is performed; finally, we transform back with
F
1
.Thus,M is constructed as follows:
M = F
1
S(1, 1, 1)
T
F. (9.25)
Note that this matrix has to be recomputed if the position or orientation
of the reflector surface changes.
The scene is rendered by first drawing the objects to be reflected (trans-
formed by M), followed by drawing the rest of the scene with the reflector
included. An example of the results of this process appear in Figure 9.42.
An equivalent method is to instead reflect the viewer’s position and orienta-
tion through the mirror to the opposite side of the reflector. The advantage
of moving the viewer is that none of the geometry has to be manipulated
before being sent down to form the reflection [492, 849, 957]. In either case,
care must be taken with properly setting backface culling for the reflection
pass, as the use of a reflection matrix will normally flip the sense needed.
The reflector has to be partially transparent, so that the reflection is vis-
ible. As such, the transparency acts like a kind of reflectivity factor; the
reflector appears more reflective with increasing transparency.
However, sometimes the reflections can be rendered incorrectly, as in
the left part of Figure 9.43. This happens because the reflected geometry
can appear at places where there is no reflector geometry.Inotherwords,
i
i
i
i
i
i
i
i
388 9. Global Illumination
Figure 9.42. The water reflection is performed by mirroring polygons through the water’s
surface and blending them with the textured water polygon. The chandelier and some
other elements are replaced with sets of textured polygons. (Image courtesy of Agata
and Andrzej Wojaczek [ag[email protected]], Advanced Graphics Applications Inc.)
Figure 9.43. The left image shows an incorrectly rendered reflection against three mir-
rored squares. The right image was rendered with the use of the stencil buffer to mask
out the part where there is visible reflector geometry, which yields a correct reflection.
i
i
i
i
i
i
i
i
9.3. Reflections 389
the viewer will figure out the trick, seeing that the reflected objects are
actually real.
To solve the problem, the reflector is first rendered into the stencil
buffer, with the stencil parameters set so that we can write to the screen
only where the reflector is present. Then the reflected geometry is rendered
with stenciling turned on. In this way, the reflected geometry is rendered
only where the stencil buffer is set, i.e., where the reflector exists.
Objects that are on the far side of (i.e., behind) the reflector plane
should not be reflected. This problem can be solved by using the reflec-
tor’s plane equation. The simplest method is to set a user-defined clipping
plane. Place the clipping plane so that it coincides with the plane of the
reflector [492]. Using such a clipping plane when rendering the reflected
objects will clip away all reflected geometry that is on the same side as the
viewpoint, i.e., all objects that were originally behind the mirror.
Portal culling methods (Section 14.4) can be used to restrict the amount
of reflected geometry that needs to be fully processed. A mirror on a wall
can be treated as a different kind of portal, “through the looking-glass.”
The user-defined clipping plane itself can also help to check if bounding
volumes in the scene are entirely culled out, so that parts of the scene do
not have to be sent down the pipeline at all.
A number of significant global illumination effects and lighting models
are presented by Diefenbach and Badler [253]. We will discuss two here,
glossy reflection and frosted glass. A simple way to enhance the illusion
that the reflector is truly a mirror is to fog the reflected objects seen in it.
This effect is created by having each object fade to black as the distance
from the reflector increases. One way to do this is to render the reflected
objects with a shader program that fades them to black by their distance
from some plane. Another approach is to render the reflected objects to
atextureandaZ-buffer. When the reflector is rendered, its z-depth is
compared to the stored depth. The difference in depths is used to diminish
the contribution of the reflected objects. In this way, no modification of
the other objects’ shader is necessary.
The accumulation and stencil buffers can be used together to produce
the effects of fuzzy reflection and frosted glass. The stencil buffer creates
the window into the effect, and the accumulation buffer captures the effect
from jittering the position of the object. Fogging to black is used for the
reflection, fogging to white for the refraction. Examples of these techniques
are shown in Figure 9.44.
While conceptually appealing, using an accumulation buffer is expen-
sive, as geometry has to be processed multiple times. A considerably faster
way to create a similar effect is to use filtering techniques. The idea is
to render the objects beyond the glass to an image that is then used as a
texture. When the frosted glass is rendered, its shader program samples
i
i
i
i
i
i
i
i
390 9. Global Illumination
Figure 9.44. Fuzzy reflections and refractions, done by using the accumulation and
stencil buffers along with fog. (Images courtesy of Paul Diefenbach, window design by
Elsa Schmid.)
Figure 9.45. The upper left and right show the reflection and refraction images generated
from the scene. These are then used by the water’s surface as environment map textures,
in the lower left. The lower right shows a similar shader performing refraction [848].
(Images courtesy of Valve Corp.)
i
i
i
i
i
i
i
i
9.3. Reflections 391
this texture in a number of locations, thereby giving a blurred effect. See
Section 10.9 for more about such methods.
This idea of having an object (such as the reflector polygon) accessing a
previously stored depth or otherwise compute the distance from some sur-
face can be used for many other effects. For example, to simulate translu-
cency, the depth between the front and back faces can be mapped to a
one-dimensional texture. Blending and smoothing techniques are needed
to avoid artifacts from any tiny folds in the model [947].
One way to provide reflection and refraction effects in a bump-mapped
surface is given by McTaggart [848]. The scene is reflected using the tech-
nique described earlier in Section 9.3.1. This reflection image is stored for
use as a texture. Similarly, the part of the world seen through the surface
is stored in a texture. The world in front of the reflector is then ren-
dered normally. The reflector is rendered with a normal map, changing the
reflection and refraction directions. These directions then access the cor-
responding image textures to create the appearance of distorted reflection.
See Figure 9.45.
9.3.2 Reflections from Curved Reflectors
Ray tracing is the traditional solution for producing general reflections. See
Section 9.8.2 for details. A reflection ray starts from the viewed location
and picks up and adds in the color in the reflection direction. Ofek and
Rappoport [957] present a technique for sharp, true reflections from convex
and concave reflectors that can be considerably faster. Their observation is
that in a convex reflector (e.g., a sphere), the reflected object is distorted
by the surface, but is otherwise unchanged. That is, each reflected vertex is
reflected by only one point on the reflector (unlike what can happen with a
concave reflector). The curved reflector can be treated like a window into a
mirror world, in a similar manner to the planar reflector. The full descrip-
tion of this method is fairly involved and has limitations; the interested
reader should see the original paper [957].
Recursive reflections of curved objects in a scene can be performed using
environment mapping [253, 849, 933]. For example, imagine a red and a
blue mirrored ball some distance from each other. Generate an EM for the
red sphere, then generate an EM for the blue while using the red sphere’s
EM during its creation. The blue sphere now includes a reflection of the red
sphere, which in turn reflects the world. This recursion should in theory go
on for several steps (until we cannot make out any differences), but this is
expensive. A cheaper version of this computes only one environment map
per frame using the environment maps from the previous frame [360]. This
gives approximate recursive reflections. Figure 9.46 shows some examples
using this technique.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset