• Advertisement

# normals in tangent space question

This topic is 1706 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

#### Share this post

##### Share on other sites
Advertisement

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).

#### Share this post

##### Share on other sites

"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

#### Share this post

##### Share on other sites

"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.

#### Share this post

##### Share on other sites

"derived from the u-v coordinates"

how exactly is the bitangent direction derived?

#### Share this post

##### Share on other sites

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

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

#### Share this post

##### Share on other sites

"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

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites

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).

#### Share this post

##### Share on other sites

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?

#### Share this post

##### Share on other sites

the middle vector of the matrix will be what?

The bitangent  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

#### Share this post

##### Share on other sites

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.

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites

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.

#### Share this post

##### Share on other sites

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.

#### Share this post

##### Share on other sites

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

#### Share this post

##### Share on other sites

• Advertisement