In my game engine I'm passing a normal matrix to my shaders like so:
Matrix3f normalMatrix = modelMatrix.invert().transpose();
However this is causing lighting to rotate with my object, producing a weird effect.
As I'm not performing any non-uniform scaling, I tried substituting normalMatrix for mat3(modelMatrix), and that worked fine.
Also doing the transpose inverse on the GPU using transpose(inverse(modelMatrix)) worked fine.
This has lead me to believe there is a bug in my invert() and transpose() functions.
According to some math websites, when the modelMatrix lacks any non-uniform scaling, calling inverse().transpose() on it will produce the exact same matrix.
However in my code the output is far from the same:
modelMatrix
0.25 0 0 2353.3474
0 0.25 0 0
0 0 0.25 51.86973
0 0 0 1
normalMatrix = new Matrix3f(modelMatrix).invert().transpose()
4.0 0.0 0.0
0.0 4.0 0.0
0.0 0.0 4.0
Would anyone be able to shed some light on this issue...
(I don't want to just stick with modelMatrix because I do want to support non-uniform scaling in the future)
Here are some screenshots describing the issue:
These are two frames of my planet as it rotates. The light source appears to be rotating with it (it shouldn't be). Using the modelMatrix instead of normalMatrix solves the issue.
