Created
September 19, 2019 10:27
-
-
Save mrdoob/f5e7f20bec74b3f91eaec40097da9d55 to your computer and use it in GitHub Desktop.
Matrix3.getNormalMatrix()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use to transform normals with transformation of | |
// arbitrary non-uniform scales (including negative) | |
// and skewing. The code assumes the last column of m is | |
// [0,0,0,1]. More info here: | |
// https://github.com/graphitemaster/normals_revisited | |
mat3 adjoint( in mat4 m ) | |
{ | |
return mat3( | |
m[1][1]*m[2][2]-m[1][2]*m[2][1], | |
m[1][2]*m[2][0]-m[1][0]*m[2][2], | |
m[1][0]*m[2][1]-m[1][1]*m[2][0], | |
m[0][2]*m[2][1]-m[0][1]*m[2][2], | |
m[0][0]*m[2][2]-m[0][2]*m[2][0], | |
m[0][1]*m[2][0]-m[0][0]*m[2][1], | |
m[0][1]*m[1][2]-m[0][2]*m[1][1], | |
m[0][2]*m[1][0]-m[0][0]*m[1][2], | |
m[0][0]*m[1][1]-m[0][1]*m[1][0] ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment