Converting to and from tangent space

Godot Version



i’m trying to learn the godot 3d suite this week and so far i really like the shader workflow. one thing i’ve been having trouble with is getting inputs like fragment coordinate, normal vector, etc in a usable space (like world space or object space). i’ve figured out how to use the transformation matrices to hop between view and world space, but how can i get a vector in tangent space? it doesn’t seem like there is a transformation matrix for this (at least not in the godot docs).

say for instance that i have a shader that intercepts the normal vector. i want to be able to also use a normal map input to add to the default normal direction from the mesh face. that means i need to pull the normal out of view space, pull the normal map out of tangent space, add them together, do all of my shader’s custom transformation (maybe i’m sharpening them, or rounding them into cells, or adding random noise) and finally convert back into view space.

the problem is that it doesn’t seem like there is a way to convert to and from tangent space. i assume that the NORMAL_MAP output is doing this behind the scenes, but i need to be able to do it manually. any ideas?

You should already have TANGENT and BINORMAL in view space (same as the rest of the inputs of fragment)

isn’t TANGENT just the tangent vector? and what space is it in, certainly not tangent space. what i need is to be able to convert vectors from tangent space to object space, and vice versa

i’m not super familiar with matrix multiplication but is there a way for me to construct a transformation matrix out of the tangent normal and binormal?

Yep! mat3(TANGENT, BINORMAL, NORMAL) is what you are looking for. It will take a vec3 from view space and convert it into tangent space

1 Like

thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.