Voxel grid DDA ray traversal (Amanatides–Woo)
Walks a ray through a regular grid one cell at a time in strict order using two vectors, the distance to the next boundary on each axis and the distance between boundaries, so no cell is missed or visited twice.
Also known as DDA grid traversal, 3D DDA, Amanatides-Woo
In the family Geometry, meshing & signed distance fields, grid ray traversal
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | VoxelGI uses mipmapped voxel cone tracing rather than exposing a general-purpose voxel DDA ray-traversal primitive. |
| Unity | None found | No built-in 3D Amanatides-Woo voxel grid DDA ray-traversal API. |
| Unreal 5.7 | None found | No built-in voxel DDA traversal. |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Convert the ray origin to its starting cell and find, for each axis, the step direction (±1) and tMax, the ray parameter at which it crosses the first cell boundary on that axis. Also compute tDelta, the ray parameter needed to cross one whole cell on each axis. Each iteration tests the current cell, then advances along the axis with the smallest tMax: bump that component of the cell index by its step and add its tDelta to tMax. The axis you just stepped across gives the face normal, and the smaller tMax before stepping gives the hit distance. Everything is integer indexing plus min comparisons, making it ideal for shaders. It also works for voxel picking, line-of-sight, light propagation and traversing hierarchical grids (octrees) if you step at the right level.
When to choose it
Reach for it when
- ray marching through voxel grid skips cells at corners
- need to pick a block with the mouse in a voxel world
- fast line of sight test through a grid
- cast rays against a voxel chunk in a shader
Choose it for ray casting through dense or sparse voxel grids, volume marching with an occupancy test, and block picking. Prefer Sphere Tracing when the data is a distance field and you can skip empty space in big jumps, Greedy meshing for voxel worlds when you want a rasterised mesh instead, Ray-marched Participating Media for density integration, and three-mesh-bvh when the primitives are triangles.
Field marks
- Division by zero or NaN tMax when a ray direction component is exactly 0, unless guarded by a small epsilon or an infinity convention
- Rays that start exactly on a cell boundary or at the grid edge can pick the wrong first cell
- Long empty stretches cost one step per cell, so large sparse worlds stall without a two-level grid or octree
- Floating-point drift over very long rays can skip a cell at corners; rebase the origin per chunk
Presets
DDA traversal of a procedural voxel heightfield
{
"max_steps": 96,
"half_extent": 9
}Show GLSL (45 lines)
// GLSL ES 3.0, Shadertoy-style. Amanatides-Woo voxel traversal through a procedural heightfield grid.
const int MAX_STEPS = 96;
const float HALF = 9.0;
bool solid(ivec3 c) {
if (abs(float(c.x)) > HALF || abs(float(c.z)) > HALF || c.y < 0) return false;
float x = float(c.x), z = float(c.z);
float h = 2.0 + 1.5 * sin(x * 0.55) * cos(z * 0.45) + 0.08 * (x * x + z * z) * 0.25;
return float(c.y) < h;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 p = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float a = 0.3 * iTime;
vec3 ro = vec3(14.0 * sin(a), 9.0, 14.0 * cos(a));
vec3 fw = normalize(vec3(0.0, 1.5, 0.0) - ro);
vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
vec3 up = cross(rt, fw);
vec3 rd = normalize(fw * 1.4 + rt * p.x + up * p.y);
rd += vec3(1e-5); // avoid exact zeros in 1/rd
ivec3 cell = ivec3(floor(ro));
vec3 stp = sign(rd);
vec3 tDelta = abs(1.0 / rd);
vec3 tMax = (vec3(cell) + step(0.0, rd) - ro) / rd;
vec3 mask = vec3(0.0);
bool hit = false;
for (int i = 0; i < MAX_STEPS; i++) {
if (solid(cell)) { hit = true; break; }
mask = vec3(lessThanEqual(tMax.xyz, min(tMax.yzx, tMax.zxy)));
tMax += mask * tDelta;
cell += ivec3(mask * stp);
}
vec3 col = mix(vec3(0.55, 0.7, 0.9), vec3(0.15, 0.2, 0.35), clamp(p.y + 0.6, 0.0, 1.0));
if (hit) {
vec3 n = -mask * stp;
float hgt = float(cell.y) / 5.0;
vec3 base = mix(vec3(0.25, 0.5, 0.2), vec3(0.75, 0.7, 0.6), hgt);
float lit = 0.35 + 0.65 * max(dot(n, normalize(vec3(0.4, 0.9, 0.3))), 0.0);
float chk = mod(float(cell.x + cell.y + cell.z), 2.0);
col = base * lit * (0.88 + 0.12 * chk);
}
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 |
|---|---|---|---|
| voxel-dda-terrain | Tesla T4 1920x1080 | 18.8× baseline (moderate) · 0.619 ms / 0.654 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| voxel-dda-terrain | NVIDIA L4 1920x1080 | 16.6× baseline (moderate) · 0.264 ms / 0.280 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| voxel-dda-terrain | NVIDIA A100-SXM4-40GB 1920x1080 | 13.7× baseline (moderate) · 0.395 ms / 0.419 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Overhang-capable voxel erosion with pipe-model water: Interactive hydraulic erosion that carves real 3D caves, undercut banks, and collapsing arches instead of flat 2.5D heightfields. A fast pipe-model water solver drives surface runoff and scouring, a mass-conserving 3D Margolus cellular automaton moves loosened sand and rock voxels through overhangs, and exact DDA ray traversal renders the evolving volume with zero remeshing.
- NanoVDB: A hierarchical DDA over NanoVDB's tree skips empty space while using the same cell-stepping logic.
Sources
- primaryJohn Amanatides, Andrew Woo. A Fast Voxel Traversal Algorithm for Ray Tracing. cse.yorku.ca.Verified via live page · 2026-11-29