- Phong shading
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 usinginterpolation ofsurface normal s acrossrasterize d polygons.These methods were developed by
Bui Tuong Phong , who published them in his 1973 Ph.D. dissertation at theUniversity 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 shader s 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 asGouraud shading orflat shading . The Phong reflection model may be used in conjunction with any of these interpolation methods.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 onBui Tuong Phong 's informal observation that for very shiny surfaces thespecular 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 and , where these are the intensities (often as
RGB values) of the specular and diffuse components of the light sources respectively. A single 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):
:: specular reflection constant, the ratio of reflection of the specular term of incoming light:: diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light (
Lambertian reflectance ):: 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 as the
set of all light sources, is the direction vector from the point on the surface toward each light source, is the normal at this point of the surface, is the direction that a perfectly reflected ray of light (represented as a vector) would take from this point of the surface, and is the direction towards the viewer (such as a virtual camera).Then the shade value for each surface point is calculated using this equation, which is the "Phong reflection model":
:
The diffuse term does not use the direction towards the viewer (), 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 is nearly aligned with viewpoint vector , as measured by the power of the cosine of the angle between them, which is the
dot product of the normalized direction vectors and . 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.
Phong interpolation
Phong shading improves upon
Gouraud shading and provides a better approximation of the shading of a smooth surface. Phong shading assumes a smoothly varying surface normal vector. The Phong interpolation method works better than Gouraud shading when applied to a reflection model that has smallspecular highlight s such as the Phong reflection model.The most serious problem with Gouraud shading occurs when specular highlights are found in the middle of a large triangle. Since these specular highlights are absent from the triangle's vertices and Gouraud shading interpolates based on the vertex colors, the specular highlight will be missing from the triangle's interior. This problem is fixed by Phong shading.
Unlike
Gouraud shading , which interpolates colors across triangles, in Phong shading we linearly interpolate a normal vector across the surface of the triangle from the three given normals. The surface normal is interpolated and normalized at each pixel and then used in the Phong reflection model to obtain the final pixel color. Phong shading is more computationally expensive than Gouraud shading since the reflection model must be computed at each pixel instead of at each vertex.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.
ee 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
Wikimedia Foundation. 2010.