Jump to content
  • Advertisement
_Flame_

TBN matrix in learnopengl

Recommended Posts

Posted (edited)

Hello.

These is an article about normal mapping - https://learnopengl.com/Advanced-Lighting/Normal-Mapping

The  author is creating TBN matrix where each vector corresponds to R, G, B or X, Y, Z vector. AFAIK these vectors are x - "right", y - "up", z - "dir" and in order to build a matrix from them we must place them in that exact order - first "right", second "up", third "dir". But the author says that normal vector is "up" for some reason.  Why is normal vector not "dir" since it's last in the TBN?"

 

Quote from the article -

Quote

We already know the up vector which is the surface's normal vector. The right and forward vector are the tangent and bitangent vector respectively. The following image of a surface shows all three vectors on a surface:

But he constructs matrix  as mat3(T, B, N). I don't understand why N is called "up" whereas it should be "dir" to my mind.

Edited by _Flame_

Share this post


Link to post
Share on other sites
Advertisement

I didn't read the whole article, but I'll mention that there's no rule regarding which vector in an orthonormal basis is 'up'. This, for example:

Quote

...x - "right", y - "up", z - "dir"...

Is only one of various possible conventions. For example, you could instead use the convention of z = up, y = forward, and x = right or left (depending on handedness).

I did see that the article refers to another related tutorial about cameras, and it looks like in that tutorial y is up and +/-z is forward. Once again though, that's just a convention, and just because y is 'up' in one context doesn't mean it has to be 'up' in another.

Lastly, I'll again offer the disclaimer that I didn't read the whole article and may be missing relevant context. If so, maybe someone else will jump in and provide a better answer.

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, _Flame_ said:

Yes, i understand this thing is convention.

But I think in opengl the convention is to have side, up, forward like here - https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml

glm::LookAt also has same convention. It would be strange to do it differently.

Certain coordinate spaces in the OpenGL pipeline incorporate certain conventions/expectations, and functions like gluLookAt() and similar functions in GLM reflect that inasmuch as their purpose is to transform geometry into such spaces. But outside of those parts of the pipeline, what convention to use is up to you. In world space, for example, both y-up and z-up are common conventions, and I'd argue that neither is any 'stranger' than the other (although people can certainly have strong opinions on the matter, as is often the case when conventions come into play).

As for your original question, there are others here more qualified to comment on that specific issue, but my intuition is that there's no 'necessary' mapping between 'side, up, and direction/forward' and 'T, B, and N'. For example, this tutorial:

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/

Seems to refer to x as right and y as up based on how they tend to be oriented in the plane of the texture, while calling z 'outside' (and not, for example, 'direction' or 'forward'). The tutorial you linked to, on the other hand, describes the normal direction as 'up', and since the normal is assigned to the z vector, that makes z up.

I'm happy to be corrected (and maybe someone will do so), but I think the question of which direction is 'up' is purely a matter of convention here (as, I think, the two tutorials mentioned above demonstrate, given that they appear to use different conventions for this). In summary (assuming I'm correct about all this) it's perfectly fine to call z 'up' in a TBN basis.

Edited by Zakwayda

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!