Skip to content

Instantly share code, notes, and snippets.

@mrdoob
Created September 19, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdoob/f5e7f20bec74b3f91eaec40097da9d55 to your computer and use it in GitHub Desktop.
Save mrdoob/f5e7f20bec74b3f91eaec40097da9d55 to your computer and use it in GitHub Desktop.
Matrix3.getNormalMatrix()
// 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