The subject of Phong shading receives careful treatment in most books on computer graphics, and here I will only say enough about it to explain its use in 3D-XplorMath.

As mentioned in the section on color, the Phong model for shading surfaces (the one used by 3D-XplorMath) considers that light incident from a light source and reflected from a given surface patch is made up of two components. First there is a "diffuse" component, the intensity iof which iss independent of the viewing direction and is proportional to the cosine of the angle between the normal to the patch and the direction of the incoming light rays. This models quite well the effect of light reflected off a rough or matte surface. On the other hand, the intensity of the second or "specular" component is depends strongly on the View Direction and models the quality of glossiness of a polished surface. If the diffuse component predominates too strongly then the surface may seem flat and lifeless, while if the specular component is too strong then the surface may seem metallic and shiny with concentrated "hotspots". A good balance between the two will give the most realistic effect and enhances the three-dimensional qualities of the rendering. We have discussed above the way that the diffuse component is computed, and we consider next how to compute the intensity of the specular component, and how to to combine the intensities of the two components.

Suppose the light from a point source is travelling in a certain direction v. The "Law of Reflection" (the angle of incidence equals the angle of reflection) determines a certain direction w for the rays reflected off the surface patch. If the surface were a perfect reflector, then the light reflected from the source would have a maximum intensity I when viewed from a point in the direction w as seen from the patch, and zero from any other direction. Let P be a viewpoint, and let A be the angle between the direction w and the direction from the patch to P. Then the intensity of the light from the source as seen at P is I f(cos(A)), where f(1)=1 and f(t)=0 for t < 1. The function cos^n(A) approximates f(cos(A)) well when n is large, and I cos^n(A) is taken as the law of reflection for an imperfect reflector in the Phong model. We call the choice of n the "Specular Exponent". Clearly if n is small then highlights will be spread out and diffuse, while if n is large then highlights will be almost pointlike.

Let's assume that if all the light were diffusely reflected the intensity would be I_d while if all the light were reflected specularly then the intensity would be I_s. How should we combine these to find a total intensity I? A first guess is to assume that a certain fraction r (called the "Specular Ratio") of the incident light is reflected specularly and the rest is reflected diffusely. This leads to the addition formula (1-r) I_d + r I_s, and this was the original formula that I used. However I was a little dissatisfied with the results and after some playing around I settled on the formula (1-k r) I_d + r I_s where k seemed best at around 0.6.

Documentation Table Of Contents.

Documentation Index.