Skip to content

Commit

Permalink
TangentFrame cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tunabrain committed May 16, 2018
1 parent a0a8f6f commit 49027bd
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/core/math/TangentFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ struct TangentFrame
TangentFrame(const Vec3f &n)
: normal(n)
{
// naive method
// if (std::abs(normal.x()) > std::abs(normal.y()))
// tangent = Vec3f(0.0f, 1.0f, 0.0f);
// else
// tangent = Vec3f(1.0f, 0.0f, 0.0f);
// bitangent = normal.cross(tangent).normalized();
// tangent = bitangent.cross(normal);

// [Duff et al. 17] Building An Orthonormal Basis, Revisited. JCGT. 2017.
float sign = copysignf(1.0f, normal.z());
const float a = -1.0f / (sign + normal.z());
const float b = normal.x() * normal.y() * a;
tangent = Vec3f(1.0f + sign * normal.x() * normal.x() * a, sign * b, -sign * normal.x());
bitangent = Vec3f(b, sign + normal.y() * normal.y() * a, -normal.y());
const float a = -1.0f/(sign + normal.z());
const float b = normal.x()*normal.y()*a;
tangent = Vec3f(1.0f + sign*normal.x()*normal.x()*a, sign*b, -sign*normal.x());
bitangent = Vec3f(b, sign + normal.y()*normal.y()*a, -normal.y());
}

Vec3f toLocal(const Vec3f &p) const
Expand Down

0 comments on commit 49027bd

Please sign in to comment.