Per pixel lighting with normal mapping. Instead of using the interpolated vertex normal, this shader samples from a normal map. The lighting calculation is done in a surface local space, defined at each vertex by three vectors (tangent, original vertex normal and binormal). At each vertex the light and view vector are transformed into the surface local space and then interpolated across the triangle.
To get good results, the three vectors at the vertices should behave nicely and shouldn't jump around to much. Right now these vectors are still hard coded in the vertex shader, so this shader works only on surfaces parallel to the x / z plane. The next step will be to make these vectors proper vertex attributes and store them in the vertex array. I then have to found a method to compute the vectors for arbitrary geometry loaded from .3ds files.
|