我目前正在研究路径追踪器,我正在寻找优化我的光线三角形交叉点的方法。我目前使用以下 Moller-Trumbore 算法的 sse4 实现:
bool Ray::intersectTriangle(const Triangle tri, float& result) const
{
__m128 q = _mm_cross_ps(m_directionM128, tri.e2);
float a = _mm_dp_ps(tri.e1, q, dotProductMask).m128_f32[0];
if (a > negativeEpsilon && a < positiveEpsilon)
return false;
float f = 1.0f / a;
__m128 s = _mm_sub_ps(m_originM128, tri.v0);
float u = f * _mm_dp_ps(s, q, dotProductMask).m128_f32[0];
if (u < 0.0f)
return false;
__m128 r = _mm_cross_ps(s, tri.e1);
float v = f * _mm_dp_ps(m_directionM128, r, dotProductMask).m128_f32[0];
if (v < 0.0f || (u + v …Run Code Online (Sandbox Code Playgroud)