Jump to content
  • Advertisement
Sign in to follow this  

is this a correct tangent computation?

This topic is 1597 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

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;

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!