---
id: "moller-trumbore-ray-triangle"
title: "Möller–Trumbore ray-triangle intersection"
aliases: [Moller-Trumbore, MT intersection]
domain: "geometry"
stage: "geometry"
realtime: "realtime"
platforms: [cpu, webgl2, webgpu, desktop-gpu, cuda]
year_introduced: 1997
inputs: [mesh]
outputs: [depth]
style: "both"
dynamic: "both"
cost: "cheap"
authority: "Möller & Trumbore, 1997"
url: "https://texelatlas.vercel.app/t/moller-trumbore-ray-triangle/"
sources_verified_at: "2026-11-29"
---
# Möller–Trumbore ray-triangle intersection (Möller & Trumbore, 1997)

> 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.

## 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

## 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 use it

Choose it as the default leaf test for ray tracing, picking and CPU collision queries over triangle soups. Prefer [three-mesh-bvh](https://texelatlas.vercel.app/t/three-mesh-bvh.md) when you want it already wired into a BVH for three.js picking, and [SAH BVH construction](https://texelatlas.vercel.app/t/sah-bvh-construction.md) for the acceleration structure around it. Prefer watertight intersection variants when thin-edge leaks between adjacent triangles are unacceptable. Prefer [Sphere Tracing](https://texelatlas.vercel.app/t/sphere-tracing.md) when the surface is an SDF instead of a mesh.

## Cost

cheap — A few dozen flops per test; in practice traversal and memory access dominate, not this test.
Measured GPU Weight: 5.73× baseline (light) — 0.1885 ms median / 0.1913 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 4.62× baseline (light) — 0.0734 ms median (2.57× faster on L4).
Ampere A100 scaling: 3.56× baseline (light) — 0.1024 ms median (1.84× faster on A100).

## Failure modes

- 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

## Engine support

- babylonjs: builtin — `ray.intersectsTriangle() / scene.pick` (evidence: https://github.com/BabylonJS/Babylon.js/blob/9.38.0/packages/dev/core/src/Culling/ray.core.ts, checked 2026-12-01)
- blender: builtin — `Cycles ray-triangle intersection kernel in intern/cycles/kernel/geom/triangle_intersect.h` (evidence: https://github.com/blender/blender/blob/main/intern/cycles/kernel/geom/triangle_intersect.h, checked 2026-12-01)
- godot: builtin — `Geometry3D.ray_intersects_triangle(from, dir, a, b, c)` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/core/math/geometry_3d.h, checked 2026-12-01) — Engine source implements the Moller-Trumbore edge/determinant form.
- threejs: builtin — `Ray.intersectTriangle() / Raycaster` (evidence: https://github.com/mrdoob/three.js/blob/r187/src/math/Ray.js, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: depth
- Platforms: cpu, webgl2, webgpu, desktop-gpu, cuda

## Presets

### Möller–Trumbore picking a spinning tetrahedron (glsl-fragment; rendered 2026-11-29)

```json
{
  "eps": 0.000001,
  "spin": 0.6
}
```

```glsl
// 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

## Combines with

- [SAH BVH construction](https://texelatlas.vercel.app/t/sah-bvh-construction.md): The BVH culls most triangles and hands the surviving leaves to the Möller–Trumbore test.
- [three-mesh-bvh](https://texelatlas.vercel.app/t/three-mesh-bvh.md): Provides ray, closest-point and shape casts over indexed meshes using this test at the leaves.

## Sources

1. [primary] Tomas Möller, Ben Trumbore (1997) Fast, Minimum Storage Ray-Triangle Intersection. Journal of Graphics Tools. https://doi.org/10.1080/10867651.1997.10487468 (verified via crossref on 2026-11-29)
2. [implementation] gkjohnson (2018) gkjohnson/three-mesh-bvh. https://github.com/gkjohnson/three-mesh-bvh License: MIT. (verified via github on 2026-11-29)

## Cite this entry

Texel. "Möller–Trumbore ray-triangle intersection." https://texelatlas.vercel.app/t/moller-trumbore-ray-triangle/ (accessed 2026-12-01).
