• Advertisement
Sign in to follow this  

Visualizing tangent space theory

This topic is 3489 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

I'm fairly new to bumpmapping and whilst managed to implemented in HLSL i have some questions(please forgive me if they seem noobish, but here goes): In my vertex shader i calculated the light vector in world space and then, when just about to multiply it with the inverse of the tangent space matrix i transformed the tangent,bitangent and normal from object space to eye space and then performed the multiplication. It seems that everything is ok now. 1.0 Why do i have to transform the T,B,N vectors from object space to eye space? (Not doing this it seems the illuminated portion of the model is "fixed", affecting the modelview matrix the illuminated portion of the model just rotates along with the model). I'm trying to understand the calculation of the tangent space matrix but there's something bothering me. From a text over the internet(here: http://www.cescg.org/CESCG-2006/papers/TUBudapest-Premecz-Matyas.pdf) i can read:
Quote:
Let us first consider the computation of the appropriate tangent and binormal(seems they call it binormal here for a discussion about naming convensions see: Lengyel, Eric. "Computing Tangent Space Basis Vectors for an Arbitrary Mesh", here: http://www.terathon.com/code/tangent.html ) vectors. Suppose that we have a triangle with vertices p1, p2, p3 in local modeling space, and with texture coordinates [u1, v1], [u2, v2], [u3, v3]. According to their definition, unknown tangent T and binormal B correspond to texture space vectors [1, 0] and [0, 1], respectively. The mapping between the texture space and the local modeling space is linear, thus an arbitrary point p is the following function of the texture coordinates: p(u, v) = p1 + (u - u1)*T + (v - v1)*B: Note that the linear approximation means that 3D vector p2 - p1 corresponds to texture space vector [u2 - u1, v2 - v1], and 3D vector p3 - p1 corresponds to texture space vector [u3 - u1. v3 - v1].
What do they mean when they say that
Quote:
The mapping between the texture space and the local modeling space is linear
and why is this so?
Quote:
Note that the linear approximation means that 3D vector p2 - p1 corresponds to texture space vector [u2 - u1, v2 - v1], and 3D vector p3 - p1 corresponds to texture space vector [u3 - u1, v3 - v1]
I need to figure a way of visualizing this. Edit: I made a mistake, T,B,N we're transformed in eye space, multiplied by the modelview matrix. [Edited by - Deliverance on July 30, 2008 4:30:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
I think a picture would help a lot here:



The fact that it is linear is something people who invented UV mapping chose for convenience. Basically it means that if you write a point as a linear combination of 2 vectors in uv space, then its value in xy space is a linear combination of the vectors in xy space:
p((u,v)) = p(u*(1,0) + v*(0,1)) = u*p((1,0)) + v*p((0,1)) = u*T + v*B

They could have chosen a nonlinear mapping, but that would just be a different type of mapping, and the straight lines in the diagram would look curvy.

There is one other complication which is that the origins may be offset from 0, and so that is where the p1, and u1, v1 come into play.

Share this post


Link to post
Share on other sites
When doing computations with vectors, it's important that they all live in the same space. You'll get meaningless garbage if you try to dot one vector in model space with another vector in a tangent space.

So the first job in normal mapping is to get everything in the same space. The normals encoded in the normal map are living in what we might call tangent space. However, the light vector (that is, the vector from a point on the mesh to the light source) is in model space. To meaningfully dot the light vector with a normal vector extracted from the normal map, we must therefore transform the normal vector into model space or transform the light vector into tangent space.

Imagine taking a sheet of paper that represents the normal map and gluing some thumbtacks on it upside down. The direction of each thumbtack is a normal in the normal map. Of course, you'd need to space them out a bit so they all fit. Now, say your model is a statue of a cat. Pick out a thumbtack on your sheet of paper and figure out which point on the cat statue it corresponds to (in practice this will be handled by the texture coordinates). Now pick up the sheet of paper and put it against the statue so that all the thumbtacks are facing away from the statue and, most importantly, the chosen thumbtack is against the point to which it corresponds on the statue. Notice that the sheet of paper is now tangent to the statue at the point to which the chosen thumbtack corresponds. This is why it's called tangent space. This operation represents the transformation of taking the normal from tangent space to model space. Because we only moved the sheet of paper around and rotated it, we can represent this transformation by a matrix. All transformations represented by matrices are conveniently linear.

Now, usually in practice we go the other way. We take the light vector and transform it into tangent space (this way we perform one transform per vertex rather than one transform per pixel). For this we use the inverse of the transformation found above.

By the way, is it just me or is this use of the term "tangent space" completely conflicting with the ordinary use in the theory of manifolds?

[Edited by - nilkn on August 1, 2008 12:18:03 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by nilkn
By the way, is it just me or is this use of the term "tangent space" completely conflicting with the ordinary use in the theory of manifolds?


If I understand the analogy correctly, in usual math the tangent space at a point would be the flat piece of paper tangent to the surface at that point, and locally the normal map would be a scalar function on the tangent space.

(As an aside, for more general manifolds that aren't embedded in a euclidean space, you can't put a piece of paper on there since there is no space for the paper to be in, so you have to define the tangents in terms of equivalence classes of curves running through a point or some such trickery.)

I'm getting a little confused about trying the linear map on a curving surface though. I don't think its going to work. The linear map will only work on a flat surface like a triangle, or very close to the point the tangent space is based off of. For a more general curving surface like from a spline or something I think you'd need to either triangulate it first, or have the normal map as a function on the manifold's coordinate charts, which would be nonlinear. Is there something I'm missing here?

Share this post


Link to post
Share on other sites
If I'm interpreting you right, then you're right that a single linear map wouldn't work for a curved surface. Generally a different linear map is constructed for each vertex of the mesh. There's a preprocessing stage where the engine calculates the tangent, bitangent, and normal to the mesh at each vertex and sends these vectors to the vertex shader packed with the vertex data. The vertex shader then constructs the linear map as a matrix using these vectors and transforms the light vector to tangent space. Then the pixel shader just unpacks the normal and dots it with the tangent space light vector.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement