Sign in to follow this  
Dragon_Strike

tangents from normals

Recommended Posts

all the information ive found regarding tangents have always been calculating them from vertex and texture coordinates.. but wouldnt it be simpler to calculate the tangents from allrdy calculated normals? and if so how would u do that?

Share this post


Link to post
Share on other sites
Calculating the normals is the first thing you do, but you need more than normals to calculate the tangents and bitangents. The thing is, for a given normal there are an infinite number of potential tangent/bitangent pairs. The normal way to decide what to use as the "real" tangent and bitangent is to put the tangent along the texture coordinates' X direction, and the bitangent as the cross product of the normal and the tangent. This isn't a hard and fast rule, though.

Share this post


Link to post
Share on other sites
so basicly u can calculate the tangent as a normalized vector starting at the vertex and pointing towards the u coordinate? i find that a bit weird... shouldnt the tangent be perpendicular to the normal? does anyone please explain to me exactly what a tangent is... cuzz i get more confused the more i learn...

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
so basicly u can calculate the tangent as a normalized vector starting at the vertex and pointing towards the u coordinate? i find that a bit weird... shouldnt the tangent be perpendicular to the normal?


Yeah. This is not a problem; since the normal is perpendicular to the surface (by definition), the tangent computed in this way will be perpendicular to the normal (since it's coplanar to the surface).

Share this post


Link to post
Share on other sites
I don't understand your question. You could calculate the bitangent from the tangent and normal by rotating about the normal 90 degrees from the tangent.

A similar solution would just be to calculate the cross product of the normalized vectors. This should be more efficient than a mat3 multiply (for a rotation) - if the vectors are normalized.

Share this post


Link to post
Share on other sites
Quote:
Original post by talas
I don't understand your question. You could calculate the bitangent from the tangent and normal by rotating about the normal 90 degrees from the tangent.

A similar solution would just be to calculate the cross product of the normalized vectors. This should be more efficient than a mat3 multiply (for a rotation) - if the vectors are normalized.


my question is how can u easily calculate the tangent from the normal

Share this post


Link to post
Share on other sites
The tangent and bitangent (also called binormal) vectors that are most useful are those that align with the U and V texture directions. Without knowing U and V coordinates of a given vertex and its neighbors, you can't easily compute those vectors (note that the computation of these vectors, as already suggested, doesn't actually require use of the normal at all).

Trying to do something like "rotate the normal 90 degrees in the direction of the U texture coordinate" is pointless because if you can do it, you already have your answers. You'd have to know which axis to rotate the normal around -- it would be the axis form by the 'direction' of the V texture coordinate -- and if you have that axis, you already have the bitangent, and since you have two of the vectors, you can find the third with a cross product trivially. Not to mention the fact that what you mean by "direction" of the texture coordinate is the vector (in texcoord space) from the current vertex's U to an adajecent vertex's U, which is exactly the result you're looking for anyway.

If you just have the normal, you can find two other vectors that form an orthogonal basis with the normal, but they won't neccessarily be the aforemention most-useful tangent and bitangent. In fact, since there are an infinite number of tangent vectors, you're pretty much guaranteed they won't be the most-useful ones.

To put it simply, you can't simply find the tangent that you probably want from just the normal. Computing them from texture coordinates of the current vertex and neighboring vertices is the way you want to go.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
The tangent and bitangent (also called binormal) vectors that are most useful are those that align with the U and V texture directions. Without knowing U and V coordinates of a given vertex and its neighbors, you can't easily compute those vectors (note that the computation of these vectors, as already suggested, doesn't actually require use of the normal at all).

Trying to do something like "rotate the normal 90 degrees in the direction of the U texture coordinate" is pointless because if you can do it, you already have your answers. You'd have to know which axis to rotate the normal around -- it would be the axis form by the 'direction' of the V texture coordinate -- and if you have that axis, you already have the bitangent, and since you have two of the vectors, you can find the third with a cross product trivially. Not to mention the fact that what you mean by "direction" of the texture coordinate is the vector (in texcoord space) from the current vertex's U to an adajecent vertex's U, which is exactly the result you're looking for anyway.

