What follows is an extract from a very famous book on computer graphics (which I strongly recommend you buy if you haven't already) called, "Computer Graphics: Principles and Practice", by Foley, Van Dam, Feiner and Hughes (Addison Wesley press, 2nd Edition, 1990) which I first typed up in August 1995; it explains all the above shading methods in detail, though I have occasionally added extra text in curly brackets {} in order to make the prose clearer to a younger audience. The 'Color Plate' images referred to in the text can be viewed simply by going to your local library and consulting the book in question.
It should be clear that we can shade any surface by calculating the surface normal {a vector perpendicular to the surface} at each visible point and applying the desired illumination model at that point. Unfortunately, this brute-force shading model is {computationally} expensive. In this section, we describe more efficient shading models for surfaces defined by polygons and polygon meshes.
Mathematical definitions:
_ L - Light source vector (direction) striking the surface (abbreviated to 'L', but remember this is a vector). _ V - Viewpoint vector (eyepoint) looking at the surface (abbreviated to 'V', but remember this is a vector). _ N - Normal vector (perpendicular) to the surface (abbreviated to 'N', but remember this is a vector).
16.2.1 Constant Shading.
The simplest shading model for a polygon is 'constant shading', also known as 'faceted shading' or 'flat shading'. This approach applies an illumination model once to determine a single intensity value that is then used to shade an entire polygon, and holding the value across the polygon to reconstruct the polygon's shade. This approach is valid if several assumptions are true:
If either of the first two assumptions is wrong {actually, all three are wrong for just about every computer game you'll ever see}, then, if we are to use constant shading, we need some method to determine a single value for each L and V. For example, values may be calculated for the center of the polygon, or for the polygon's first vertex. Of course, constant shading does not produce the variations in shade across the polygon that should occur in this situation.
{see 'Note A' at the end of this document}
16.2.2 Interpolated Shading.
As an alternative to evaluating the illumination equation at each point on the polygon, Wylie, Romney, Evans, and Erdahl [WYLI67] pioneered the use of 'interpolated shading', in which the shading information is linearly interpolated across a triangle from values determined for its vertices. Gouraud [GOUR71] generalized this technique to arbitrary polygons. This is particularly easy for a scan-line algorithm that already interpolates the z value across a span from interpolated z values computed for the span's endpoints. For increased efficiency, a difference equation may be used, like that developed in Section 15.4 to determine the z value at each pixel. Although z interpolation is physically correct (assuming that the polygon is planar {flat}), note that interpolated shading is not, since it only approximates evaluating the illumination model at each point on the polygon.
{what they're saying here is that interpolated shading looks cool, but it isn't visually correct because it can only ever be an approximation of what one would see in real life}
Our final assumption, that the polygon accurately represents the surface being modelled, is most often the one that is incorrect, which has a much more substantial effect on the resulting image than does the failure of the other two assumptions. Many objects are curved, rather than polyhedral {made up of many flat surfaces}, yet representing them as a polygon mesh allows the use of efficient polygon visible-surface algorithms. We discuss next how to render a polygon mesh so that it looks as much as possible like a curved surface.
16.2.3 Polygon Mesh Shading.
Suppose that we wish to approximate a curved surface by a polygonal mesh. If each polygonal facet in the mesh is shaded individually, it is easily distinguished from neighbors whose orientation is different, producing a "faceted" appearance, as shown in Color Plate II.29. This is true if the polygons are rendered using constant shading, interpolated shading, or even per-pixel illumination calculations, because two adjacent polygons of different orientation have different intensities along their borders. The simple solution of using a finer mesh turns out to be surprisingly ineffective {see Note A}, because the perceived difference in shading between adjacent facets is accentuated by the Mach band effect (discovered by Mach in 1865 and described in detail in [RATL72]), which exaggerates the intensity change at any edge where there is a discontinuity in magnitude or slope of intensity. At the border between two facets, the dark facet looks darker and the light facet looks lighter. Figure 16.17 shows, for two separate cases, the actual and perceived changes in intensity along a surface.
Mach banding is caused by 'lateral inhibition' of the receptors in the eye. The more light a receptor receives, the more that receptor inhibits the response of the receptors adjacent to it. The response of a receptor to light is inhibited by its adjacent receptors in reverse relation to the distance to the adjacent receptor. Receptors directly on the brighter side of an intensity change have a stronger response than do those on the brighter side that are farther from the edge, because they receive less inhibition from their neighbors on the darker side. Similarly, receptors immediately to the darker side of an intensity change have a weaker response than do those father into the darker area, because they receive more inhibition from their neighbors on the brighter side. The Mach band effect is quite evident in Color Plate II.29, especially between adjacent polygons that are close in color.
The polygon-shading models we have described determine the shade of each polygon individually. Two basic shading models for polygon meshes take advantage of the information provided by adjacent polygons to simulate a smooth surface. In order of increasing complexity (and realistic effect), they are known as Gouraud shading and Phong shading, after the researchers who developed them. Current 3D graphics workstations typically support one or both of these approaches through a combination of hardware and firmware {software}.
16.2.4 Gouraud Shading.
{'Gouraud' is pronounced rather like goo (rhyming with 'hood') row (rhyming with 'how'); ie. the 'd' is silent}
'Gouraud shading' [GOUR71], also called 'intensity interpolation shading' or 'color interpolation shading', eliminates intensity discontinuities. Color Plate II.30 uses Gouraud shading. Although most of the Mach banding of Color Plate II.29 is no longer visible in Color Plate II.30, the bright ridges on objects such as the torus and cone are Mach bands caused by a rapid, although not discontinuous, change in the slope of the intensity curve; Gouraud shading does not completely eliminate such intensity changes.
Gouraud shading extends the concept of interpolated shading applied to individual polygons by interpolating polygon vertex illumination values that take into account the surface being approximated. The Gouraud shading process requires that the normal {perpendicular vector} be known for each vertex of the polygonal mesh. Gouraud was able to compute these 'vertex normals' directly from an analytical description of the surface. Alternatively, if the vertex normals are not stored with the mesh and cannot be determined directly from the actual surface, then, Gouraud suggested, we can approximate them by averaging the surface normals of all polygonal facets sharing each vertex (Fig 16.18). If an edge is meant to be visible (as at the joint between a plane's wing and body), then we find two vertex normals, one for each side of the edge, by averaging the normals of polygons on each side of the edge separately. Normals were not averaged across the teapot's patch cracks in Color Plate II.30.
The next step in Gouraud shading is to find 'vertex intensities' by using the vertex normals with any desired illumination model. Finally, each polygon is shaded by linear interpolation of vertex intensities along each edge and then between edges along each scan line (Fig. 16.19) in the same way that we describe interpolating z values in Section 15.4. The term 'Gouraud shading' is often generalized to refer to intensity interpolation shading of even a single polygon in isolation, or to the interpolation of arbitrary colors associated with polygon vertices {as is the case in computer games}.
The interpolation along edges can easily be integrated with the scan-line visible-surface algorithm of section 15.6. With each edge, we store for each color component {red, green and blue} the starting intensity and the change of intensity for each unit change in y. A visible span on a scan line is filled in by interpolating the intensity values of the two edges bounding the span. As in all linear-interpolation algorithms, a difference equation may be used for increased efficiency.
16.2.5 Phong Shading.
'Phong Shading' [BUIT75], also known as 'normal-vector interpolation-shading', interpolates the surface normal vector N, rather than the intensity. Interpolation occurs across a polygon span on a scan line, between starting and ending normals for the span. These normals are themselves interpolated along polygon edges from vertex normals that are computed, if necessary, just as in Gouraud shading. The interpolation along edges can again be done by means of incremental calculations, with all three components of the normal vector being incremented from scan line to scan line. At each pixel along a scan line, the interpolated normal is normalised, and is backmapped into the WC {world coordinate} system or one isometric to it, and a new intensity calculation is performed using any illumination model. Figure 16.20 shows two edge normals and the normals interpolated from them, before and after normalization.
Color Plates II.31 and II.32 were generated using Gouraud shading and Phong shading respectively, and illumination equation with a specular reflectance term. Phong shading yields substantial improvements over Gouraud shading when such illumination models are used, because highlights are reproduced more faithfully, as shown in Fig. 16.21. Consider what happens if n in the cos^n.a illumination term is large and one vertex has a very small a, but each of its adjacent vertices has a large a. The intensity associated with the vertex that has a small a will be appropriate for a highlight, whereas the other vertices will have nonhighlight intensities. If Gouraud shading is used, then the intensity across the polygon is linearly interpolated between the highlight intensity and the lower intensities of the adjacent vertices, spreading the highlight over the polygon (Fig. 16.21a). Contrast this with the sharp drop from the highlight intensity that is computed if linerly interpolated normals are used to compute the cos^n.a term at each pixel (Fig. 16.21b). Furthermore, if a highlight fails to fall at a vertex, then Gouraud shading may miss it entirely (Fig. 16.21c), since no interior point can be brighter than the brightest vertex from which it is interpolated. In contrast, Phong shading allows highlights to be located in a polygon's interior (Fig. 16.21d). Compare the highlights on the ball in Color Plates II.31 and II.32.
Even with an illumination model that does not take into account specular reflectance, the results of normal-vector interpolation are in general superior to intensity interpolation, because an approximation to the normal is used at each point. This reduces Mach-band problems in most cases, but greatly increases the {computational} cost of shading in a straighforward implementation, since the interpolated normal must be normalized every time it is used in an illumination model. Duff [DUFF79] has developed a combination of difference equations and table lookup to speed up the calculation. Bishop and Weimer [BISH86] provide an excellent approximation of Phong shading by using a Taylor series expansion that offers even greater increases in shading speed.
Another shading model, intermediate in complexity between Gouraud and Phong shading, involves the linear interpolation of the dot products used in the illumination models. As in Phong shading, the illumination model is evaluated at each pixel, but the interpolated dot products are used to avoid the expense of computing and normalizing any of the direction vectors. This model can produce more satisfactory effects than Gouraud shading when used in specular-reflection illumination models, since the specular term is calculated separately and thus has power-law, rather than linear, falloff {power-law falloff is closer to real-life}. As in Gouraud shading, however, highlights are missed if they do not fall at a vertex, since no intensity value computed for a set of interpolated dot products can exceed those computed for the set of dot products at either end of the span.
{See Note B below}
The implications of using flat-shading in graphics is that, for high realism and detail levels, a large number of flat-shaded polygons is needed for a good-looking image. Models can contain millions of polygons, yet the faceted nature of the model will still be visible in certain areas (this is due to a visual effect called Mach Banding). Very high detail requires a ridiculous number of polygons when using flat shading and as such it's not a technique that one would or should ever use for situations which require realism. However, CAD/CAM designers will find flat-shaded models useful, because they're very fast.
Conclusion: flat shading is of no use where realism is required; hence, if you see a flat-shading figure quoted for a games console, just ignore it.
Flat-shading is fast and ok for prototyping and testing, but is of little value for realistic games. Note that none of the next-gen consoles could cope with a multi-million polygon mesh in real-time, by which I mean 25fps or higher (one would need a flat-shaded polygon performance of about 240 million/second, which is about 200 times greater than that which even the best of the consoles can manage). In practice, the use of texture mapping enables one to vastly reduce the number of polygons required. In the case of planetary models, the increased realism gained from texture mapping would enable a reduction from having to use more than a million flat-shaded polygons to only a few thousand textured polygons.
Note B
In other words, Gouraud shading doesn't produce images as realistic as Phong shading when specular lights are involved, but Phong shading is a much more mathematically complex task (ie. it's slower). In practice, because the new games consoles use texture mapping anyway, the use of Phong shading would be a waste of computing resources; hence, as far as I know, none of the new consoles have the ability to do Phong shading. On the other hand, all of them can do Gouraud shading; when used in combination with texture mapping, Gouraud shading makes for good realistic scenes, though it does help considerably if good quality detailed textures are used in the first instance.
Warning! Warning! Marketing con trick! A common cheat that marketing people use is the phrase 'Phong Lighting'. It means that Phong-style equations are used to calculate the appropriate lighting value at each main vertex of a polygon (typically 3 or 4 points), but the Phong algorithm is not used to extrapolate those valuea cross the polygon's face - ordinary Gouraud shading is used instead. This is a very sneaky way of making people think that a system is doing Phong Shading (a more complex task than Gouraud shading) when in fact it's not.