• Advertisement
Sign in to follow this  

is this a correct tangent computation?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

please take a look:

// 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));
// TODO: is the per-face tangent value valid here???

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

Edited by fread

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement