TimS

09-04-2011, 09:06 PM

I'm having some trouble with math behind per-pixel lighting when using normal maps.

This is what I understand so far (please correct me if I'm mistaken):

In the case of a single triangle, the T,B,N vectors for each vertex are the same, and is equal to the T,B,N vectors of the face. To light the face, the light vector is transformed into tangent space (by the matrix defined by the T,B,N vectors of the face), and then the standard Np dot L light equation is applied. The normal Np of any point on the triangle is defined in tangent space by the given normal map.

This is what I don't quite get:

In the case of a a smooth shaded mesh, the T,B,N vectors for each vertex are averaged across each connected face. This means any given triangle will have 3 different light vectors, each in their own unique tangent space. How do you light a point on a triangle in this case? Calculate Np dot L for each light vector, and then average it? Or Interpolate the light vectors (like with interpolating vertex normals in phong shading) to get the light vector at that specific point?

There are some resources online about the subject, but most seem to simplify the case into face/surface T,B,N vectors instead of per-vertex T,B,N vectors. Others mention that a light vector for each vertex is used in per-pixel lighting, but the actual calculations are not given.

This is what I understand so far (please correct me if I'm mistaken):

In the case of a single triangle, the T,B,N vectors for each vertex are the same, and is equal to the T,B,N vectors of the face. To light the face, the light vector is transformed into tangent space (by the matrix defined by the T,B,N vectors of the face), and then the standard Np dot L light equation is applied. The normal Np of any point on the triangle is defined in tangent space by the given normal map.

This is what I don't quite get:

In the case of a a smooth shaded mesh, the T,B,N vectors for each vertex are averaged across each connected face. This means any given triangle will have 3 different light vectors, each in their own unique tangent space. How do you light a point on a triangle in this case? Calculate Np dot L for each light vector, and then average it? Or Interpolate the light vectors (like with interpolating vertex normals in phong shading) to get the light vector at that specific point?

There are some resources online about the subject, but most seem to simplify the case into face/surface T,B,N vectors instead of per-vertex T,B,N vectors. Others mention that a light vector for each vertex is used in per-pixel lighting, but the actual calculations are not given.