🔒 Locked
tangent, binormal...
Advertisement
Original Post
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
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.
Heres a picture I drew to help visualise it:

And here is a link with some better pics explaining it:
http://www.paulsprojects.net/tutorials/simplebump/simplebump.html

And here is a link with some better pics explaining it:
http://www.paulsprojects.net/tutorials/simplebump/simplebump.html
http://www.terathon.com/code/tangent.html
That has some good code for calculating a tangent/bitangent as well
That has some good code for calculating a tangent/bitangent as well
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.
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.
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 ?
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 ?
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
Illco
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]
(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]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement