Now we'll look at this polygon at an angle so the vector from the light source to the vertex
can be seen. This is vector L.
The aim is to calculate the coordinates (u,v) in terms of
V, H and L
The algorithm is a very simple one. If the phong map is 256x256 and centered then:
u = ( V . L ) * 128 + 127
v = ( H . L ) * 128 + 127
do this for each vertex, and then map the Phong map onto it, and there you have one nicely phong
Since this can be slow, there are various ways you can speed it up if you don't mind a little
loss of freedom. If you assume that the light source is at the same place as the camera, then you
can ignore the V and H
vectors altogether. Instead take the X and Y components of the normal vector, multiply
by 128 and add 127 (assuming that is that the magnitude of the normal vector is 1).
Alternatively, you can take the light source as being like an inverse camera. Transform the
object as if the light source were the camera, and calculate the phong as in the previous
Notes on Fake Phong Shading
As you would probably expect, this method is not perfect. The fact that the Phong Map has
a limited resolution means that sometimes the highlights on an object will look a little
pixelated. This will not really be noticable though if the object is spinning or moving quickly.
If you add bump mapping, the effect will be barely noticable.
One artifact of the technique is that you get the effect of 2 light sources. The first will
be where you expected it to be. The other will appear to be on the other side of the object. This
is possible to overcome, and I will explain how to do this later, and how to make that extra light
a different colour if you want.
If you're really clever with a bump map, you can turn it into a shinyness map too. It is
possible to have, say, an object with diffuse bits and chrome bits, all controled by the bump
map. I'll get onto this n the next article on Bump Mapping.