Problem with TangentSpace (Tangent & Binormal calculatio
Posted: Wed May 10, 2006 10:45 am
I have problems with calculating the tangent and binormal (bitangent) vector!
Can any body help me pls!
:: IMG WITH MY PROBLEM ::
:: 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 ::
Can any body help me pls!
:: IMG WITH MY PROBLEM ::
:: 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