Jump to content

  • Log In with Google      Sign In   
  • Create Account


normals in tangent space question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 lomateron   Members   -  Reputation: 300

Like
0Likes
Like

Posted 04 May 2013 - 06:19 PM

when blender makes the normals in tangent space it has to use 3 direction vectors, one is the normal of a face, the other is vector "b" and the other is the cross between this two vectors.

What is vector "b"?


Edited by lomateron, 04 May 2013 - 08:56 PM.


Sponsor:

#2 RobTheBloke   Crossbones+   -  Reputation: 2295

Like
0Likes
Like

Posted 04 May 2013 - 06:59 PM

you don't make normals in tangent space, you just make normals. The tangent, bi-normal, and normal, make up the TBN 3x3 rotation matrix which is used to transform light rays into the coordinate system of your texture. The tangent & bi-normal therefore represent the u & v directions of your texture (which you can deduce by inspecting the texture coordinates). 



#3 lomateron   Members   -  Reputation: 300

Like
0Likes
Like

Posted 04 May 2013 - 07:25 PM

"you don't make normals in tangent space, you just make normals"

blender produces normals in tangent space, no?

 

"u & v"

What is that?

 

Apart from that:

 

when blender makes the normals in tangent space it has to use 3 direction vectors, one is the normal of a face, the other is vector "b" and the other is the cross between this two vectors.

What is vector "b"?


Edited by lomateron, 04 May 2013 - 08:56 PM.


#4 Bacterius   Crossbones+   -  Reputation: 8133

Like
2Likes
Like

Posted 04 May 2013 - 09:50 PM

"b" is the bitangent. It describes, loosely, the "orientation" of the object about the normal vector, and generally is derived from the u-v coordinates, as the bitangent is used for texture mapping and anisotropic shading.

 

In tangent space, the normal is equal to (0, 1, 0) or (0, 0, 1) depending on what your up-axis is, by definition.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#5 lomateron   Members   -  Reputation: 300

Like
1Likes
Like

Posted 04 May 2013 - 10:51 PM

"derived from the u-v coordinates"

how exactly is the bitangent direction derived?



#6 Eric Lengyel   Crossbones+   -  Reputation: 2173

Like
1Likes
Like

Posted 04 May 2013 - 11:32 PM

The tangent and bitangent are derived using a calculation like this:

 

http://www.terathon.com/code/tangent.html



#7 Bacterius   Crossbones+   -  Reputation: 8133

Like
1Likes
Like

Posted 04 May 2013 - 11:34 PM

"derived from the u-v coordinates"

how exactly is the bitangent direction derived?

 

The u-v coordinates basically map a vertex (in 3D space) to a 2D texture coordinate, right? The u-coordinate corresponds to the horizontal texture coordinate and the v-coordinate corresponds to the vertical coordinate (in fact, u-v are typically called "texcoords"). So now you can work out the tangent and bitangent vectors by taking the difference in texcoords between neighbouring vertices (interpolated to give per-face TBN matrices, of course).

 

EDIT: Eric above gives the complete derivation - ninja'ed? :P


Edited by Bacterius, 04 May 2013 - 11:34 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#8 0r0d   Members   -  Reputation: 797

Like
0Likes
Like

Posted 04 May 2013 - 11:57 PM

when blender makes the normals in tangent space it has to use 3 direction vectors, one is the normal of a face, the other is vector "b" and the other is the cross between this two vectors.

What is vector "b"?

"b" refers to the binormal.

 

In tangent space calculations you have the Normal, Tangent, and Binormal.  These 3 normalized vectors represent the basis vectors of the tangent space, which BTW is not necessarily an orthogonal space.  These vectors are in object space, and the 3x3 matrix generated from them represents the transformation from object space to "tangent" space.

 

The normal is the vector pointing directly away from the surface.  This is calculated from the vertex positions and has nothing to do with the UV coordinates.  The tangent vector points along the direction of change of the U coordinates.  The binormal points along the direction of change of the V coordinates.

 

if the UV coordinates are orthogonal, then you can calculate the binormal like this:

 

B = T x N

 

