{
 "id": "voxel-grid-dda-traversal",
 "title": "Voxel grid DDA ray traversal (Amanatides–Woo)",
 "aliases": [
  "DDA grid traversal",
  "3D DDA",
  "Amanatides-Woo"
 ],
 "domain": "geometry",
 "subdomain": "grid ray traversal",
 "stage": "geometry",
 "realtime": "realtime",
 "platforms": [
  "cpu",
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda"
 ],
 "year_introduced": 1987,
 "inputs": [
  "voxels"
 ],
 "outputs": [
  "depth",
  "normals"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "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.",
 "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": "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-voxel-meshing` when you want a rasterised mesh instead, `volume-ray-marching` for density integration, and `three-mesh-bvh` when the primitives are triangles.",
 "cost": {
  "class": "cheap",
  "notes": "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."
 },
 "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:http://www.cse.yorku.ca/~amana/research/grid.pdf",
   "type": "web",
   "title": "A Fast Voxel Traversal Algorithm for Ray Tracing",
   "authors": [
    "John Amanatides",
    "Andrew Woo"
   ],
   "year": null,
   "venue": "cse.yorku.ca",
   "url": "http://www.cse.yorku.ca/~amana/research/grid.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261018231913/https://www.cse.yorku.ca/~amana/research/grid.pdf",
     "timestamp": "20261018231913"
    },
    "page_title": null,
    "host": "cse.yorku.ca",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET http://www.cse.yorku.ca/~amana/research/grid.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET http://www.cse.yorku.ca/~amana/research/grid.pdf → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "amanatidesfast"
  }
 ],
 "presets": [
  {
   "id": "voxel-dda-terrain",
   "title": "DDA traversal of a procedural voxel heightfield",
   "runtime": "glsl-fragment",
   "params": {
    "max_steps": 96,
    "half_extent": 9
   },
   "code": "// GLSL ES 3.0, Shadertoy-style. Amanatides-Woo voxel traversal through a procedural heightfield grid.\nconst int MAX_STEPS = 96;\nconst float HALF = 9.0;\n\nbool solid(ivec3 c) {\n  if (abs(float(c.x)) > HALF || abs(float(c.z)) > HALF || c.y < 0) return false;\n  float x = float(c.x), z = float(c.z);\n  float h = 2.0 + 1.5 * sin(x * 0.55) * cos(z * 0.45) + 0.08 * (x * x + z * z) * 0.25;\n  return float(c.y) < h;\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 p = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float a = 0.3 * iTime;\n  vec3 ro = vec3(14.0 * sin(a), 9.0, 14.0 * cos(a));\n  vec3 fw = normalize(vec3(0.0, 1.5, 0.0) - ro);\n  vec3 rt = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));\n  vec3 up = cross(rt, fw);\n  vec3 rd = normalize(fw * 1.4 + rt * p.x + up * p.y);\n  rd += vec3(1e-5);                        // avoid exact zeros in 1/rd\n\n  ivec3 cell = ivec3(floor(ro));\n  vec3 stp = sign(rd);\n  vec3 tDelta = abs(1.0 / rd);\n  vec3 tMax = (vec3(cell) + step(0.0, rd) - ro) / rd;\n  vec3 mask = vec3(0.0);\n  bool hit = false;\n  for (int i = 0; i < MAX_STEPS; i++) {\n    if (solid(cell)) { hit = true; break; }\n    mask = vec3(lessThanEqual(tMax.xyz, min(tMax.yzx, tMax.zxy)));\n    tMax += mask * tDelta;\n    cell += ivec3(mask * stp);\n  }\n  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));\n  if (hit) {\n    vec3 n = -mask * stp;\n    float hgt = float(cell.y) / 5.0;\n    vec3 base = mix(vec3(0.25, 0.5, 0.2), vec3(0.75, 0.7, 0.6), hgt);\n    float lit = 0.35 + 0.65 * max(dot(n, normalize(vec3(0.4, 0.9, 0.3))), 0.0);\n    float chk = mod(float(cell.x + cell.y + cell.z), 2.0);\n    col = base * lit * (0.88 + 0.12 * chk);\n  }\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "voxel-grid-dda-traversal",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6495,
      "std": 0.0797,
      "unique_colors": 27
     },
     "image": "/specimens/voxel-dda-terrain.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "sphere-tracing",
  "volume-ray-marching",
  "greedy-voxel-meshing",
  "nanovdb",
  "openvdb"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "nanovdb",
   "why": "A hierarchical DDA over NanoVDB's tree skips empty space while using the same cell-stepping logic."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/geometry/voxel-grid-dda-traversal.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Amanatides & Woo",
 "url": "https://texelatlas.vercel.app/t/voxel-grid-dda-traversal/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 18.83,
  "tier": "moderate",
  "p50_ms": 0.6194,
  "p95_ms": 0.6541,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "voxel-dda-terrain",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 16.63,
   "tier": "moderate",
   "p50_ms": 0.2644,
   "p95_ms": 0.2802,
   "speedup_x": 2.34,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 13.73,
   "tier": "moderate",
   "p50_ms": 0.3954,
   "p95_ms": 0.4189,
   "speedup_x": 1.57,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}