Sign in to follow this  

normal mapping and tangent space

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


Link to post
Share on other sites
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


Link to 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


Link to post
Share on other sites
Quote:
Original post by Rasmadrak
Hi,

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


Link to 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


Link to post
Share on other sites

This topic is 3635 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this