# Blinn–Phong shading model

The Blinn–Phong shading model (also called Blinn–Phong reflection model or modified Phong reflection model) is a modification to the Phong reflection model developed by Jim Blinn.[1]

Blinn–Phong is the default shading model used in OpenGL and Direct3D's fixed-function pipeline (before Direct3D 10 and OpenGL 3.1), and is carried out on each vertex as it passes down the graphics pipeline; pixel values between vertices are interpolated by Gouraud shading by default, rather than the more computationally-expensive Phong shading.

## Description

Vectors for calculating Phong and Blinn–Phong shading

In Phong shading, one must continually recalculate the angle $R \cdot V$ between a viewer (V) and the beam from a light-source (L) reflected (R) on a surface.

If, instead, one calculates a halfway vector between the viewer and light-source vectors,

$H = \frac{L + V}{\left| L + V \right|}$

we can replace $R \cdot V$ with $N \cdot H$, where N is the normalized surface normal. In the above equation, L and V are both normalized vectors.

This dot product represents the cosine of an angle that is half of the angle represented by Phong's dot product if V, L, N and R all lie in the same plane. This relation between the angles remains approximately true when the vectors don't lie in the same plane, especially when the angles are small. The angle between N and H is therefore sometimes called the halfway angle.

The halfway angle is smaller than the angle desired in Phong's model, but considering that Phong is using $\left( R \cdot V \right)^{\alpha}$, an exponent can be set $\alpha^\prime > \alpha$ such that $\left(N \cdot H \right)^{\alpha^\prime}$ is closer to the former expression. The size of the specular highlights can be matched in this way very closely to a corresponding Phong reflection, but they will always retain a subtly different shape.

Additionally, while it can be seen as an approximation to the Phong model, it produces more accurate models of empirically determined bidirectional reflectance distribution functions than Phong for many types of surfaces. (See: Experimental Validation of Analytical BRDF Models, Siggraph 2004)

## Efficiency

This rendering model is less efficient than pure Phong shading in most cases, since it contains a square root calculation. While the original Phong model only needs a simple vector reflection, this modified form takes more into consideration. However, as many CPUs and GPUs contain single and double precision square root functions (as standard features) and other instructions that can be used to speed up rendering -- the time penalty for this kind of shader will not be noticed in most implementations.

However, Blinn-Phong will be faster in the case where the viewer and light are treated to be at infinity. This is the case for directional lights. In this case, the half-angle vector is independent of position and surface curvature. It can be computed once for each light and then used for the entire frame, or indeed while light and viewpoint remain in the same relative position. The same is not true with Phong's original reflected light vector which depends on the surface curvature and must be recalculated for each pixel of the image (or for each vertex of the model in the case of vertex lighting).

In most cases where lights are not treated to be at infinity, for instance when using point lights, the original Phong model will be faster.

## Code sample

This sample in High Level Shader Language is a method of determining the diffuse and specular light from a point light. The light structure, position in space of the surface, view direction vector and the normal of the surface are passed through. A Lighting structure is returned;


struct Lighting
{
float3 Diffuse;
float3 Specular;
};

struct PointLight
{
float3 position;
float3 diffuseColor;
float diffusePower;
float3 specularColor;
float specularPower;
};

Lighting GetPointLight(PointLight light, float3 pos3D, float3 viewDir, float3 normal)
{
Lighting OUT;
if(light.diffusePower > 0)
{
float3 lightDir = light.position - pos3D; // FIND THE VECTOR BETWEEN THE 3D POSITION IN SPACE OF THE SURFACE
float distance = length(lightDir); // GET THE DISTANCE OF THIS VECTOR
distance = distance * distance; // USES INVERSE SQUARE FOR DISTANCE ATTENUATION
lightDir = normalize(lightDir); // NORMALIZE THE VECTOR

// INTENSITY OF THE DIFFUSE LIGHT
// SATURATE TO KEEP WITHIN THE 0-1 RANGE
// DOT PRODUCT OF THE LIGHT DIRECTION VECTOR AND THE SURFACE NORMAL
float i = saturate(dot(lightDir, normal));

OUT.Diffuse = i * light.diffuseColor * light.diffusePower / distance; // CALCULATE THE DIFFUSE LIGHT FACTORING IN LIGHT COLOUR, POWER AND THE ATTENUATION

//CALCULATE THE HALF VECTOR BETWEEN THE LIGHT VECTOR AND THE VIEW VECTOR. THIS IS CHEAPER THAN CALCULATING THE ACTUAL REFLECTIVE VECTOR
float3 h = normalize(lightDir + viewDir);

// INTENSITY OF THE SPECULAR LIGHT
// DOT PRODUCT OF NORMAL VECTOR AND THE HALF VECTOR TO THE POWER OF THE SPECULAR HARDNESS
i = pow(saturate(dot(normal, h)), specularHardness);

OUT.Specular = i * light.specularColor * light.specularPower / distance; // CALCULATE THE SPECULAR LIGHT FACTORING IN LIGHT SPECULAR COLOUR, POWER AND THE ATTENUATION
}
return OUT;
}


## References

1. ^ James F. Blinn (1977). "Models of light reflection for computer synthesized pictures". Proc. 4th annual conference on computer graphics and interactive techniques: 192. doi:10.1145/563858.563893.

Wikimedia Foundation. 2010.

### Look at other dictionaries:

• 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… …   Wikipedia

• Phong — may refer to: Computer graphics *Phong shading *Blinn–Phong shading model *Bui Tuong Phong creator of the Phong shading interpolation method and reflection model. Other *Phong Kniang language *Nam Phong *A character in the animated show ReBoot *A …   Wikipedia

• Gouraud shading — Gouraud shading, named after Henri Gouraud, is a method used in computer graphics to simulate the differing effects of light and colour across the surface of an object. In practice, Gouraud shading is used to achieve smooth lighting on low… …   Wikipedia

• Jim Blinn — James F. Blinn is a computer scientist who first became widely known for his work as a computer graphics expert at NASA s Jet Propulsion Laboratory (JPL), particularly his work on the pre encounter animations for the Voyager project, [See Wayne… …   Wikipedia

• Specular highlight — Specular highlights on a pair of spheres. A specular highlight is the bright spot of light that appears on shiny objects when illuminated (for example, see image at right). Specular highlights are important in 3D computer graphics, as they… …   Wikipedia

• Schlick's approximation — In 3D computer graphics, Schlick s approximation is a formula for approximating the BRDF of metallic surfaces. It was proposed by Christophe Schlick to approximate the contributions of Fresnel terms in the specular reflection of light from… …   Wikipedia

• Rendering (computer graphics) — Not to be confused with 3D rendering. A variety of rendering techniques applied to a single 3D scene …   Wikipedia

• 3D rendering — is the 3D computer graphics process of automatically converting 3D wire frame models into 2D images with 3D photorealistic effects on a computer.Rendering methods Main Article: RenderingRendering is the final process of creating the actual 2D… …   Wikipedia

• Рендеринг — Фотореалистичное изображение, созданное POV Ray 3.6. Модели кувшина, стаканов и пепельницы созданы при помощи Rhinoceros 3D, модель игральной кости  в Cinema 4D. Рендеринг ( …   Википедия

• Рендер — Фотореалистичное изображение, отрендеренное в Rhinoceros 3D, модель игральной кости  в Cinema 4D. Рендеринг (англ. rendering  «визуализация») в компьютерной графике  процесс получения изображения по модели с помощью компьютерной программы. Здесь… …   Википедия