All About Lighting

by Ga'ash Soffer on December 26, 1998 7:57 PM EST

Phong Shading and Angle Interpolation

 

Well, we know that Gouraud shading is extremely fast, but also extremely ugly. The main problem with Gouraud shading is the lack of highlights, where necessary. There is another shading model which will give us the cool highlights that we want. This algorithm would be called Phong Shading.

What is it?

Recall that with Gouraud shading, intensities are interpolated? Well, with Phong shading, the normal between the vertices and the light source are interpolated, and the color calculated from these normals, per pixel. Obviously, this approach is quite slow, but it is much more accurate than Gouraud shading, not to mention it looks much much better. (A common misconception is that Phong shading is "real" shading. This is not the case. Phong shading linearly interpolates between normals, since you can't linearly interpolate between normals without generating error, Phong shading, is, well, wrong)

What's wrong with Phong?

The problem with Phong shading is that it is very very slow. Phong shading interpolates between normal vectors to get a normal vector at each pixel. For each pixel, it then uses this normal vector to calculate the light intensity at that point. This calculation is quite hefty, considering it must be done for each pixel. Currently, real time phong shading a 5-10k polygon level is virtually impossible. Of course, it is possible to generate a low resolution (16x16 or so) "phong texture" and then blend it in during rasterization (displaying the polygon). Chances are, this approach will be much (probably 4x or so) faster than Phong shading per-pixel in the rasterization loop, plus it is the only method of doing Phong shading in hardware. (Since no hardware I know of does Phong shading)

Another way of getting the highlight

Even though Phong is so slow, that doesn't mean that there isn't a way to get that cool highlight which is at least relatively fast. That method is, Angle Interpolation. Angle interpolation works virtually the same as Gouraud shading; however, instead of interpolating intensities, one interpolates (I bet you can't guess this one :) angles. Angle interpolation requires 1 addition and 1 table look up (that gives the intensity at various angles). Obviously, this is MUCH faster than Phong shading. Of course, you can't linearly interpolate angles without error (bummer), so angle interpolation is an approximation. This method looks relatively good (not as good as Phong shading, but close enough), and is very fast. Using the texture blending method discussed above, angle interpolation can be combined with 3D acceleration to help make some very fast nice looking dynamic lights.

 

 

 

 

 

 

Index Real lighting
Comments Locked

0 Comments

View All Comments

Log in

Don't have an account? Sign up now