# is this a correct tangent computation?

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

## Recommended Posts



// PREPARE, for 3 vertices (a triangle)
float3 v1 = vertex2.xyz - vertex0.xyz;
float3 v2 = vertex2.xyz - vertex1.xyz;
float2 st1 = vertex2.st - vertex0.st;
float2 st2 = vertex2.st - vertex1.st

// now the magic
//     generateNormalAndTangent(float3 v1, float3 v2, text2 st1, text2 st2)

float3 normal = v1.crossProduct(v2);

float coef = 1/ (st1.u * st2.v - st2.u * st1.v);
float3 tangent;

tangent.x = coef * ((v1.x * st2.v) + (v2.x * -st1.v));
tangent.y = coef * ((v1.y * st2.v) + (v2.y * -st1.v));
tangent.z = coef * ((v1.z * st2.v) + (v2.z * -st1.v));

normal.normalize();
tangent.normalize()
// TODO: is the per-face tangent value valid here???


is this code calculating a valid per-face tangent vector?

##### Share on other sites

You are not calculating handedness:

const Vec3 cp = Vec3::Cross( normal, Vec3( tangent.x, tangent.y, tangent.z ) );
tangent.w = Vec3::Dot( cp, bitangents[v] ) >= 0.0f ? 1.0f : -1.0f;



1. 1
2. 2
Rutin
20
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013614
×