Sometimes in games, inside the shaders, the binormals are calculated this way.  But, again, this only works if the U and V coordinates are orthogonal, which they're not guaranteed to be.  It's very easy for artists to make the texture coordinates flow however they want.  The general solution is to pass in all three, N, T, and B in the vertex to the vertex shader.


Edited by 0r0d, 05 May 2013 - 12:00 AM.


#9 lomateron   Members   -  Reputation: 300

Like
0Likes
Like

Posted 05 May 2013 - 01:57 AM

I can't understand

 

What I thought when I just hear about tangent space normals was this:

 

normal:::> is just the simple normal of the face

binormal":::> is the direction<<if i have 3 vertices positions(in world space) for a face>>:  normalize(vertice2 - vertice1)

tangent:::>cross(normal, binormal)or the other way cross(binormal, normal)...i don't know

 

wouldn't this be much simpler?

 

so with this 3 vectors I just build a 3x3matrix multiply it by the normal of the texture and finally get the normals in world space

//-----------------------------------------------------------------------------------

this is my new question

 

I want to tranform this tangent normals of the texture to world space

I have three vectors in world space that  represent a face of the object i am drawing

I just need a 3x3 matrix to rotate this tangent normals of the texture

the last vector of the matrix is the normal of the face: normalize(cross(v1-v0,v2-v0))

the middle vector will be what?

the first vector will be: cross(last vector,middle vector)


Edited by lomateron, 05 May 2013 - 04:22 AM.


#10 Bacterius   Crossbones+   -  Reputation: 8133

Like
1Likes
Like

Posted 05 May 2013 - 03:42 AM

What I thought when I just hear about tangent space normals was this:
 
normal:::> is just the simple normal of the face
binormal":::> is the direction<>:  normalize(vertice2 - vertice1)
tangent:::>cross(normal, binormal)or the other way cross(binormal, normal)...i don't know
 
wouldn't this be much simpler?

 

But this vector doesn't have any use. The point of bitangents is to create a TBN matrix (tangent bitangent normal) which is used for normal mapping, bump mapping, etc.. because the normal isn't enough. We also need to know the "rotation" of the texture at the given vertex/pixel to map it properly. This is why we need a bitangent coming from the texture coordinates. The direction of the vertex doesn't have any relation to that, it's for all intents and purposes random (and may not be coherent from vertex to vertex).


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#11 lomateron   Members   -  Reputation: 300

Like
0Likes
Like

Posted 05 May 2013 - 04:30 AM

this is my new question

 

I want to tranform the tangent normals of the texture to world space

I have three vectors in world space that represent a face of the object i am drawing

I will need a 3x3 matrix to rotate this tangent normals

the last vector of the matrix will be the normal of the face: normalize(cross(v1-v0,v2-v0))

the first vector of the matrix will be: cross(last vector,middle vector)

the middle vector of the matrix will be what?



#12 Bacterius   Crossbones+   -  Reputation: 8133

Like
1Likes
Like

Posted 05 May 2013 - 04:35 AM

the middle vector of the matrix will be what?

 

The bitangent smile.png but that matrix is incorrect either way.

 

The "normal" way (no pun intended) to generate this matrix is to know the face or vertex normal in advance from the model (though you can calculate it from the vertices if you want) as well as the bitangent, and compute the missing vector by crossing the two and possibly flipping the sign of the resulting vector depending on your coordinate system. And, no, you can't make both vectors up, if you need the correct TBN matrix (not just the normal) then you need to obtain the bitangent somehow and that is from the model's u-v coordinates or other equivalent source as linked above.

 

As your matrix is now it has zero information about the actual texture of the object, so it can't possibly be a texture space to world space matrix. You see the problem?


Edited by Bacterius, 05 May 2013 - 04:39 AM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#13 Bacterius   Crossbones+   -  Reputation: 8133

Like
2Likes
Like

Posted 05 May 2013 - 04:43 AM

I think the problem is that you are failing to realize that there are infinitely many possible TBN matrices for any given face. They are all the same except they are slightly rotated around the normal. And they will produce different results when you try to use them. So which one to use? The idea is to already know two of the vectors of the matrix (normal and bitangent) and the bitangent tells you exactly which matrix you want. But to be meaningful, this bitangent needs to be defined with respect to the texture coordinates, to correctly align the matrix of each face to the orientation of the texture covering said face. On the other hand, the locations of the vertices of the object are independent of how the object's texture is mapped, so using them won't produce good results at all.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#14 lomateron   Members   -  Reputation: 300

Like
0Likes
Like

Posted 05 May 2013 - 04:57 AM

ok i thought it was simple tranformation, I will try now to undestand again what is inside the link the man gave me

 

I thought i just needed different rotational matrix for every face of an object but the same rotational matrix for every texel normal of a face


Edited by lomateron, 10 May 2013 - 01:26 AM.


#15 0r0d   Members   -  Reputation: 797

Like
-2Likes
Like

Posted 05 May 2013 - 01:59 PM

I think the problem is that you are failing to realize that there are infinitely many possible TBN matrices for any given face. 

This not correct.  For one thing the TBN matrix exists for each vertex, not for each face.  Also, the Tangent is defined to point in the direction of change of the U coordinate, and the binormal (or bitangent as some here are calling it) points in the direction of the V coordinate.



#16 0r0d   Members   -  Reputation: 797

Like
-1Likes
Like

Posted 05 May 2013 - 02:02 PM

this is my new question

 

I want to tranform the tangent normals of the texture to world space

I have three vectors in world space that represent a face of the object i am drawing

I will need a 3x3 matrix to rotate this tangent normals

the last vector of the matrix will be the normal of the face: normalize(cross(v1-v0,v2-v0))

the first vector of the matrix will be: cross(last vector,middle vector)

the middle vector of the matrix will be what?

 

The tangent-space matrix is not guaranteed to be orthonormal, so you cant get the basis vectors like this by crossing them to get the last one.  Also, they will transform the tangent-space normals into object-space, not world-space.  



#17 grhodes_at_work   Moderators   -  Reputation: 1361

Like
2Likes
Like

Posted 17 May 2013 - 04:34 PM

There is some very good discussion here, and I appreciate all of the contributions. There are a couple of points that I think are worth restating, or clarifying, so that people might understand more deeply.

 

With regard to which aspect of geometry the TBN is associated, the TBN exists for any point on the surface, not only at each face, and also not only at each vertex. It may be computed at each vertex, or each pixel, or once per face for that matter, depending on how it is to be used (vertex or fragment shader or just asset calculations on the CPU) or what is convenient, but strictly speaking it exists continuously across the surface.

 

With regard to the tangent direction, it is not in general true that it is defined to point in the direction of change of the u coordinate. A tangent vector can be any vector that is located in the tangent plane at a point on the surface (the tangent plane being the plane that is orthogonal to the local surface normal at that point, er, for a surface that is continuously differentiable). So, as Bacterius noted, it is true that there are infinitely many possible tangent space choices at any point on the surface.

 

It happens that computing the tangent along the curve of the u direction is quite convenient, and, since it aligns with texture coordinates, this choice fits very nicely with computer rendering use cases. Also, on a mesh, standardizing on this choice enables continuity of the tangent spaces across the entire mesh surface.


As for the bitangent (which is a more appropriate term than binormal, when dealing with surfaces), it is in fact just like the tangent in that it lies in the tangent plane. It is a tangent vector, just a different one than the T in TBN. In computer graphics the bitangent is often computed along the v direction, again in order to align with texture coordinate directions and provide for TBN continuity, but there is that issue of the u and v directions being nonorthogonal in model/world space (vs. tangent space), as discussed in prior posts. The terathon page linked above discusses this orthogonality issue with a workable solution, concisely.

 

I know many resources out there explicitly define the tangent to be computed along the u direction and bitangent to be computed along the v direction, but to understand deeply you should recognize that these choices are made merely to achieve the alignment with the texture directions with the happy bonus of TBN continuity. I hope this reply helps someone understand more deeply, if only a little.

 

Graham


Graham Rhodes Moderator, Math & Physics forum @ gamedev.net




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS