Skip to content

Instantly share code, notes, and snippets.

@XProger
Last active March 13, 2018 04:53
Show Gist options
  • Save XProger/b338c55634f1856d93030cd4f7964a5d to your computer and use it in GitHub Desktop.
Save XProger/b338c55634f1856d93030cd4f7964a5d to your computer and use it in GitHub Desktop.
method to get orthonormal basis without normalization by Jeppe Revall Frisvad (jrf@imm.dtu.dk)
void getBasis(const vec3 &n, vec3 &t, vec3 &b) {
if (n.z < -0.9999999f) {
t = vec3( 0.0f, -1.0f, 0.0f);
b = vec3(-1.0f, 0.0f, 0.0f);
return;
}
const float x = 1.0f / (1.0f + n.z);
const float y = -n.x*n.y*x;
t = vec3(1.0f - n.x*n.x*x, y, -n.x);
b = vec3(b, 1.0f - n.y*n.y*x, -n.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment