🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Question about bump mapping

Started by
4 comments, last by Halibut 18 years, 3 months ago
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.
Advertisement
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.
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.
Quote: Original post by Halibut
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.


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

This topic is closed to new replies.

Advertisement