TBN vectors

How do you create TBN matrix polysoup. I know that T and B vectors follow s and t coordinats but I realy dont know how to calculate them. I’ve searched some forums and google but I only found info how to calculate T and B for simple objects like cubes and spheres. Any (pseudo)code would be very usefull.

If you have a procedural model (a sphere, a torus…) then the TNB triplet is pretty obvious. That’s why you’ve found so many info on them over the Internet.

If you’re looking for the TNB triplet for bump-mapping, then all you can select whatever Tangent and Binormal you like once you have the Normal.

Compute a (first) vector - the Tangent - orthogonal to the Normal. You can use the equation : dot_product(T,N)=0
There is an infinite number of vectors that solves the quation. Choose whichever you like.

Then compute a (second) vector - the Binormal - orthogonal to the Normal and orthogonal to the Tangent. Given a Normal and a Tangent, there is a unique Binormal vector. It can be computed as the cross product between the Normal and the Tangent : B=cross_product(N,T)

Additional Information
Even though there exists an infinite number of triplets TNB (for a given Normal), I recommend you to select a Tangent that has some kind of organization. If words like “up/down”, “left/right” or "cw/ccw’ (not for backface culling this time!) has some meaning to your model, then it’s better to use them.
For instance, you may want to have all your tangents facing “upwards”, or “in clockwise direction relatively to the vertical axis”.

Hope this helps, and I hope I’m clear !

Thanks. That’s what I’m doing now. But when I read nVidias papers on this they said T and B must follow texture mapping coordinats but I dind’t know how to calculate them. The problem with this aproach is that scene looks diferent if I change T (and B). Does anyone else has opinion on this?

I’m sorry but I can’t figure why your scene looks different.
Also, does it look really different, or just a bit ?

Maybe you should post in another forum. You won’t get much answers in the OpenGL.org beginners forum. Perhaps try the advanced forum ?

I think I got this sloved. It look OK except in some cases with animated meshes… If I can’t get this bug out then I’ll try asking in the advanced forum…