Phong shading
From Wikipedia, the free encyclopedia
Phong shading refers to a set of techniques in 3D computer graphics. Phong shading combines a model for the reflection of light from surfaces with a compatible method of estimating pixel colors using interpolation of surface normals across rasterized polygons.
These methods were developed by Bui Tuong Phong, who published them in his 1973 Ph.D. dissertation at the University of Utah.
The model of reflection may also be referred to as the Phong reflection model, Phong illumination or Phong lighting. It may be called Phong shading in the context of pixel shaders or other places where a lighting calculation can be referred to as "shading".
The interpolation method may also be called Phong interpolation, and is also usually what is referred to by "per-pixel lighting". Typically it is called "shading" when being contrasted with other interpolation methods such as Gouraud shading or flat shading. The Phong reflection model may be used in conjunction with any of these interpolation methods.
[edit] Phong reflection model
Phong reflection is an empirical model of local illumination. It describes the way a surface is lit as a combination of the diffuse lighting of rough surfaces with the specular reflection of shiny surfaces. It is based on Bui Tuong Phong's informal observation that for very shiny surfaces the specular highlight was small and the intensity fell off rapidly, while for duller surfaces it was larger and fell off more slowly. Additionally it includes an ambient term to simulate the way that a low level of light is typically present everywhere in a scene.
We first define, for each light source in the scene to be rendered, the components is and id, where these are the intensities (often as RGB values) of the specular and diffuse components of the light sources respectively. A single ia term controls the ambient lighting; it is sometimes computed as a sum of contributions from the light sources.
If we then define, for each material (which is typically assigned 1-to-1 for the object surfaces in the scene):
- ks: specular reflection constant, the ratio of reflection of the specular term of incoming light
- kd: diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light (Lambertian reflectance)
- ka: ambient reflection constant, the ratio of reflection of the ambient term present in all points in the scene rendered
- α: is a shininess constant for this material, which decides how "evenly" light is reflected from a shiny spot, and is very large for most surfaces, on the order of 50, getting larger the more mirror-like they are.
We further define lights as the set of all light sources, L is the direction vector from the point on the surface toward each light source, N is the normal at this point of the surface, R is the direction that a perfectly reflected ray of light (represented as a vector) would take from this point of the surface, and V is the direction towards the viewer (such as a virtual camera).
Then the shade value for each surface point Ip is calculated using this equation, which is the Phong reflection model:
The diffuse term does not use the direction towards the viewer (V), as the diffuse term is equal in all directions from the point, including the direction of the viewer. The specular term, however, is large only when the reflection vector R is nearly aligned with viewpoint vector V, as measured by the α power of the cosine of the angle between them, which is the dot product of the normalized direction vectors R and V. When α is large, representing an almost mirror-like reflection, the specular reflection will be very small because the high power of the cosine will go rapidly to zero with any viewpoint not aligned with the reflection.
When we have color representations as RGB values, this equation will typically be calculated individually for R, G and B intensities.
[edit] Phong interpolation
As a rendering method, Phong shading can be regarded as an improvement on Gouraud shading that provides a better approximation to a point-by-point application of an underlying reflection model by assuming a smoothly varying surface normal vector. The Phong interpolation method works better than Gouraud shading when applied to the Phong reflection model or to any reflection model that has small specular highlights.
The main problem with Gouraud shading is that when a specular highlight occurs near the center of a large triangle, it will usually be missed entirely due to the interpolation of colors between vertices. This problem is fixed by Phong shading.
We are given three vertices in two dimensions, v1, v2 and v3, as well as surface normals for each vertex n1, n2 and n3; we assume these are of unit length. Unlike Gouraud shading, which interpolates colors across triangles, in Phong shading we linearly interpolate a normal vector N across the surface of the triangle from the three given normals. This is done for each pixel in the triangle, and at each pixel we normalize N and use it in the Phong reflection model to obtain the final pixel color.
In some modern hardware, variants of this algorithm are implemented using pixel or fragment shaders. This can be accomplished by coding normal vectors as secondary colors for each polygon, have the rasterizer use Gouraud shading to interpolate them and interpret them appropriately in the pixel or fragment shader to calculate the light for each pixel based on this normal information.
[edit] See also
- Blinn–Phong shading model — Phong shading modified to trade precision with computing efficiency
- Bui Tuong Phong
- Specular highlight — Other specular lighting equations
- Gouraud shading
- Bidirectional reflectance distribution function : Another reflection model


