Jump to content
• Advertisement

normal mapping and tangent space

This topic is 3936 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 currently try to add normal mapping to my raytracer, but the first tests made me clear that I'm missing something and I wonder if you guys could confirm (or correct) my knowledge. Assume that I have a triangle facing the viewer, with normal (0, 0, 1), using as with OGL the z negative in the viewing direction. In addition, assume that texture coordinates are (0, 1), (0.5, 0), (1,1) clockwise from the left vertex. 1 Question: Can I use as tangent (for this test) the vector (0, 1, 0) ? When I want to calculate the textel normal: -I build the TBN matrix with (tangent, tangent.Cross(normal), normal) -I read the pixel value, normalize it and negate it (because I use -z) -I multiply the TBN for the normal to transform the pixel normal from tangent space to world space. Note that I already transformed tangent and normal into world space with the world matrix. 2 Question: I'm not sure if TBN*normal transforms the tangent space normal to the world space one or I need to further multiply the result by the world transformation of the triangle. 3 Question: The TBN must be built with T, B and N in the first 3 columns if I use column vector matrices, right? I once implemented normal mapping with OGL and GLSL but cannot find the code, so I'm not really sure where is the problem. Thank you if you can check my knowledge :-)

Share this post

Share on other sites
Advertisement
1. Yes, the tangent is <0, 1, 0> in that case.

2. If you've transformed the tangent, binormal, and normal by your world matrix, the resulting transformed normal from your normal map will be in world space.

3. Yes. Like this:

 [t.x b.x n.x] [t.y b.y n.y] [t.z b.z n.z]

Share this post

Share on other sites
Thank you very much! This means that at least my knowledge should be quite correct, and that my problem is somewhere else (implementation bug perhaps).
I'm still opened to other suggestions...

Share this post

Share on other sites
Hi,

Isn´t z always positive when you read back pixels?

/Robert

Share this post

Share on other sites
Quote:
 Original post by RasmadrakHi,Isn´t z always positive when you read back pixels?/Robert

Yes, that's why I negate the vector (should I perhaps negate only the z component?)...

Share this post

Share on other sites
Ok I've found it, quite stupid mistake but could be useful to others:

In the normal map x and y (r and g) channels are 'signed', that is the 0 is 127. This means that after you read them and scale them in the [0,1] range, you need to substract 0.5.

Obvious perhaps, but I forgot to do that.

Thank you all!

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 14
• 9
• 9
• 10
• 12
• Forum Statistics

• Total Topics
632911
• Total Posts
3009186
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!