graphics-snippets

StackOverflow


Phong reflection model

About the nomenclature

The Phong reflection model must not be confused with Phong shading. While Phong shading in common means the technique, which does the light calculations per fragment, is the Phong reflection model a light model, which was presented by Bui Tuong Phong in 1975.
Note, in compare to Phong shading, at Gouraud Shading, the light calculations ar done per vertex. The calculated light is interpolated according to the Barycentric coordinate of the fragment on the primitive. This increases the performance, but gives a big loss of quality, especially on large primitives.
In common the Phong reflection model and the Phong shading technique are used together.

The Phong model is easy to compute with a small number of operations, but it is an empirical model which obeys neither energy conservation nor reciprocity. It is an approximation model, based on an statistic distribution of microfacettes. It depends on an alpha angle, which is calculated after reflecting the incident direction. \n

dot A, B

alpha   = theta_o - theta_i
f_phong = max(0, pow(cos(alpha), sh)

sh (shininess) in [0, infinite] characterizes the shape of the specular highlight (from 0 or dull to more glossy surface). The Phong model works well with large exponents, but has issues and limitations with small exponents.

cos(alpha) can be caluclated by the dot product of the view vector and the reflection vector:

R       = reflect(L, N)
VdotR   = dot(V, R)
f_phong = max(0, pow(VdotR, sh))

reflect L, N

dot V, R


GLSL coding:

float Distribution_Phong( vec3 esVEye, vec3 esVLight, vec3 esPtNV, float shininess ) 
{
    vec3 reflVector = normalize( reflect( -esVLight, esPtNV ) );
    return 4.0 * max( pow( dot(reflVector, esVEye), 0.3 * shininess ), 0.0 );
}


Furthermore, the performance of this model could be improved by an optimization of the exponential operator, like the approximation given by Schlick:

VdotR_sh = VdotR / (sh - sh * VdotR - VdotR)


Obvious issues

Phong Clipping

If the light is close to the surface, the specular area tends to have very sharp edges. This is part of the nature of specular reflections. If the light is almost perpendicular to the surface, the specular reflection will shine brightest when the light is almost eclipsed by the surface. This creates a strong discontinuity at the point where the light is no longer in view.
You generally see this most with rough surfaces (small exponents). With smoother surfaces, this is rarely seen.

Phong Distortion

This ring area shows one of the main limitations of the Phong model. When trying to depict a surface that is rough but still has specular highlights, the Phong model starts to break down. It will not allow any specular contribution from areas outside of a certain region.

This region comes from the angle between the reflection direction and the view direction. This area is the region where the reflection direction and view direction are more than 90 degrees apart.

Under the microfacet model, there is still some chance that some microfacets are oriented towards the camera, even if reflection direction is pointed sharply away. Thus, there should be at least some specular contribution from those areas. The Phong model cannot allow this, due to how it is computed.


See also:


<hr/>

profile for Rabbid76 on Stack Exchange, a network of free, community-driven Q&A sites