Game Development Reference
In-Depth Information
of anisotropic materials are brushed metal, hair, and those little Christmas
ornaments made of shiny fibers.
10.6.7 Flat and Gouraud Shading
On modern shader-based hardware, lighting calculations are usually done
on a per-pixel basis. By this we mean that for each pixel, we determine a
surface normal (whether by interpolating the vertex normal across the face
or by fetching it from a bump map), and then we perform the full lighting
equation using this surface normal. This is per-pixel lighting, and the tech-
nique of interpolating vertex normals across the face is sometimes called
Phong shading, not to be confused with the Phong calculation for specu-
lar reflection. The alternative to Phong shading is to perform the lighting
equation less frequently (per face, or per vertex). These two techniques are
known as flat shading and Gouraud shading, respectively. Flat shading is
almost never used in practice except in software rendering. This is because
most modern methods of sending geometry e ciently to the hardware do
not provide any face-level data whatsoever. Gouraud shading, in contrast,
still has some limited use on some platforms. Some important general prin-
ciples can be gleaned from studying these methods, so let's examine their
results.
When using flat shading, we com-
pute a single lighting value for the
entire triangle. Usually the “posi-
tion” used in lighting computations
is the centroid of the triangle, and
the surface normal is the normal of
the triangle. As you can see in Fig-
ure 10.27, when an object is lit us-
ing flat shading, the faceted nature of
the object becomes painfully appar-
ent, and any illusion of smoothness
is lost.
Gouraud shading, also known as vertex shading, vertex lighting, or in-
terpolated shading, is a trick whereby values for lighting, fog, and so forth
are computed at the vertex level. These values are then linearly interpo-
lated across the face of the polygon. Figure 10.28 shows the same teapot
rendered with Gouraud shading.
As you can see, Gouraud shading does a relatively good job at restor-
ing the smooth nature of the object. When the values being approximated
are basically linear across the triangle, then, of course, the linear inter-
polation used by Gouraud shading works well. Gouraud shading breaks
down when the values are not linear, as in the case of specular highlights.
Figure 10.27
A flat shaded teapot
Search WWH ::




Custom Search