Jump to content
  • Advertisement
Sign in to follow this  

Why is my coordinate space transformation wrong? (Tangent -World)

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

Hi guys,
I am trying to teach myself graphicsprogramming, but sometimes I stumble over some things.
I try to convert a normal that I get from sampling a normal map into worldspace.
My thoughts on this:
A vector x can be expressed as a linear combination of three scalar values a1,a2,a3 like this:

x = e1 * a1 + e2 * a2 + e3 * a3 = [e1,e2,e3] * (a1,a2,a3).
e1, e2, e3 are vectors that form a basis of a vector space.
Assume that M is the change of basis matrix that converts from vector space [e1,e2,e3] to [f1,f2,f3].
M * [e1,e2,e3] = [f1,f2,f3]
To get M I do the following: M = [f1,f2,f3] * [e1,e2,e3]^T (1)

In this special case let [e1,e2,e3] be [Tangent,Bitangent,Normal] (They are basis vectors, right?):
To convert a sampled vector v=[Tangent,Bitangent,Normal] * v' to world space I do the following:

M * [Tangent, Bitangent, Normal] * v' = [W1,W2,W3] * v'.
=> M * v = [W1,W2,W3] * v' =(1)=> [W1,W2,W3] * [Tangent,Bitangent,Normal]^T * v =? "Point in world space"

However this produces wrong results. I read online that M should be [Tangent,Bitangent,Normal], so I implemented it that way and it works.
But I also want to get the math behind this. So why is my solution not working? And whats the math behind the correct solution?

Thank you guys

Share this post

Link to post
Share on other sites

There are a number of things that could be the issue, and without a bit more info it will be hard to narrow it down. Shortlisted are 1) what type of multiplication are you using, V*M or M*V. 2) what handedness are the spaces(and are they all the same).  Can you provide some code to show how you are attempting to use it?

Share this post

Link to post
Share on other sites


so in my shader I do this (Z-Up, objects have no transformations)
out mat3 TBN
TBN = mat3(0,1,0, 0,0,1 ,1,0,0) * transpose(mat3(Tangent, Bitangent, Normal));
So mat3(Tangent,Bitangent,Normal) should do this:
[Tangent.x, Tangent.y, Tangent.z       ]
[Bitangent.x, Bitangent.y, Bitangent.z]
[Normal.x, Normal.y, Normal.z            ]

And after the transpose() I should end up with      [Tangent.x,... ]
                                                                         [Tangent.y, ...]
                                                                         [Tangent.z, ...]   
So now I should be in world space.

1) I am using M * V assuming M is the change of basis matrix and V is the normal.
2) Right handed coordinate systems, Z-Up.

Thank you ;)

Edited by DaOnlyOwner

Share this post

Link to post
Share on other sites

Okay so it turns out that my mat3 creates matrices in column major order. So if I do mat3(Tangent, Bitangent, Normal) I am actually already assigning the transposed matrix.

Anyways thank you

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

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!