Skip to main content
gamedev.net
🔒 Locked

tangent, binormal...

Started by Thaligar Aug 22, 2005 at 6:44 AM 14 replies 1.4k views
Original Post
Thaligar
Thaligar
hi, i surfed now for couple of hours in the net because i wanna know how to calculate the tangent of a vertex, i already (took a long time) that the binormal/bitangent is the dotprod of the normal and the tangent, but how can i calc the tangent? if anyone got good tutorials or websites to look at please post, thanks in advance for your help and time, greets tgar
krum
krum
I think the binormal is the cross product of the tangent and the normal (not the dot product). The tangent can be computed as a function of the texture coordinates, but depending on what you're doing there's other ways of computing it (such as with terrain).
Richy2k
Richy2k
First off, its actually tangent, and bitangent to be totally correct, although it doesn't really matter as long as you do the same thing. A face normal is the cross product of the tangent, and bitangent. I believe in terms for normal mapping, you want the tangent to follow one axis, ie - X, and the bitangent to follow the other - Y or Z depending on the system you chose. Best wait till someone with a bit more mathematical knowledge comes along unless you are satisfied with my answer.
Thaligar
Thaligar
sorry, my fault, yes it is the cross prod [oh]

thanks for the replies,

greets
tgar
Staffan E
Staffan E
Quote:
Original post by Richy2k
Heres a picture I drew to help visualise it:

That's a great explanatory picture Richy. Most people have trouble drawing 3d directions and lines but I see you don't. [smile]
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Richy2k
Richy2k
Quote:
Original post by staaf
Quote:
Original post by Richy2k
Heres a picture I drew to help visualise it:

That's a great explanatory picture Richy. Most people have trouble drawing 3d directions and lines but I see you don't. [smile]


Was that sarcasm or were you actually being honest? I would have mocked up a model in Blender but it would have taken longer, besides my picture is accurate enough to a degree...

Addition: This topic could really go nicely as an article, a lovely article on normals, tangents, bitangents, etc, to answer all the nitty gritty 3D maths questions.

PS: Yes I know there is an article on height map normal calculation, but thats just one small thing that it covers.
Staffan E
Staffan E
Quote:
Original post by Richy2k
Quote:

Was that sarcasm or were you actually being honest? I would have mocked up a model in Blender but it would have taken longer, besides my picture is accurate enough to a degree...

I was being honest. I see a lot of geometry-related figures drawn by other students and most are less than intelligible unless you get them explained to you. Drawing geometry by hand is a rare trait it seems.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Basiror
Basiror
seeing the picture from richy2k couldn t you simply generate the binormal(bitangent) and tangent by rotating the base axis vectors accordingly?

you have got the normal


now find out the dominant axis component

x > y and x > z -> dominat axis is the x axis

so find the angles you need to rotate the x axis vector to match the normal and apply these rotations to the y and z axis vectors

any idea if that would work ?
http://www.8ung.at/basiror/theironcross.html
Illco
Illco
Yes. It won't because it doesn't uniquely define the resulting vectors. Imagine the X vector matching an upward normal vector N. Now we could rotate the whole system around the axis N (or X transformed). With your approach any rotation would be valid while the tangent and bitangent should point in the direction (derivative/curvature) of the surface at said point.

Illco
Basiror
Basiror
i think i understood the concept behind the TBN now
(after having a look into the terathon code)
you have got a triangle and the triangles texture coordinates

and with the help of the texture coordinates you can scale the components

i have drawn it onto paper

v1---v2
|---/
|--/
|-/
|/
v3
basically you have 4 space equations

x1 = v2 - v1
x2 = v3 - v1

s1 = tex2.s - tex1.s
s2 = tex3.s - tex1.s

t1 = tex2.t - tex1.t
t2 = tex3.t - tex1.t


sdir.x = (t2 * x1 - t1 * x2)/(s1 * t2 - s2 * t1)

which is the same as
|x1 t1| /|s1 t1|
|x2 t2|/ |s2 t2|

seeing this you set the x components of the worldspace edges in relation to the x components of the texture coordinates

doing this for each axis will result in a perfect tangent

try it with tex coords
v1(0,0) st1(0,0)
v2(0,1) st2(0,1)
v3(1,0) st3(1,0)

will result in 1 for the x component of the tangent

ok i did some further research about the 2d cross products over there



if you have 2 2d direction vectors a and b
then the cross product of these 2 vectors
|a.x b.x|
|a.y b.y|
is the sinus angle between these two vectors
now taking a 2d rotation matrix
|cos 0|
|0 sin|

now back to these cross products
|x1 t1| /|s1 t1|
|x2 t2|/ |s2 t2|

what you basically do is you set the angles into relation to each other thus you perform a simple rotation hidden behind a lot of freaking math


[Edited by - Basiror on August 22, 2005 4:41:15 PM]
http://www.8ung.at/basiror/theironcross.html
Thaligar
Thaligar
thanks alot,

these pictures opened my eyes,
now it's alot simpler,

thx again,
greets
tgar
Basiror
Basiror
yeah maybe someone could write an article about it
last time i searched for some reference about this topic all i found as the terathon link posted above
http://www.8ung.at/basiror/theironcross.html
Richy2k
Richy2k
When I buck up at bit of vectors, matrices, and all the maths stuff in general i'm willing to start on an article, I don't wanna write an article on a topic I could learn a bit more about first.
Basiror
Basiror
here is a tutorial i found
you find the tangent of a surface by finding the increasing s direction

http://www.opengl.org/resources/tutorials/advanced/advanced98/notes/node108.html#SECTION000105100000000000000
http://www.8ung.at/basiror/theironcross.html

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.