Game Development Reference
In-Depth Information
Information about the surface of a model, such as the positions of points on the
surface and the normal vectors at those points, are stored only for each vertex of
a triangle mesh. When a single triangle is rendered, information known at each
vertex is interpolated across the face of the triangle, as discussed in Section 5.4.2.
Conventional lighting pipelines calculate diffuse and specular illumination only
at the vertices of a mesh. More modern graphics hardware enables the calculation
of the entire illumination formula at every individual pixel drawn to the display.
The manner in which lighting is determined for the surface of a triangle, com-
bined with any number of texture maps, is called shading .
7.7.1 Calculating Normal Vectors
To apply the lighting formula to a triangle mesh, we need to have a representa-
tion of the surface normal at each vertex. We can calculate the normal vector for
a single triangle by using the cross product. The unit-length normal vector N of a
triangle whose vertices lie at the points P , P , and P is given by
(
)
(
)
PP
−×−
P P
1
0
2
0
N
=
P P .
(7.23)
(
)
(
)
PP
−×−
1
0
2
0
This assumes that the vertices are oriented in a counterclockwise fashion when
the normal points toward the viewer, as shown in Figure 7.13.
The normal vector at a single vertex is typically calculated by averaging the
normal vectors of all triangles that share that vertex. Using the formula
P
2
P
P
Figure 7.13. The vertices of a triangle should be oriented in a counterclockwise fashion
when the normal vector points toward the viewer.
0
1