I'm doing a per fragment lighting and when correcting normal vecter, i got this code: vec3 f_normal = mat3(MVI) * normal;
Where MVI is: mat4 MVI = transpose(inverse(ModelViewMatrix));
. So what is return after mat3(MVI)
statement?
mat3(MVI) * normal
Returns the upper 3x3 matrix from the 4x4 matrix and multiplies the normal by that. This matrix is called the 'normal matrix'. You use this to bring your normals from world space to eye space. The upper 3x3 portion of the matrix is important for scale and rotation, while the rest is only for translation (and normals are never translated)
To take a normal from world space to eye space, you just need the 3x3 inverse transpose of the model view matrix. Unless your matrix in othro normal (no non-uniform scale) in that case the original matrix is the same as its inverse transpose.
From GLSL types: "There are no restrictions on size when doing matrix construction from another matrix. So you can construct a 4x2 matrix from a 2x4 matrix; only the corresponding elements are copied.". So, you get the MVI's top-left 3x3 submatrix as a result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With