Möller–Trumbore ray-triangle intersection
Tests a ray against a triangle by solving for the hit distance and two barycentric coordinates in one go, with no precomputed plane and no extra per-triangle storage beyond the three vertices.
Also known as Moller-Trumbore, MT intersection
In the family Geometry, meshing & signed distance fields, ray-primitive intersection
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Built in | Ray.intersectTriangle() / Raycaster docs |
| Babylon.js 9.38.0 | Built in | ray.intersectsTriangle() / scene.pick docs |
| Godot 4.7 | Built in | Geometry3D.ray_intersects_triangle(from, dir, a, b, c) docs Engine source implements the Moller-Trumbore edge/determinant form. |
| Unity | None found | Physics raycasts and DXR/Vulkan RT use PhysX/hardware BVH; no public Möller-Trumbore shader helper is exposed. |
| Unreal 5.7 | None found | |
| Blender 5.2 | Built in | Cycles ray-triangle intersection kernel in intern/cycles/kernel/geom/triangle_intersect.h docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
A point on the triangle is A + u(B-A) + v(C-A), and a point on the ray is O + tD. Setting them equal gives a 3x3 linear system in (t, u, v). Cramer's rule solves it with two cross products and a handful of dot products: one cross of the ray direction with an edge yields the determinant, and a second cross yields the numerators for v and t. The determinant also tells you whether the ray is parallel to the triangle. You reject early when u falls outside [0,1] or u+v exceeds 1, so most misses cost one cross product. The result is the distance t plus barycentrics, which you can reuse to interpolate normals, UVs or vertex colours. Because it stores nothing but the vertices it fits mesh storage as-is, which is why BVH leaves in CPU and GPU tracers use it as the primitive test.
When to choose it
Reach for it when
- need to know which triangle a mouse ray hits
- ray casting against a triangle mesh for picking
- getting barycentric coordinates of a ray hit
- writing my own ray tracer leaf test
- cpu raycast misses thin triangle edges
Choose it as the default leaf test for ray tracing, picking and CPU collision queries over triangle soups. Prefer three-mesh-bvh when you want it already wired into a BVH for three.js picking, and SAH BVH construction for the acceleration structure around it. Prefer watertight intersection variants when thin-edge leaks between adjacent triangles are unacceptable. Prefer Sphere Tracing when the surface is an SDF instead of a mesh.
Field marks
- Rays passing exactly through a shared edge or vertex can slip through both neighbouring triangles because of rounding, leaving pinholes
- Grazing rays with a tiny determinant give noisy t and barycentrics; the epsilon threshold also discards legitimate near-parallel hits
- Self-intersection acne when secondary rays start on a surface without an offset or t-min
- Single-precision error grows far from the origin, so large world coordinates make hits jitter unless vertices are rebased
Presets
Möller–Trumbore picking a spinning tetrahedron
{
"eps": 0.000001,
"spin": 0.6
}Show GLSL (51 lines)
// GLSL ES 3.0, Shadertoy-style. Moller-Trumbore ray/triangle test on a spinning tetrahedron.
const float EPS = 1e-6;
const float SPIN = 0.6;
bool mollerTrumbore(vec3 o, vec3 d, vec3 a, vec3 b, vec3 c, out float t, out vec2 uv) {
vec3 e1 = b - a, e2 = c - a;
vec3 p = cross(d, e2);
float det = dot(e1, p);
if (abs(det) < EPS) return false; // ray parallel to triangle plane
float inv = 1.0 / det;
vec3 s = o - a;
float u = dot(s, p) * inv;
if (u < 0.0 || u > 1.0) return false;
vec3 q = cross(s, e1);
float v = dot(d, q) * inv;
if (v < 0.0 || u + v > 1.0) return false;
t = dot(e2, q) * inv;
uv = vec2(u, v);
return t > EPS;
}
mat3 rotY(float a) { float c = cos(a), s = sin(a); return mat3(c, 0., -s, 0., 1., 0., s, 0., c); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 p = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.6, 3.2);
vec3 rd = normalize(vec3(p, -1.6));
mat3 R = rotY(iTime * SPIN);
vec3 V[4];
V[0] = R * vec3( 1.0, -0.7, 0.8);
V[1] = R * vec3(-1.0, -0.7, 0.8);
V[2] = R * vec3( 0.0, -0.7, -1.0);
V[3] = R * vec3( 0.0, 1.0, 0.0);
int I[12] = int[12](0,2,1, 0,1,3, 1,2,3, 2,0,3);
float best = 1e9; vec3 col = mix(vec3(0.05, 0.07, 0.12), vec3(0.35, 0.45, 0.6), p.y + 0.5);
for (int f = 0; f < 4; f++) {
vec3 a = V[I[3*f]], b = V[I[3*f+1]], c = V[I[3*f+2]];
float t; vec2 uv;
if (mollerTrumbore(ro, rd, a, b, c, t, uv) && t < best) {
best = t;
vec3 n = normalize(cross(b - a, c - a));
float lit = 0.25 + 0.75 * max(dot(n, normalize(vec3(0.5, 0.8, 0.6))), 0.0);
vec3 base = 0.5 + 0.5 * cos(6.2831 * (float(f) / 4.0 + vec3(0.0, 0.33, 0.67)));
float w = 1.0 - uv.x - uv.y;
float edge = smoothstep(0.0, 0.04, min(min(uv.x, uv.y), w));
col = base * lit * mix(0.35, 1.0, edge);
}
}
fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| moller-trumbore-tetrahedron | Tesla T4 1920x1080 | 5.73× baseline (light) · 0.189 ms / 0.191 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| moller-trumbore-tetrahedron | NVIDIA L4 1920x1080 | 4.62× baseline (light) · 0.073 ms / 0.075 ms · 2.6× faster on L4 | opengl-timer-query · Cross-architecture validation |
| moller-trumbore-tetrahedron | NVIDIA A100-SXM4-40GB 1920x1080 | 3.56× baseline (light) · 0.102 ms / 0.104 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): cited by Ray-Traced Prism Displacement Mapping.
Crosses
- SAH BVH construction: The BVH culls most triangles and hands the surviving leaves to the Möller–Trumbore test.
- three-mesh-bvh: Provides ray, closest-point and shape casts over indexed meshes using this test at the leaves.
Sources
- primaryTomas Möller, Ben Trumbore (1997). Fast, Minimum Storage Ray-Triangle Intersection. Journal of Graphics Tools.Verified via crossref · 2026-11-29doi:10.1080/10867651.1997.10487468
- implementationgkjohnson (2018). gkjohnson/three-mesh-bvh. A BVH implementation to speed up raycasting and enable spatial queries against three.js meshes.GitHub API · license MIT · 2026-11-29