Phong shading
From DmWiki
Phong shading (named after the Vietnamese graphics researcher Phong Bui-Tuong) refers to a simple local illumination model, that extends Lambert diffuse lighting by allowing an additional specular highlight on a material. Historically, it also refers to a shading method in which a lighting equation is evaluated at every pixel rather than being evaluated at the vertices only, as in Gouraud shading.
| Table of contents |
Phong illumination model
Phong diffuse illumination
The diffuse term of the Phong illumination model is calculated by taking the dot product between the vector from the surface to the light source and the surface normal at the point to be illuminated. This is the same as in the Lambert illumination model.
In case the dot product is negative, the angle between the surface and the light source must be greater than 90 degrees, which means it is behind the surface. Thus the surface would not be illuminated at all.
Phong specular highlight
Phong's model of the specular highlight calculates the following value, the specular coefficient, as follows:
where r is the reflection vector (formed by reflecting the light vector l about the normal vector n):
and v is the view vector.
An alternative formulation of the Phong specular highlight is:
where h is the half-angle vector between the view and light vectors,
This is technically called the Blinn highlight (after Jim Blinn, the inventor of bump mapping), but is often referred to as a Phong highlight.
In both cases, the value n, called the Phong exponent, determines how sharp the highlight appears. Smaller values (e.g. 20 to 60) create a large, dull-looking highlight, while higher values (eg. 60 to 200 and higher) create a smaller, focused highlight. At an specular exponent of infinity the surface would become a perfect reflector (e.g. a mirror).
All vectors must be normalized for these formulas to work correctly.
Putting it together
The final phong equation, representing the total amount of light reflected by a surface, is :
. Where matdiff and matspec are material properties. The above equation is wavelength dependant, which in practice means that it has to be evaluated for each color component (R, G ,B). In the normal case this is represented by letting the material properties be vector values, representing the reflection properties on the red, green and blue wavelengths.
Alternatively matspec is often set to be the lights color.
Sometimes an additional, constant valued, ambient term is introduced that represents background illumination that always occurs and is the same from any direction. Basically this is a crude way to account for indirect illumination.
Phong shading
Older graphics systems used only Lambert diffuse lighting, which varies relatively slowly over the surface of an object. As a result, it was possible to get away with Gouraud shading: the lighting equation would be evaluated only at the vertices of a model, and the resulting color interpolated bilinearly across the model's surface.
However, when specular highlights are added the color changes very rapidly in the region around the highlight. Gouraud shading was no longer adequate; if it is used, specular highlights will appear to fade in and out as the camera or surface moves, unless the surface is very highly tesselated.
Thus, Phong shading calls for each of the inputs to the lighting equation, i.e. the three vectors n, l, and v, to be bilinearly interpolated across the surface of the model. Then, at each pixel, the three vectors are normalized and used to evaluate the lighting equation. This is an ideal job for a pixel shader.
See also
