CS184 Lecture 30 summary

Gouraud Shading

Gouraud shading is a method to remove facetization effects on polygonal meshes (IndexedFaceSets in VRML) and to make them appear closer to smooth surfaces. Without Gouraud shading, the brightness of a polygonal facet is nearly constant, since it is the dot product of the facet normal with the light shource direction. An adjacent facet with a different normal will have a different brightness, leading to a sharp boundary between the two. This kind of shading is called flat shading, since it emphasizes that the facets are flat.

Here is a cylinder in VRML with flat shading. Here is the same cylinder smoothly shaded.

The simplest way to obtain the smooth shading effect is with Gouraud shading. In this method, there are 3 steps. First we assume that the surface has been subdivided into triangles. Then we:

The last step forces us to use triangular polygons (why?). To get the average unit normal vector at a vertex, we take the average of the normals of the neighboring faces. Since the resulting normal should be a unit normal, we can do the averaging by summing all the neighboring normals, and then dividing by the magnitude of this sum.

Interpolation can be done in one of two ways:

Barycentric coordinates. If the triangle has vertices A, B, C, then every point inside it can be expressed with Barycentric coordinates aB + bB + cC, where a, b, c, are positive scalars whose sum is 1. The intensity at the point (a,b,c) is then aIA + bIB + cIC where aIA is the intensity computed for vertex A etc.

Scanline methods. Scanline methods are optimized for display on a raster graphics device, or indeed, on any device that uses an array of output values. To compute the intensities at pixels along a line, we first intersect the line with the polygon, which gives us two endpoints E and F. Each of E and F lies between two of the vertices of the triangle, and we can linearly interpolate to compute their intensities IE and IF. Then we linearly interpolate between E and F to generate the intermediate vertices. Because these vertices have constant offsets, the increments in intensity will also be constant. So we can compute all these points intensities by adding a fixed constant from one pixel intensity to get the next.

For this reason, Gouraud shading is popular on some low-end renderers, e.g. Doom.

Phong Shading

One problem with Gouraud shading is that it does not really simulate a curved surface. On a real curved surface, the normal changes direction within a surface patch. The intensities that result may not correspond to linear interpolates of the vertex intensities. In particular, if there is a specular highlight somewhere in the middle of the face, that point will be bright while all the vertices will be dull. A more accurate shading model is Phong Shading. In Phong shading, the normals are linearly interpolated from the vertex normals. Then the lighting model is applied to every point using the computed normal.

Phong Shading is clearly going to be slower than Gouraud, since the latter only requires one addition per pixel using a scan-line method. There is a refinement of Phong shading called fast Phong shading which can be used for diffuse surfaces (but doesnt work for specular). It approximates the actual equation with a second-order Taylor series, and then uses forward difference methods to compute the Taylor series along a scan-line.

Here is the vase with specular highlights from last lecture. See if you can determine if the VRML browser is doing Gouraud or Phong Shading of the polygons.