< Zurück | Inhalt | Weiter >

Phong shading

Two years after Gouraud, Bui Tuong Phong developed an algorithm to incorporate specular highlights into the intensity interpolation algorithm developed by Gouraud. So−called Phong shading computes an approximate normal vector for each point along the scan lines. These intermediate normal vectors can then be used to calculate an intensity based partly on the interpolated Gouraud shading component and partly from a point’s normal vector.

Consider a triangular surface where the averaged normal vector for two of the vertices was a little less than 90 degrees while the averaged normal vector for the third vertex was a little more than 90 degrees. If the surface were Gouraud shaded, the interpolated intensities would be fairly uniform across the surface (as the cosine of the angle for each normal vector would be approximately equal). However, the planar surface is probably intended to model a smooth surface fitted between the vertices of the surface. If this is the case, then at some point across the surface, the normal vector must reach 90 degrees. This point, within the surface, should therefore be assigned a higher intensity than any of the vertices at the edges of the surface. Phong shading, by interpolating the normal vectors across the surface, as well as Gouraud intensity, can introduce local highlights that would otherwise be merely averaged into the intensity of the surface as a whole. Phong introduced a new coefficient for each surface, called shininess, that controls how radically the surface responds to light and influences the size of a surface’s specular highlight.

An interesting compromise must be made between Lambert and Gouraud shading, as the averaging behavior of Gouraud shading must be balanced with the facet display behavior of Lambert shading. Using Gouraud shading, it is easy to display a coarsely triangulated sphere that is beautifully and smoothly shaded and has Phong specular highlights applied, but whose edges are straight—and belie the faceted nature of the model.

Lambert shading varies the intensity of a surface based on its angle relative to a light source.

Gouraud shading smoothes Lambert shading across a surface and between surfaces.

Phong shading can add specular highlights to Gouraud shading.

Notice that these three components are visible in the Java 3D lighting equations given in section 10.1.1. As should be clear from these equations, lights are expensive computationally and you should design your scene’s lighting requirements in the context of general application performance and usability. With artful design, however, apparently complex lighting can be created with a fairly modest number of lights. The surface smoothing characteristics of the lighting equations can also be gainfully employed to give coarsely meshed models a smoother appearance. If the models in the scene contain fewer vertices, the scene may render quicker, even with the added overhead of a more complex shading model.