Page 1 of 1

Problem with TangentSpace (Tangent & Binormal calculatio

Posted: Wed May 10, 2006 10:45 am
by chromdragon
I have problems with calculating the tangent and binormal (bitangent) vector!

Can any body help me pls!

:: IMG WITH MY PROBLEM ::
Image

:: REFERENCES ::
Engine: Irrlicht
http://irrlicht.sourceforge.net/

Bump Mapping Using CG (3rd Edition)
http://www.blacksmith-studios.dk/projec ... ing_cg.php

Derivation of the Tangent Space Matrix
http://www.blacksmith-studios.dk/projec ... vation.php

:: CODE ::

Code: Select all

core::vector3df& normal,
core::vector3df& tangent,
core::vector3df& binormal,
core::vector3df& vt1, core::vector3df& vt2, core::vector3df& vt3 // vertices
core::vector2df& tc1, core::vector2df& tc2, core::vector2df& tc3 // texture coords

#ifdef USE_BOGDAN_VERSION

normal.set(0,0,0);
tangent.set(0,0,0);
binormal.set(0,0,0);

// normal
core::vector3df v1 = vt1 - vt2;
core::vector3df v2 = vt3 - vt1;
normal = v2.crossProduct(v1);
normal.normalize();

// tangent & binormal
core::vector3df deltaV2V1 = vt2 - vt1;
core::vector3df deltaV3V1 = vt3 - vt1;
f32 deltaC2C1T = tc2.X - tc1.X;
f32 deltaC2C1B = tc2.Y - tc1.Y;
f32 deltaC3C1T = tc3.X - tc1.X;
f32 deltaC3C1B = tc3.Y - tc1.Y;
f32 mTex = 1.0f / (deltaC2C1T*deltaC3C1B - deltaC3C1T*deltaC2C1B);

tangent = (deltaV2V1 * deltaC3C1B - deltaV3V1 * deltaC2C1B) * mTex;
tangent.normalize();

binormal = (deltaV2V1 * deltaC3C1T * -1.0f + deltaV3V1 * deltaC2C1T) * mTex;
binormal.normalize();

#endif // USE_BOGDAN_VERSION

Posted: Mon May 15, 2006 5:44 pm
by WhiteNoise
I can't see what the problem is from that picture. Also, what's wrong with Irrlicht's binormal computation?

Posted: Tue May 23, 2006 12:43 pm
by chromdragon
Is anyone who had correct calculated the normal/tangent/bitagent for TangetSpace? (normal-maps generated but ATI NormalMapper or NVIDIA Melody)

Computing tangents on GameDev

Posted: Tue May 23, 2006 2:34 pm
by needforhint
cool link , thanks....