# why scale the tangent vector

## Recommended Posts

In his book Eric Lengyel computes the tangent space vector for a face with vertices A,B,and C as such:
//computing face tangent
float s1 = B.fU1 - A.fU1;
float s2 = C.fU1 - A.fU1;
float t1 = B.fV1 - A.fV1;
float t2 = C.fV1 - A.fV1;
float scale = 1/(s1*t2 - s2*t1);
D3DXVECTOR3 P, Q, tangent_result;
P.x = B.fX - A.fX;
P.y = B.fY - A.fY;
P.z = B.fZ - A.fZ;
Q.x = C.fX - A.fX;
Q.y = C.fY - A.fY;
Q.z = C.fZ - A.fZ;
tangent_result = scale*t2*P - scale*t1*Q;


My question is, what need is there for scale if you are going to normalize the tangent anyways?

##### Share on other sites
Lets assume two faces affect the same vertex. For clarity, one face will have the tangent 1,0,0. The next will have the tangent 0,1,0.

Unscaled add: (scale 1, and 1)
1,1,0, or 0.707, 0.707, 0 normalized

One of an infinite set of possible scaled adds: (scales 0.5, and 1)
0.5, 1, 0, which != 0.707, 0.707, 0 normalized.

##### Share on other sites
Ah so I leave the face tangents scaled and unnormalized, and once I have computed per vertex tangents normalize those?

[Edited by - Khaos Dragon on May 24, 2005 11:12:41 PM]

##### Share on other sites
No! That will get you into trouble.
It's the other way around, normalize face normals, leave the summed vertex normals (if you're normalizing the in a pixel shader or so).

Consider:

Unscaled face normal A(1, 0, 0) and B(0, 1, 0)

Vertex normal C = A + B = (1, 1, 0)

Pixel shader normalized normal = (0.707, 0.707, 0) = Correct.

Unscaled face normal A(8, 0, 0) and B(0, 2, 0) <= Note these normals are oriented in exactly the same way as the previous example, thus the results in the pixel shader should be the same, or?

Vertex normal C = A + B = (8, 2, 0)

Pixel shader normalized normal = (0.970, 0.243, 0) = Wrong!

You also assumes that every face normal constibutes equally to the vertex normal.
This assumption doesn't work very well in practice, some sort of weighting is necessary.

Some uses the area of the triangle as a contribution weight, I prefere to use the angle.

Consider these triangles:
   0-----------1  /| \         | / |   \  A    |4 C|     \     | \ |  B    \   |  \|         \ |   2-----------3

A's normalized normal is (0, 0, 1)
B's normalized normal is (0, 0, 1)
C's normalized normal is (-1, 0, 0)

Without weighting:
The normal for vertex 0 is: A + B + C = (-1, 0, 2) = (-0.44, 0, 0.89)
Since A and B are having the same normal, vertex 2's normal should be the same as vertex 0.
Using the equal weight for each face normal we get:
The normal for vertex 2 is: B + C = (-1, 0, 1) = (-0.71, 0, 0.71). Not the same!

With edge angle weighting:
Using the angles instead, for vertex 0 we get:
WeightA0 = angle(Edge10, Edge30) = 45
WeightB0 = angle(Edge30, Edge20) = 45
WeightC0 = angle(Edge40, Edge20) = 45

VertexNormal0 = (NormalA * WeightA0 + NormalB * WeightB0 * NormalC * WeightC0) = (-45, 0, 90) = (-0.45, 0, 0.89).

For vertex 1:

WeightB2 = angle(Edge02, Edge32) = 90
WeightC2 = angle(Edge42, Edge02) = 45

VertexNormal1 = (NormalB * WeightB2 * NormalC * WeightC2) = (-45, 0, 90) = (-0.45, 0, 0.89).

We get the same normal for vertex 0 and 2 as expected!

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627689
• Total Posts
2978646

• 13
• 14
• 12
• 10
• 12