Working with normal spaces
A catalog of different normal spaces
Part of the motivation of this thinking is that in godot the NORMAL comes in view space by default:
NORMAL (vec3): Normal that comes from the vertex() function, in view space. ...
INV_VIEW_MATRIX (vec4): View space to world space transform.
Convert from view space to world space
n_world_space = INT_VIEW_MATRIX * vec4(NORMAL, 0.0)
Convert from world space to local space
mat4 inv_model_matrix = inverse(MODEL_MATRIX);
vec3 n_local = (inv_model_matrix * vec4(n_world_space, 0.0)).xyz;
Working with vec3 and vec4
When working with some of these values we have to use a vec. There is a handy shortform:
vec4(vec3, value) which converts this to vec4(vec3.x, vec3.y, vec3.z, value);
To retrieve values, or convert down we have
vec4().xyz which will return a vec3.
View/Camera Space
View space (or camera space) shifts the center of the universe to the camera lens. While it is natural to assume the camera looks straight forward down the Z-axis, Godot’s right-handed coordinate system flips this logic. The positive Z-axis actually points backward out of the screen toward you, meaning the camera is technically staring down the negative Z-axis into your 3D world.
World Space
Think of world space as the master grid of your entire game level. It is the global, shared coordinate system where the origin (0, 0, 0) acts as the exact center of the universe. All transformations are calculated relative to this grid. If you place a cube at (5, 0, 3), you are defining its absolute location within the world, regardless of how the object itself is rotated or where the camera is looking.
Model/Local space
Think of model space as an object’s personal, internal blueprint. The origin (0, 0, 0) is simply the pivot point of the mesh itself. Whenever you scale or rotate an object locally, you are manipulating it inside this specific space. A 3D cube might be placed a thousand miles away in the game world, but inside its own model space, its vertices still sit perfectly around its own center, ranging predictably from (-1, -1, -1) to (1, 1, 1).
Tangent Space
Normals point in the direction of the z-axis away from the face. Tangent space originates at the point on the polygon that it is being calculated at. The z-axis is point straight away from the mesh and the x,y are pointing perfectly flat along the polygon.