I am currently working on a Path Tracer, and i am looking for ways to optimize my ray-triangle intersections. I currently use the following sse4 implementation of Moller-Trumbore algorithm:
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 > 1.0f))
return false;
float t = f * _mm_dp_ps(tri.e2, r, dotProductMask).m128_f32[0];
if (t < 0.0f || t > m_length)
return false;
result = t;
return true;
}
(If someone see a way to optimize it let me know). Then i've read that it is possible to perform intersection tests on 4 triangles simultaneously using SIMD intructions. But how to do that ? I don't see how could it be possible to implement it in a way that will be more efficient than my sequential fashion.
Here the small code concerned of my renderer.