If you just have the normal, you can find two other vectors that form an orthogonal basis with the normal, but they won't neccessarily be the aforemention most-useful tangent and bitangent. In fact, since there are an infinite number of tangent vectors, you're pretty much guaranteed they won't be the most-useful ones.

To put it simply, you can't simply find the tangent that you probably want from just the normal. Computing them from texture coordinates of the current vertex and neighboring vertices is the way you want to go.


couldnt ask for a better answer.. thank u

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
The tangent and bitangent (also called binormal) vectors that are most useful are those that align with the U and V texture directions.

Careful there. Although the tangent DOES usually align with the U axis, the bitangent often doesn't align with the V axis. This is because having the normal/tangent/bitangent form an orthonormal basis is much more important than pointing straight down the V axis. One figures out the normal and tangent, and then bases the bitangent off those, with no regards to any shear that might be going on with the U/V axes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Careful there. Although the tangent DOES usually align with the U axis, the bitangent often doesn't align with the V axis. This is because having the normal/tangent/bitangent form an orthonormal basis is much more important than pointing straight down the V axis. One figures out the normal and tangent, and then bases the bitangent off those, with no regards to any shear that might be going on with the U/V axes.


Actually you don't need to align anything really. What's more important is to use the same exact space for encoding (typically during the export process of a mesh) and decoding (in-game on the GPU).

Another concern is to avoid sharp rotation of this space because it is usually interpolated (in the GPU for instance).

Share this post


Link to post
Share on other sites
Quote:

Careful there. Although the tangent DOES usually align with the U axis, the bitangent often doesn't align with the V axis. This is because having the normal/tangent/bitangent form an orthonormal basis is much more important than pointing straight down the V axis. One figures out the normal and tangent, and then bases the bitangent off those, with no regards to any shear that might be going on with the U/V axes.


Oops. You're complete right, that was a poor assumption on my part (I kept visualizing right triangles whose legs were the U and V directions!).

Share this post


Link to post
Share on other sites
well the real thought for this question was for loading 3d models.. when u load a model from file u usually only get the normals, not the tangents.. as far as ive understood at least.. but how u get the tangents then? its seems to me a bit excessive to have complicated tangent calculation for every vertex every time u want to load a model...

Share this post


Link to post
Share on other sites
Well this is normally what you have to do, load a model, and call a compute tangent function. If you use D3D there is a simple function for doing this, and it is very fast, not fast enough to be recomputed every frame perhaps, but this not needed of course. Only run it once when you create the mesh.

It would be useful if the tangent could be calculated in a vertex shader however. Anyone have any thoughts?

Share this post


Link to post
Share on other sites
http://nwn2forums.bioware.com/forums/viewpost.html?topic=524659&post=4569982&forum=115&highlight=

I was able to put the algorithm to get the tangent and binormal using what was posted here in my own model exporter program. Seems to be exactly what you're looking for.

In this algorithm, though, he finds the tangent and binormal for each face. In my program I then took those and used the normal for each of the three verticies to make them appropriate for the verticies of the face.

