Skip to content

Instantly share code, notes, and snippets.

@shakesoda
Last active August 17, 2022 18:10
Show Gist options
  • Save shakesoda/8485880f71010b79bc8fed0f166dabac to your computer and use it in GitHub Desktop.
Save shakesoda/8485880f71010b79bc8fed0f166dabac to your computer and use it in GitHub Desktop.
// cofactor matrix. drop-in replacement for the traditional transpose(inverse(m)) normal matrix calculation.
// this is a substantial performance improvement.
// short form found via shadertoy: https://www.shadertoy.com/view/3s33z
mat3 cofactor(mat4 m) {
return mat3(
cross(m[1].xyz, m[2].xyz),
cross(m[2].xyz, m[0].xyz),
cross(m[0].xyz, m[1].xyz)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment