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. This problem is fixed by Phong shading.
Some argue that using smaller triangles fixes the problem of Gouraud shading, with respect to specular highlights. Others counter that Phong shading is better able to handle large triangles, and that in any case, very sharp specular highlights would require tiny triangles. The truth is somewhere in between, and it pays to remember that Phong interpolation does very little to soften the abrupt change in color gradient near the edges of triangles. In fact, the improved handling of specular highlights can worsen this problem.
Our goal is to calculate the color from physical illumination data. We are given a position V in three dimensional space, a normal N (we presume that V is on a surface whose normal is N.) We also have the position of a light L. We are given the following scalar values: a specular coefficient x, and a specular power y. We are also given the position of the observer E.
The vector from the surface to the light is Z=LV. We can compute the reflection R of this vector about N. For insstance, if N is unit, note that R+Z=2(Z dot N)N hence R=2(Z dot N)NZ.
Set W=EV, the vector from the surface to the eye. Normalize R and W. Then, the scalar value R dot W will be nearly one if the observer is in the direction of the reflection R, and will decay to 1 as the eye moves away from the direction. Let s be the maximum of R dot W and 0 (i.e., R dot W clamped to 0.)
The Phong specular contribution is simply x*s^y.
We can also calculate a diffuse contribution, by calculating (E dot N)/E and multiplying by a diffuse coefficient. Of course, negative values should be treated as a 0.
Lastly, we can add a constant, which we call "ambient light".
The sum of ambient light, diffuse contribution and specular contribution is the Phong Illumination Model.
We are given three vertices in two dimensions, v1, v2 and v3, as well as normals for each vertex n1, n2 and n3; we assume these are of unit length. As in Gouraud shading, we linearly interpolate[?] a normal N across the surface of the triangle, from the three given normals. This is done, as in Gouraud shading, for each pixel in the triangle, and at each pixel we normalize N and use it in the Phong illumination model to obtain the final pixel color.
In some modern hardware, variants of this algorithm are called "pixel shading." It usually means that the lighting calculations can be done perpixel, and that the lighting variables are interpolated across the triangle.
Search Encyclopedia

Featured Article
