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

## Recommended Posts

Ok, so I've been reading up on bump mapping recently, and I am having a little difficulty understanding something. I understand the tangent space matrix (TSM), and I understand that you have to transform the light vector into tangent space by multiplying it by the inverse of the TSM, so that way the dot product makes sense. The problem is that some websites claim that when the triangle is rotated, the TSM must be recalculated. I understand why that is, but the triangles are being rotated practically every frame, so what is the point of precalculating the inverse-TSM, if you have to recalculate it anyway? I'm assuming that most modern games don't do this, as it seems like a real performance killer. I would guess that there is some other matrix that already exists that I can multiply the precalculated inverse-TSM by to get the rotated inverse-TSM. Maybe the gl_NormalMatrix (in GLSL)? Any help I can get would be greatly appreciated. I would like to understand this completely before I try to implement my own shader.

##### Share on other sites
Right, just calculate the tangent space matrix in the vertex shader, and as you suggested, transform the normal and tangent vectors by gl_NormalMatrix before calculating the bitangent vector. That will give you the correct vectors for your TSM.

##### Share on other sites
Thanks for the quick response! Let me make sure I understand what you're saying.

So, lets say I've already pre-computed T,B, and N vectors. I could send these to the vertex shader, transform each one by gl_NormalMatrix and then find the inverse of that new matrix to transform the light direction into tangent space?

Or can I pre-compute the inverse T,B, and N vectors, and transform those by the gl_NormalMatrix? (is there an inverse normal matrix I could use?) That way I wouldn't have to calculate the inverse of the transformed tangent space matrix in the vertex shader.

Thanks again for any help.

##### Share on other sites
Quote:
 Original post by HalibutOr can I pre-compute the inverse T,B, and N vectors, and transform those by the gl_NormalMatrix? (is there an inverse normal matrix I could use?) That way I wouldn't have to calculate the inverse of the transformed tangent space matrix in the vertex shader.

Don't worry so much about calculating the inverse of the matrix--since the TSM is orthonormal, finding its inverse is trivial (the inverse of an orthonormal matrix is its transpose).

##### Share on other sites
Ok, it all seems to be making sense now. I thought that the solution was easier than I was making it out to be. I guess I should have checked up on my matrix math for the orthonormal bit.

Thanks for the help!

##### Share on other sites
Ok, I was doing some more thinking, and I have one last question. If my texture coordinates are skewed (i.e. not a simple translation or rotation or uniform scale of the vertex coordinates), this method will not work right?

Otherwise the tangent space matrix wouldn't be orthonormal. If I calculate the T and N and then find B from N X T, then the matrix is orthonormal, but the matrix might not be right.

So I guess my question is this: Is there any way around this problem, or should I just make sure that when I create texture coordinates for my models that I don't stretch the texture across it in a way that would make the TSM non-orthonormal?

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011399
• ### Who's Online (See full list)

There are no registered users currently online

×