21 #ifndef LIB_LIGHTMETRICA_TRIACCEL_H
22 #define LIB_LIGHTMETRICA_TRIACCEL_H
24 #include "math.functions.h"
50 LM_FORCE_INLINE
int Load(
const Math::Vec3& A,
const Math::Vec3& B,
const Math::Vec3& C);
53 LM_FORCE_INLINE
bool Intersect(
const Ray& ray, Math::Float mint, Math::Float maxt, Math::Float& u, Math::Float& v, Math::Float& t)
const;
57 LM_FORCE_INLINE
int TriAccel::Load(
const Math::Vec3& A,
const Math::Vec3& B,
const Math::Vec3& C)
59 static const int waldModulo[4] = { 1, 2, 0, 1 };
63 Math::Vec3 N = Math::Cross(c, b);
67 for (
int j = 0; j < 3; j++)
69 if (Math::Abs(N[j]) > Math::Abs(N[k]))
75 uint32_t u = waldModulo[k];
76 uint32_t v = waldModulo[k+1];
77 const Math::Float n_k = N[k];
78 const Math::Float denom = b[u]*c[v] - b[v]*c[u];
89 n_d = Math::Dot(Math::Vec3(A), N) / n_k;
100 LM_FORCE_INLINE
bool TriAccel::Intersect(
const Ray& ray, Math::Float mint, Math::Float maxt, Math::Float& u, Math::Float& v, Math::Float& t)
const
102 Math::Float o_u, o_v, o_k, d_u, d_v, d_k;
138 if (d_u * n_u + d_v * n_v + d_k == 0)
145 t = (n_d - o_u*n_u - o_v*n_v - o_k) / (d_u * n_u + d_v * n_v + d_k);
146 if (t < mint || t > maxt)
152 const Math::Float hu = o_u + t * d_u - a_u;
153 const Math::Float hv = o_v + t * d_v - a_v;
156 u = hv * b_nu + hu * b_nv;
157 v = hu * c_nu + hv * c_nv;
159 return u >= 0 && v >= 0 && u+v <= 1;
164 #endif // LIB_LIGHTMETRICA_TRIACCEL_H
Definition: triaccel.h:31