Game Development Reference
In-Depth Information
cylinder (black circle) that is being approximated by a hexagonal prism
(blue outline). Black normals at the vertices are the true surface normals,
whereas the interior normals are being approximated through interpolation.
(The actual normals used would be the result of stretching these out to unit
length.)
Figure 10.12
A cylinder
approximated with a
hexagonal prism.
Once we have a normal at a given point, we can perform the full lighting
equation per pixel. This is known as per-pixel shading. 11 An alternative
strategy to per-pixel shading, known as Gouraud 12 shading [26], is to per-
form lighting calculations only at the vertex level, and then interpolate the
results themselves, rather than the normal, across the face. This requires
less computation, and is still done on some systems, such as the Nintendo
Wii.
Figure 10.13 shows per-pixel lighting of cylinders with a different num-
ber of sides. Although the illusion breaks down on the ends of the cylinder,
where the silhouette edge gives away the low-poly nature of the geometry,
this method of approximating a smooth surface can indeed make even a very
low-resolution mesh look “smooth.” Cover up the ends of the cylinder, and
even the 5-sided cylinder is remarkably convincing.
Now that we understand how normals are interpolated in order to ap-
proximately reconstruct a curved surface, let's talk about how to obtain
vertex normals. This information may not be readily available, depending
on how the triangle mesh was generated. If the mesh is generated pro-
cedurally, for example, from a parametric curved surface, then the vertex
normals can be supplied at that time. Or you may simply be handed the
vertex normals from the modeling package as part of the mesh. However,
sometimes the surface normals are not provided, and we must approximate
them by interpreting the only information available to us: the vertex po-
sitions and the triangles. One trick that works is to average the normals
of the adjacent triangles, and then renormalize the result. This classic
technique is demonstrated in Listing 10.6.
11 This technique of interpolating the vertex normals is also sometimes confusingly
known as Phong shading, not to be confused with the Phong model for specular reflection.
12 Pronounced “guh-ROH.”
 
Search WWH ::




Custom Search