i
i
i
i
i
i
i
i
332 9. Global Illumination
Figure 9.4. The upper image was rendered with hard shadows, while the lower was
rendered with soft shadows. The soft shadow has a smaller umbra region (i.e., area fully
in shadow), and the softness increases with the distance from the receiving point (the
ground) [916]. (Images from “Hellgate: London courtesy of Flagship Studios, Inc.)
i
i
i
i
i
i
i
i
9.1. Shadows 333
shadow. Hard-edged shadows usually look less realistic and can sometimes
be misinterpreted as actual geometric features, such as a crease in a surface.
More important than having a penumbra is having any shadow at all.
Without some shadow as a visual cue, scenes are often unconvincing and
more difficult to perceive. As Wanger shows [1324], it is usually better to
have an inaccurate shadow than none at all, as the eye is fairly forgiving
about the shape of the shadow. For example, a blurred black circle applied
as a texture on the floor can anchor a person to the ground. A simple
black rectangular shape fading off around the edges, perhaps a total of 10
triangles, is often all that is needed for a car’s soft shadow.
In the following sections, we will go beyond these simple modeled shad-
ows and present methods that compute shadows automatically in real time
from the occluders in a scene. The first section handles the special case of
shadows cast on planar surfaces, and the second section covers more gen-
eral shadow algorithms, i.e., casting shadows onto arbitrary surfaces. Both
hard and soft shadows will be covered. To conclude, some optimization
techniques are presented that apply to various shadow algorithms.
9.1.1 Planar Shadows
A simple case of shadowing occurs when objects cast shadows on planar
surfaces. Two kinds of algorithms for planar shadows are presented in this
section.
Projection Shadows
In this scheme, the three-dimensional object is rendered a second time in
order to create a shadow. A matrix can be derived that projects the vertices
of an object onto a plane [101, 1263]. Consider the situation in Figure 9.5,
where the light source is located at l, the vertex to be projected is at v,
and the projected vertex is at p. We will derive the projection matrix for
the special case where the shadowed plane is y = 0, then this result will be
generalized to work with any plane.
We start by deriving the projection for the x-coordinate. From the
similar triangles in the left part of Figure 9.5, the following equation is
obtained:
p
x
l
x
v
x
l
x
=
l
y
l
y
v
y
⇐⇒
p
x
=
l
y
v
x
l
x
v
y
l
y
v
y
.
(9.4)
i
i
i
i
i
i
i
i
334 9. Global Illumination
Figure 9.5. Left: A light source, located at l, casts a shadow onto the plane y =0.
The vertex v is projected onto the plane. The projected point is called p. The similar
triangles are used for the derivation of the projection matrix. Right: The notation of the
left part of this figure is used here. The shadow is being cast onto a plane, π : n·x+d =0.
The z-coordinate is obtained in the same way: p
z
=(l
y
v
z
l
z
v
y
)/(l
y
v
y
),
while the y-coordinate is zero. Now these equations can be converted into
the projection matrix M:
M =
l
y
l
x
00
0000
0 l
z
l
y
0
0 10l
y
. (9.5)
It is straightforward to verify that Mv = p, which means that M is
indeed the projection matrix.
In the general case, the plane onto which the shadows should be cast is
not the plane y = 0, but instead π : n · x + d =0. Thiscaseisdepictedin
the right part of Figure 9.5. The goal is again to find a matrix that projects
v down to p. To this end, the ray emanating at l, which goes through v,
is intersected by the plane π. This yields the projected point p:
p = l
d + n · l
n · (v l)
(v l). (9.6)
This equation can also be converted into a projection matrix, shown in
Equation 9.7, which satisfies Mv = p:
M =
n · l + d l
x
n
x
l
x
n
y
l
x
n
z
l
x
d
l
y
n
x
n · l + d l
y
n
y
l
y
n
z
l
y
d
l
z
n
x
l
z
n
y
n · l + d l
z
n
z
l
z
d
n
x
n
y
n
z
n · l
. (9.7)
i
i
i
i
i
i
i
i
9.1. Shadows 335
As expected, this matrix turns into the matrix in Equation 9.5 if the
plane is y = 0 (that is, n =(0 1 0)
T
and d =0).
To render the shadow, simply apply this matrix to the objects that
should cast shadows on the plane π, and render this projected object with
a dark color and no illumination. In practice, you have to take measures to
avoid allowing the projected polygons to be rendered beneath the surface
receiving them. One method is to add some bias to the plane we project
upon, so that the shadow polygons are always rendered in front of the
surface. Getting this bias just right is often tricky: too much, and the
shadows start to cover the objects and so break the illusion; too little,
and the ground plane pokes through the shadows, due to precision error.
Biasing solutions are discussed in Section 11.4.
A safer method is to draw the ground plane first, then draw the pro-
jected polygons with the Z-buffer off, then render the rest of the geometry
as usual. The projected polygons are then always drawn on top of the
ground plane, as no depth comparisons are made.
A flaw with projection shadows is that the projected shadows can
fall outside of our plane. To solve this problem, we can use a stencil
buffer. First, draw the receiver to the screen and to the stencil
buffer. Then, with the Z-buffer off, draw the projected polygons only
where the receiver was drawn, then render the rest of the scene
normally.
Projecting the polygons this way works if the shadows are opaque. For
semitransparent shadows, where the underlying surface color or texture can
be seen, more care is needed. A convex object’s shadow is guaranteed to
have exactly two (or, by culling backfaces, exactly one) projected polygons
covering each shadowed pixel on the plane. Objects with concavities do
not have this property, so simply rendering each projected polygon as semi-
transparent will give poor results. The stencil buffer can be used to ensure
that each pixel is covered at most once. Do this by incrementing the sten-
cil buffer’s count by each polygon drawn, allowing only the first projected
polygon covering each pixel to be rendered. Alternately, the ground plane
could be drawn, the Z-buffer cleared, and then each successive shadow
polygon is drawn increasingly offset (e.g., using glPolygonOffset)sothat
it is further away than the previous polygon. In this way, each shadowed
pixel is drawn only once [663]. This works, but the ground plane may need
to be redrawn into the Z-buffer (only) to reestablish the correct z-depths,
if needed.
One way to avoid the problems of rendering multiple projected shadow
polygons atop a ground plane is to instead render these polygons to a
texture. This texture is then applied to the ground plane. Essentially, this
texture is a form of a light map. As will be seen, this idea of rendering the
shadow projection to a texture also allows soft shadowing and shadows on
i
i
i
i
i
i
i
i
336 9. Global Illumination
Figure 9.6. At the left, a correct shadow is shown, while in the figure on the right, an
antishadow appears, since the light source is below the topmost vertex of the object.
curved surfaces. The major drawback of this technique is that the texture
can become magnified, with a single texel covering multiple pixels.
If the shadow situation does not change from frame to frame, i.e., the
light and shadow casters do not move relative to each other, this texture can
be reused. Most shadow techniques can benefit from reusing intermediate
computed results from frame to frame.
All shadow casters must be between the light and the ground plane
receiver. If the light source is below the topmost point on the object, an
antishadow [101] is generated, since each vertex is projected through the
point of the light source. Correct shadows and antishadows are shown in
Figure 9.6. A similar rendering error as that found with planar reflections
can occur for this kind of shadow generation. For reflections, errors occur
when objects located on the opposite side of the reflector plane are not dealt
with properly. In the case of shadow generation, errors occur when we use
a shadow-casting object that is on the far side of the receiving plane. This
is because an object beyond the shadow receiver does not cast a shadow
on it.
It is certainly possible to explicitly cull and trim shadow polygons to
avoid such artifacts. A simpler method, presented next, is to use the ex-
isting GPU pipeline to perform projection with clipping.
Soft Shadows
Projective shadows can also be made soft, by using a variety of techniques.
Here, we describe an algorithm from Heckbert and Herf [524, 544] that
produces soft shadows. The algorithm’s goal is to generate a texture on a
..................Content has been hidden....................

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