[Edited by - Kimani on December 15, 2006 2:25:37 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kimani
http://nwn2forums.bioware.com/forums/viewpost.html?topic=524659&post=4569982&forum=115&highlight=

I was able to put the algorithm to get the tangent and binormal using what was posted here in my own model exporter program. Seems to be exactly what you're looking for.

In this algorithm, though, he finds the tangent and binormal for each face. In my program I then took those and used the normal for each of the three verticies to make them appropriate for the verticies of the face.


first of all i dont rly get how to rewrite that to vertex... secondly... when u load a model the vertex coordsniates are put into an array... but that doesnt say anything about which vertexes u need to be able to calculate the tangent...

does lib3ds have some kind of function for calculating tangents also?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kimani
http://nwn2forums.bioware.com/forums/viewpost.html?topic=524659&post=4569982&forum=115&highlight=

I was able to put the algorithm to get the tangent and binormal using what was posted here in my own model exporter program. Seems to be exactly what you're looking for.

In this algorithm, though, he finds the tangent and binormal for each face. In my program I then took those and used the normal for each of the three verticies to make them appropriate for the verticies of the face.


thx.. but aths jsut to many files and code for me to read, understand and rewrite..

Share this post


Link to post
Share on other sites
You need to use all the vertices to calculate the tangents... Why? Because you need to use them to find the normals. Then you use the normals and texCoords to find the tangent or bitangent and then do a cross product on tangent or bitangent and you find the other one. With a model you can just use the index order to find your normals and tangents. AKA Index buffer that you would setup for a VBO use the ordering that is loaded to that for determining your order of operations.

BTW Binormal isn't the correct term when used with bumpmapping per Eric L. It's bitangent... Now I duck and run...

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
You need to use all the vertices to calculate the tangents... Why? Because you need to use them to find the normals. Then you use the normals and texCoords to find the tangent or bitangent and then do a cross product on tangent or bitangent and you find the other one. With a model you can just use the index order to find your normals and tangents. AKA Index buffer that you would setup for a VBO use the ordering that is loaded to that for determining your order of operations.

BTW Binormal isn't the correct term when used with bumpmapping per Eric L. It's bitangent... Now I duck and run...


sigh.. well yea.. thx for all the good answers... even though i havent been able to actually solve my problem... i wish opengl had the same feature as D3D with the automatic calculations...

but i havent even been able to load a model yet... lib3ds gives givin me errors.. ive been tryin to solve the past 3 days without success...

but back to the tangents... u said i just use the order of the index buffer.. but the problem is that i dont know which vertices are neighbors just from the index buffer... thus i dont know which vertices IN the index buffer 2 use in the calculations i dont know how to do... lol


Share this post


Link to post
Share on other sites
Actually, the order of indices gives you enough information to extract the neighbors of a vertex (per face). Lets take an index buffer containing triangle primitives for example (no fans nor strips). Then each pair of three indices determines exactly one triangle, and neighbors are easily identified:

IB = ( 0, 1, 2, 0, 2, 3, ... )

T1 = ( 0, 1, 2 ), T2 = ( 0, 2, 3 ), ...

neighbors of V0 in T1 = { V1, V2 }
neighbors of V1 in T1 = { V2, V0 }
neighbors of V0 in T2 = { V2, V3 }
...

I guess you already know this, maybe I didn't understand your question.

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
BTW Binormal isn't the correct term when used with bumpmapping per Eric L. It's bitangent... Now I duck and run...


I'll cover you... A curved line in 3D has one tangent and two normals (normal and binormal), but a curved surface in 3D has two tangents (tangent and bitangent) and one normal.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Actually a curve in 3-space has infinitely many normals and a surface in 3-space has infinitely many tangents. But I know what you meant.

Share this post


Link to post
Share on other sites
"binormal" is not only acceptable, it's used as a standard. Using both terms is confusing. Plus "bitangent" doesnt read well, it looks like "bit-tangent".

The same things go for "fragment program".. I hate that term, because its meaningless. What is a fragment really? Where in the pipeline do you ever deal in fragments? Never. Use "pixel shader".

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
The same things go for "fragment program".. I hate that term, because its meaningless. What is a fragment really? Where in the pipeline do you ever deal in fragments? Never. Use "pixel shader".


There can be multiple fragments per pixel for supersampling, so it's actually a more accurate name than pixel shader. Maybe you should stop venting about duplicate names (plenty of things have 2 or 3 names) and find something useful to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
"binormal" is not only acceptable, it's used as a standard. Using both terms is confusing. Plus "bitangent" doesnt read well, it looks like "bit-tangent".

The same things go for "fragment program".. I hate that term, because its meaningless. What is a fragment really? Where in the pipeline do you ever deal in fragments? Never. Use "pixel shader".


You know, you're absolutely correct. Why should we use the proper terms for concepts? I can't think of a single reason for it...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this