Skip to content

Instantly share code, notes, and snippets.

@optimizedaway
Created February 23, 2020 12:27
Show Gist options
  • Save optimizedaway/67fc832fa9c95646a92df0e8a851ea78 to your computer and use it in GitHub Desktop.
Save optimizedaway/67fc832fa9c95646a92df0e8a851ea78 to your computer and use it in GitHub Desktop.
/// Build orthonormal frame from normalized dir
/// Hughes and Moeller http://cs.brown.edu/~jfh/papers/Moller-BAO-1999/main.htm
inline float3x3 FrameFromDirHughes(float3 dir)
{
float3 dx0 = float3(0, dir.z, -dir.y);
float3 dx1 = float3(-dir.z, 0, dir.x);
float3 dx = normalize(dot(dx0, dx0) > dot(dx1, dx1) ? dx0 : dx1);
float3 dy = cross(dir, dx);
return float3x3(dx, dy, dir);
}
/// Build orthonormal frame from normalized dir
/// Improved Frisvad http://jcgt.org/published/0006/01/01/
inline float3x3 FrameFromDirFrisvad(float3 dir)
{
float sz = sign(dir.z);
float a = -rcp(sz + dir.z);
float b = dir.x * dir.y * a;
float3 dx = float3(1.0 + sz*dir.x*dir.x*a, sz*b, -sz*dir.x);
float3 dy = float3(b, sz + dir.y*dir.y*a, -dir.y);
return float3x3(dx, dy, dir);
}
/// TODO FrameFromDirPixar
/// http://marc-b-reynolds.github.io/quaternions/2016/07/06/Orthonormal.html
/// https://github.com/Marc-B-Reynolds/Stand-alone-junk/blob/master/src/Posts/ortho_basis.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment