Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Texture space normal mapping problems

Started by CJ Clark Sep 17, 2005 at 3:14 AM 1 replies 450+ views
Original Post
CJ Clark
CJ Clark
I've been pounding my head against the keyboard for quite some time now over this issues. What I have is a Doom 3 model standing in its "modellers default pose" with its arms outstretched, no animations. I performed the skinning in software. Now, all I'm trying to do is light the mesh with the tangent space normal map correctly before moving into vertex shaded skinning. However, I cannot, for the life of my get the normal map to look right. I have an object space normal mapping system working currently and I'm attempting to port that over to a tangent space normal map. I've researched this extensively however I don't ever really find information that matches other peoples info or I don't find enough information. What my question is is this: I have a function to calculate the tangent, biNormal and normal vectors from 3 vertices and 3 texture vertices. Now, if I invert this matrix and use the normal in my "NORMAL" parameter to my shader, most of the polygons do not render. If I do not invert it, then what I'm passing into the shader is the TBN matrix. Does this matrix convert texture space to object space? Then, does the TBN Inverse matrix convert object to texture space? Please let me know if this is correct. Secondly, if I DO have to pre-calculate the inverse matrix and pass in the tangent and normal's, how do I get OpenGL to render the vertex regardless of the normal being in texture space (because it would drop the vertex out thinking its backwards wouldn't it??)? Is the normal being in texture space actually causing any problems in this manner? The biggest question then is what am I SUPPOSED to pass into the vertex shader, the TBN matrix or the TBN Inverse matrix? Whichever one, what am I supposed to do with it? If its the inverse, do I transform the light vector AND the view vector or just the light vector?? If its the TBN, do I transform the normal read from the normal map? Another question, if anyone knows it. I'm trying to do smooth shading. So far I have NO idea weather or not its valid to assume that I can add together all the normals and tangents and then normalize them at the end so each vertex has a smooth shaded vertex normal and tangent. Is this valid or does EACH tangent have to be unique to a given vertex? If so, how would you go about tri-stripping and rendering those?? If I CAN add them all together and normalize them in the end, please let me know. If I can't, how do you perform smooth shading then? I hope someone has an answer to more of these than fewer, but honestly, anything helps right now. Please ask if you have questions or E-mail me and I'll answer them as soon as I can. Thank you for your time and I hope someone out there can help me! Thanks! :)
m4gnus
m4gnus
have i understood that right:
You're calculating 1 matrix for converting worldspace to tangent space in software?

Usually you calculate this matrix in the Vertexshader using the normal,tangent and binormal. Then you multiply the lightvector with this matrix(still in vertexshader) and pass this transformed vector to the pixelsahder.

In the pixelshader you can just do a dotproduct of the lightvector and the normal in the normalmap and that should give you a simple diffuse shading.

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
CJ Clark
CJ Clark
Quote:
Original post by m4gnus
have i understood that right:
You're calculating 1 matrix for converting worldspace to tangent space in software?

Usually you calculate this matrix in the Vertexshader using the normal,tangent and binormal. Then you multiply the lightvector with this matrix(still in vertexshader) and pass this transformed vector to the pixelsahder.

In the pixelshader you can just do a dotproduct of the lightvector and the normal in the normalmap and that should give you a simple diffuse shading.

regards,
m4gnus


Thank you for the response. Yes, you do understand right. I'm calculating it in software because I need to calculate the normal and tangent. After calculating that, I pass those two vectors in as the normal and color components to my shader. THEN, inside my shader I calculate the biNormal as the cross product of tangent and normal and create my TBN matrix.

So what I'm wondering is this: Is the normal and tangent that I pass to the vertex shader from the base TBN matrix or the TBN inverse matrix? If its from the base matrix (which would convert tangent space to object space) would I have to invert it when I compute it in the pixel shader? If not, why? If I don't wouldn't that then transform the light vector when I multiply that from tangent space to object space? That's the opposite of what I want isn't it?

Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.