---
id: "voxel-grid-dda-traversal"
title: "Voxel grid DDA ray traversal (Amanatides–Woo)"
aliases: [DDA grid traversal, 3D DDA, Amanatides-Woo]
domain: "geometry"
stage: "geometry"
realtime: "realtime"
platforms: [cpu, webgl2, webgpu, desktop-gpu, cuda]
year_introduced: 1987
inputs: [voxels]
outputs: [depth, normals]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Amanatides & Woo"
url: "https://texelatlas.vercel.app/t/voxel-grid-dda-traversal/"
sources_verified_at: "2026-11-29"
---
# Voxel grid DDA ray traversal (Amanatides–Woo) (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.

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

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

Choose it for ray casting through dense or sparse voxel grids, volume marching with an occupancy test, and block picking. Prefer [Sphere Tracing](https://texelatlas.vercel.app/t/sphere-tracing.md) when the data is a distance field and you can skip empty space in big jumps, [Greedy meshing for voxel worlds](https://texelatlas.vercel.app/t/greedy-voxel-meshing.md) when you want a rasterised mesh instead, [Ray-marched Participating Media](https://texelatlas.vercel.app/t/volume-ray-marching.md) for density integration, and [three-mesh-bvh](https://texelatlas.vercel.app/t/three-mesh-bvh.md) when the primitives are triangles.

## Cost

cheap — A few ALU ops per cell; total cost scales with the number of cells traversed, so large empty spaces need a hierarchy or distance-field skipping.
Measured GPU Weight: 18.83× baseline (moderate) — 0.6194 ms median / 0.6541 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 16.63× baseline (moderate) — 0.2644 ms median (2.34× faster on L4).
Ampere A100 scaling: 13.73× baseline (moderate) — 0.3954 ms median (1.57× faster on A100).

## Failure modes

- 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

## Dataflow

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

## Presets

### DDA traversal of a procedural voxel heightfield (glsl-fragment; rendered 2026-11-29)

```json
{
  "max_steps": 96,
  "half_extent": 9
}
```

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

## Combines with

- [NanoVDB](https://texelatlas.vercel.app/t/nanovdb.md): A hierarchical DDA over NanoVDB's tree skips empty space while using the same cell-stepping logic.

## Combination ideas

- [Overhang-capable voxel erosion with pipe-model water](https://texelatlas.vercel.app/ideas/margolus-voxel-erosion-pipe-water/)

## Sources

1. [primary] John Amanatides, Andrew Woo A Fast Voxel Traversal Algorithm for Ray Tracing. cse.yorku.ca. http://www.cse.yorku.ca/~amana/research/grid.pdf (verified via http on 2026-11-29)

## Cite this entry

Texel. "Voxel grid DDA ray traversal (Amanatides–Woo)." https://texelatlas.vercel.app/t/voxel-grid-dda-traversal/ (accessed 2026-12-01).
