431
Static Lighting
The fastest lighting calculation is the one you don’t do at all. Lighting is there-
fore performed off -line whenever possible. We can precalculate Phong refl ec-
tion at the vertices of a mesh and store the results as diff use vertex color at-
tributes. We can also precalculate lighting on a per pixel basis and store the
results in a kind of texture map known as a light map. At runtime, the light
map texture is projected onto the objects in the scene in order to determine the
light’s eff ects on them.
You might wonder why we don’t just bake lighting information directly
into the diff use textures in the scene. There are a few reasons for this. For one
thing, diff use texture maps are oft en tiled and/or repeated throughout a scene,
so baking lighting into them wouldn’t be practical. Instead, a single light map
is usually generated per light source and applied to any objects that fall within
that light’s area of infl uence. This approach permits dynamic objects to move
past a light source and be properly illuminated by it. It also means that our
light maps can be of a diff erent (oft en lower) resolution than our diff use tex-
ture maps. Finally, a “pure” light map usually compresses bett er than one that
includes diff use color information.
Ambient Lights
An ambient light corresponds to the ambient term in the Phong lighting model.
This term is independent of the viewing angle and has no specifi c direction.
An ambient light is therefore represented by a single color, corresponding to
the A color term in the Phong equation (which is scaled by the surface’s ambi-
ent refl ectivity kA at runtime). The intensity and color of ambient light may
vary from region to region within the game world.
Directional Lights
A directional light models a light source that is eff ectively an infi nite distance
away from the surface being illuminated—like the sun. The rays emanating
from a directional light are parallel, and the light itself does not have any
particular location in the game world. A directional light is therefore modeled
as a light color C and a direction vector L. A directional light is depicted in
Figure 10.26.
Point (Omni-Directional) Lights
A point light (omni-directional light) has a distinct position in the game world
and radiates uniformly in all directions. The intensity of the light is usually
considered to fall off with the square of the distance from the light source,
and beyond a predefi ned maximum radius its eff ects are simply clamped to
zero. A point light is modeled as a light position P, a source color/intensity C,
Figure 10.26. Model
of a directional light
source.
Figure 10.27. Mod-
el of a point light
source.
10.1. Foundations of Depth-Buffered Triangle Rasterization