# Phong shading

### From Wikipedia, the free encyclopedia

**Phong shading** refers to a set of techniques in 3D computer graphics. Phong shading includes a model for the reflection of light from surfaces and a compatible method of estimating pixel colors by interpolating surface normals across rasterized polygons.

These methods were developed by Bui Tuong Phong at the University of Utah, who published them in his 1973 Ph.D. dissertation.

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 reflects light as a combination of the diffuse reflection of rough surfaces with the specular reflection of shiny surfaces. It is based on Bui Tuong Phong's informal observation that shiny surfaces have small intense specular highlights, while dull surfaces have large highlights that fall off more gradually. The reflection model also includes an *ambient* term to account for the small amount of light that is scattered about the entire scene.

For each light source in the scene, we define the components *i*_{s} and *i*_{d} as the intensities (often as RGB values) of the specular and diffuse components of the light sources respectively. A single term *i*_{a} controls the ambient lighting; it is sometimes computed as a sum of contributions from all light sources.

For each *material* in the scene, we define:

*k*_{s}: specular reflection constant, the ratio of reflection of the specular term of incoming light*k*_{d}: diffuse reflection constant, the ratio of reflection of the diffuse term of incoming light (Lambertian reflectance)*k*_{a}: 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 is larger for surfaces that are smoother and more mirror-like. When this constant is large the specular highlight is small.

We further define lights as the set of all light sources, *L* as the direction vector from the point on the surface toward each light source, *N* as the normal at this point on the surface, *R* as the direction that a perfectly reflected ray of light would take from this point on the surface, and *V* as the direction pointing towards the viewer (such as a virtual camera).

Then *Phong reflection model* provide an equation for computing the shading value of each surface point *I*_{p}:

The diffuse term is not affected by the viewer direction (*V*). The specular term is large only when the viewer direction (*V*) is aligned with the reflection direction *R*. Their alignment is measured by the α power of the cosine of the angle between them. The cosine of the angle between the normalized vectors *R* and *V* is equal to their dot product. When α is large, in the case of a nearly mirror-like reflection, the specular highlight will be small because any viewpoint not aligned with the reflection will have a cosine slightly less than one and if this value will rapidly approach zero if is raised to a high power.

When we have color representations as RGB values, this equation will typically be calculated separately for R, G and B intensities.

## [edit] 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 small specular highlights 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 polygon. Since these specular highlights are absent from the polygon's vertices and Gouraud shading interpolates based on the vertex colors, the specular highlight will be missing from the polygon's interior. This problem is fixed by Phong shading.

Unlike Gouraud shading, which interpolates colors across polygons, in Phong shading we linearly interpolate a normal vector across the surface of the polygon from the polygon's vertex 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.

## [edit] See also

- Bidirectional reflectance distribution function, another reflection model
- Blinn–Phong shading model — Phong shading modified to trade precision with computing efficiency
- Bui Tuong Phong
- Gouraud shading
- Specular highlight — other specular lighting equations