# Question on normal mapping - averaging the TBN space

This topic is 3623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013754
×