@GreatRash said:
Final question: can you explain transpose(inverse(MODELVIEW_MATRIX))
Or maybe you have some links where I can read about it.
View space TBN matrix is constructed from 3 basis vectors representing 3 axes. The basis must be orthonormal for normal mapping to work properly. Orthonormal means that 3 basis vectors must be perpendicular to each other and their length must be 1.
So, when transforming TANGENT, BINORMAL and NORMAL vectors into view space, we must take care that above criteria are met. In order to transform them using modelview matrix we need to eliminate scaling and translation from it, so that only rotation from that matrix is applied. Simplest way to do so is to calculate transposed inverse. Explained in more detail here.
This matrix is often called 'normal matrix' and it's typically used in vertex shaders to transform mesh normals into camera space to avoid normal skewing due non-proportional scaling. It's odd that Godot didn't include it as a built-in uniform. If you plan to use it in vertex-heavy meshes it's more optimal to calculate it on the cpu side and send it to shader as an uniform. Calculating it per vertex is superfluous as the result is always the same.
Note that you can still use plain modelview matrix to do the job (either for normals or basis vectors) but there must be no non-proportional scaling in the matrix and resulting vectors must be normalized (to nullify translation and proportional scalling)