416 10. The Rendering Engine
10.1.2.4. Attribute Interpolation
The att ributes at a triangle’s vertices are just a coarse, discretized approxima-
tion to the visual properties of the surface as a whole. When rendering a tri-
angle, what really matt ers are the visual properties at the interior points of the
triangle as “seen” through each pixel on-screen. In other words, we need to
know the values of the att ributes on a per-pixel basis, not a per-vertex basis.
One simple way to determine the per-pixel values of a mesh’s surface at-
tributes is to linearly interpolate the per-vertex att ribute data. When applied to
vertex colors, att ribute interpolation is known as Gouraud shading. An example
of Gouraud shading applied to a triangle is shown in Figure 10.11, and its ef-
fects on a simple triangle mesh are illustrated in Figure 10.12. Interpolation is
routinely applied to other kinds of vertex att ribute information as well, such
as vertex normals, texture coordinates, and depth.
Figure 10.11. A Gouraud-shaded triangle with different shades of gray at the vertices.
Figure 10.12. Gouraud shading can make faceted objects appear to be smooth.
Vertex Normals and Smoothing
As we’ll see in Section 10.1.3, lighting is the process of calculating the color of
an object at various points on its surface, based on the visual properties of the
surface and the properties of the light impinging upon it. The simplest way to
light a mesh is to calculate the color of the surface on a per-vertex basis. In other
words, we use the properties of the surface and the incoming light to calculate
the diff use color of each vertex (di). These vertex colors are then interpolated
across the triangles of the mesh via Gouraud shading.