# How to generate Tangent & Binormal from a given Face?

I’m implementing a dot3 Bump mapping using 3 texture unit with Normal Cube Map.
So I’ve got a problem with Tangent & binormal Vectors Generation.

Tangent_List = new CVector3D[Num_Vertices];
Binormal_List = new CVector3D[Num_Vertices];

for(unsigned int j=0; j<Num_Faces*3; j+=3)
{
CVector3D vec1, vec2;
int i = FaceIndex_List[j];
int i1 = FaceIndex_List[j+1];
int i2 = FaceIndex_List[j+2];

``````  vec1 = Vertex_List[i2] - Vertex_List[i];
vec2 = Vertex_List[i1] - Vertex_List[i];

float d_u1 = Mapping_List[i2].x - Mapping_List[i].x;
float d_u2 = Mapping_List[i1].y - Mapping_List[i].y;

Tangent_List[i] = (vec1 * d_u1) - (vec2 * d_u2);

Tangent_List[i].Normalize();
Tangent_List[i1] = Tangent_List[i];
Tangent_List[i2] = Tangent_List[i];
``````
``````  Binormal_List[i]  = Normal_List[i].CrossProduct(Tangent_List[i]);
Binormal_List[i1] = Normal_List[i1].CrossProduct(Tangent_List[i1]);
Binormal_List[i2] = Normal_List[i2].CrossProduct(Tangent_List[i2]);
}
``````

But when Rendering, the bumped object (sphere cylinder torus etc…) doesn’t look weel.
Someplaces bump is inverted…

How must it be done?

Suggestions Are welcome.
Thanks.

You can get inverted bumps if the texture mapping is mirrored. Either use the +3 Knobbly Stick Of Artist Enlightenment, or a tool like NVMeshMender to patch it up. Or generate a texture atlas for your normal maps, rather than re-using texure coordinates.

This can be a difficult calculation if you’re not thinking about the problem in the right way. See Section 6.8 of my book, Mathematics for 3D Game Programming and Computer Graphics for a good explanation of how to do this.

I’ve tried a number of ways and I end up using the one in Eric’s book. By far the best and robust of all the onces I tried.

Also remember to take UV discontinuitise, material, and smoothing groups into mind when averaging.

Also a re-orthogonalization of the basis is good after the averaging.

If I remember correctly, all this is mentioned in his book, highly recommended.

Chris