Game Development Reference
In-Depth Information
Note: Although specifying the direction the light rays are emitted
from a light source is perhaps more intuitive, specifying the direction to
the light is better suited for the diffuse lighting calculation.
Then for each quad in the terrain, we calculate the angle between the
light vector L and the quad's surface normal N .
In Figure 13.7 we see that as angles get larger, the quad faces more
and more away from the light source, thus receiving less light. On the
other hand, as angles get smaller, the quad faces more and more toward
the light source, thus receiving more light. Also, notice that once the
angle between the light vector and the normal is greater than 90
degrees, the surface receives no light.
Figure 13.7: Angles between the
light vector L and the surface nor-
mal N determine how much light
the surface is receiving. In (a) we
see an angle less than 90
degrees. In (b) we see an angle
greater than 90 degrees. Observe
that the surface receives zero light
because the light rays (emitting in
the opposite direction of L ) strike
the back of the surface.
Using the angular relationships between the light vector and the sur-
face normal, we can construct a shading scalar in the interval [0, 1] that
determines how much light a surface receives. Using this shading sca-
lar, a large angle is represented by a scalar close to zero. When a color
is multiplied by this shading scalar that is close to zero, it is darkened,
which is the desired result. On the opposite end, multiplying by a shad-
ing scalar that represents a small angle is closer to one, and thus keeps
the color close to its original brightness.
13.4.2 Computing the Shade of a Quad
The direction to the light source is given as a normalized vector that
we call L in this discussion. In order to calculate the angle between L
and the quad's normal vector N , we first need to find N . This is a trivial
application of the cross product. But first we must find two non-zero
and non-parallel vectors that are coplanar with the quad. There are two
such vectors, u and v , in Figure 13.8:
Search WWH ::




Custom Search