There are many ways to calculate these vectors. Some are more accurate than others, but it
depends exactly what you mean by accurate. One of the most common methods is to calculate the
X and Y gradient at that pixel:
x_gradient = pixel(x-1, y) - pixel(x+1, y)
y_gradient = pixel(x, y-1) - pixel(x, y+1)
With these two gradients, you will now need to adjust the normal vector of the polygon at
Here is the polygon, with it's origional normal vector, n. Also shown are the two
vectors which are going to be used to adjust the normal vector for this pixel. The two vectors
must be aligned with the bumpmap for the polygon to be rendered correctly. I.E. the vectors are
parallel to the axes of the bumpmap.
On the right are the bump map, and the polygon. Both pictures show the U and V vectors.
Now you can see the new Normal vector after adjustment. The adjustment is simply:
New_Normal = Normal + (U * x_gradient) + (V * y_gradient)
With this New_Normal vector, you can procede to calculate the brightness of the polygon at
that point, using the usual phong shading technique.