From 49027bd6d74ae4d51e78b25cd765ebe19e03b086 Mon Sep 17 00:00:00 2001 From: Benedikt Bitterli Date: Wed, 16 May 2018 11:14:03 -0400 Subject: [PATCH] TangentFrame cleanup --- src/core/math/TangentFrame.hpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/core/math/TangentFrame.hpp b/src/core/math/TangentFrame.hpp index 022b3537..c929fed4 100644 --- a/src/core/math/TangentFrame.hpp +++ b/src/core/math/TangentFrame.hpp @@ -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