Hi
At the moment I am studying on normal mapping. I have a large terrain structure on which I am going to apply a normal map. I have a question about TBN space calculations.
In my current code, I traverse all the triangles of my terrain and calculate the T,B and N vectors for the three vertices of the related triangle. I store the calculated data per-triangle in a structure like this:
struct VertexNormal
{
D3DXVECTOR3 Tangent;
D3DXVECTOR3 Binormal;
D3DXVECTOR3 Normal;
int NumberOfContributingTriangles;
};
The general working of my code is like:
for(every triangle T of the Terrain)
{
Find out the vertices v1,v2 and v3 of T;
Calculate T,B and N vectors;
for(i=0 to i=2)
{
VertexNormal[vi].Tangent +=T;
VertexNormal[vi].Binormal+=B;
VertexNormal[vi].Normal +=N;
VertexNormal[vi].NumberOfContributingTriangles++;
}
}
After obtaining per-vertex TBN data a code similar to the following runs:
for(every vertex v of the Terrain)
{
int N=VertexNormal[v].NumberOfContributingTriangles;
VertexNormal[v].Tangent /=N;
VertexNormal[v].Binormal/=N;
VertexNormal[v].Normal /=N;
Normalize(VertexNormal[v].Tangent);
Normalize(VertexNormal[v].Binormal);
Normalize(VertexNormal[v].Normal);
}
My problem lies at this point.At this stage, by a very high possibility, Tangent,Binormal and Normal vectors of a vertex is no more orthogonal to eachother. (Not orthonormal.) But as the T,B and N vectors suppose to represent a seperate coordinate frame and will be used for transforming light vectors to the texture space, they obviously should. Now my question is; how can I ensure that the TBN vectors will stay or become orthonormal after averaging them per vertex?
Thanks in advance