# Vertex Tangent - Transformation in left hand coordinates?

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

## Recommended Posts

I'm working in left handed corrdinates and calculating the tangent to do normal mapping transforming lights to tangent space The result is working wrong as it seems that one axis is flipped (the left side of a mesh is being iluminated as should be the right side). So I am guessing that I have a mix with the coordinate system in calculating the tangent for the vertex or in the tangent trasnformation matrix. 1) Calculate tangent in left handed coordinates?
VECTOR3 GetTangentSpaceVector( const VECTOR3& position1, const VECTOR3& position2, const VECTOR3& position3,
const VECTOR2& uv1, const VECTOR2& uv2, const VECTOR2& uv3)
{
/// Calculate face normal
/// side0 is the vector along one side of the triangle of vertices passed in,
/// and side1 is the vector along another side. Taking the cross product of these returns the normal.
VECTOR3 side0 = position1 - position2;
VECTOR3 side1 = position3 - position1;
VECTOR3 normal = side1.Cross(side0);
normal.Normalize();

/// Calculate the tangent (UV space)
float deltaV0 = uv1.v - uv2.v;
float deltaV1 = uv3.v - uv1.v;
VECTOR3 tangent = deltaV1 * side0 - deltaV0 * side1;
tangent.Normalize();

/// Calculate binormal (UV Space)
float deltaU0 = uv1.u - uv2.u;
float deltaU1 = uv3.u - uv1.u;
VECTOR3 binormal = deltaU1 * side0 - deltaU0 * side1;
binormal.Normalize();

///Now, take the cross product of the tangents to get a vector which
///should point in the same direction as our normal calculated above.
///If it points in the opposite direction (the dot product between the normals is less than zero),
///then we need to reverse the s and t tangents.
///This is because the triangle has been mirrored when going from tangent space to object space.
///reverse tangents if necessary
VECTOR3 tangentCross = tangent.Cross(binormal);
if (tangentCross.Dot(normal) &lt; 0.0f)
{
tangent = -1.0f * tangent;
binormal = -1.0f * binormal;
}

return tangent;
}

2) Tangent transformation for left handed?
float3x3 worldToTangent;

worldToTangent[0] = normalize(mul (IN.tangent, matWorld));

worldToTangent[1] = normalize(mul (cross(IN.tangent, IN.normal),matWorld));

worldToTangent[2] = normalize(mul (IN.normal, matWorld));
EDIT: Using [ source ] and [ code ] tags makes your code a bit easier to read. [Edited by - jollyjeffers on January 21, 2006 6:23:41 AM]

##### Share on other sites
In a left handed system where you have clockwise winding for vertices, to calculate the normal yourself from a face with vertices A, B, and C:

D3DXVECTOR3 V1 = B - A;
D3DXVECTOR3 V2 = C - B;

D3DXVECTOR3 normal;
D3DXVec3Cross(&normal, &V1, &V2);

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009326
• ### Who's Online (See full list)

There are no registered users currently online

×