{
 "id": "jump-flooding-algorithm",
 "title": "Jump Flooding Algorithm",
 "aliases": [
  "JFA"
 ],
 "domain": "geometry",
 "subdomain": "distance transform",
 "stage": "geometry",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cuda",
  "mobile-gpu"
 ],
 "year_introduced": 2006,
 "inputs": [
  "texture"
 ],
 "outputs": [
  "sdf",
  "texture"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Approximates a Voronoi diagram or distance transform on a pixel grid in O(log n) full-screen passes by propagating nearest-seed information in halving strides. Fast on GPUs and very good for outlines, glows and SDF baking.",
 "how_it_works": "Initialise a texture where seed pixels store their own coordinates and others store 'none'. Run passes with step length N/2, N/4, ..., 1. In each pass every pixel looks at nine samples at offsets of plus or minus the step (and zero) in x and y, takes the stored seed position of each neighbour, and keeps the seed that is closest to the pixel itself. After the final pass each pixel holds an approximate nearest seed, from which the distance is computed. An extra pass with step 1 (JFA+1) or 2 reduces errors. For a signed field, run it twice on the shape and its complement and subtract. Pixels with ties and bottlenecks occasionally keep a wrong seed.",
 "when_to_use": "Choose it for GPU-side distance fields in screen space or 2D textures: outlines, soft glows, fonts, 2D shadows and radiance-cascade seed fields. Prefer `exact-euclidean-distance-transform` when you need exact values and are happy on CPU or with a compute pass, and `sdf-csg-smooth-min` for analytic shapes that need no baking.",
 "cost": {
  "class": "cheap",
  "notes": "A fixed log2(resolution) number of full-screen passes; each is nine texture reads per pixel."
 },
 "failure_modes": [
  "Rare wrong-nearest-seed errors that show as small speckles and discontinuities, especially with sparse seeds",
  "Distance values are approximate, not exact Euclidean",
  "Cost and precision depend on float format; 8-bit targets cannot store coordinates for large textures",
  "Seeds that are thin or close together can vanish under the stride pattern"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1111411.1111431",
   "type": "paper",
   "title": "Jump flooding in GPU with applications to Voronoi diagram and distance transform",
   "authors": [
    "Guodong Rong",
    "Tiow-Seng Tan"
   ],
   "year": 2006,
   "venue": "Proceedings of the 2006 symposium on Interactive 3D graphics and games  - SI3D '06",
   "url": "https://doi.org/10.1145/1111411.1111431",
   "ids": {
    "doi": "10.1145/1111411.1111431"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1111411.1111431",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1111411.1111431",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1111411.1111431",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1111411.1111431",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1111411.1111431",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "rong2006jump"
  },
  {
   "role": "tutorial",
   "key": "url:https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams",
   "type": "tutorial",
   "title": "Voronoi diagrams on the GPU",
   "authors": [
    "Ryan Kaplan"
   ],
   "year": null,
   "venue": "rykap.com",
   "url": "https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261025193735/https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams/",
     "timestamp": "20261025193735"
    },
    "page_title": "Voronoi Diagrams on the GPU",
    "host": "rykap.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams → 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 https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams → 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": 1,
   "__bib": "kaplanvoronoi"
  }
 ],
 "presets": [
  {
   "id": "jump-flooding-algorithm-live",
   "title": "Jump Flooding Algorithm (JFA) — Voronoi nearest-seed partitioning, Euclidean SDF isolines and glow",
   "runtime": "glsl-fragment",
   "params": {
    "ISO_FREQ": 26,
    "SEED_COUNT": 12,
    "GLOW_FALLOFF": 5.5,
    "OUTLINE_WIDTH": 0.032
   },
   "basis": "original",
   "license_note": "MIT — written for this index",
   "code": "const float ISO_FREQ = 26.0; // P\nconst int SEED_COUNT = 12; // P\nconst float GLOW_FALLOFF = 5.5; // P\nconst float OUTLINE_WIDTH = 0.032; // P\n\nfloat sdArc(vec2 p, vec2 sc, float ra, float rb) {\n  p.x = abs(p.x);\n  return ((sc.y * p.x > sc.x * p.y) ? length(p - sc * ra) : abs(length(p) - ra)) - rb;\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  int nSeeds = clamp(SEED_COUNT, 3, 24);\n\n  // Hero geometric seed contour (rotating segmented ring) + orbiting point seeds\n  float a0 = iTime * 0.45;\n  mat2 rot = mat2(cos(a0), -sin(a0), sin(a0), cos(a0));\n  vec2 rp = rot * uv;\n  float dRing = sdArc(rp, vec2(sin(2.15), cos(2.15)), 0.21, 0.016);\n  float dBest = max(dRing, 0.0);\n  float dSecond = 10.0;\n  float bestId = 0.0;\n  bool insideHero = (dRing < 0.0);\n\n  for (int i = 1; i <= 24; i++) {\n    if (i > nSeeds) break;\n    float fi = float(i);\n    float ang = fi * 2.39996 + iTime * (0.25 + 0.04 * mod(fi, 4.0));\n    float rad = 0.14 + 0.30 * fract(fi * 0.381966);\n    vec2 seed = vec2(cos(ang), sin(ang)) * rad;\n    if (i == 1 && (iMouse.z > 0.5 || length(iMouse.xy) > 1.0)) {\n      seed = (iMouse.xy - 0.5 * iResolution.xy) / iResolution.y;\n    }\n    float d = length(uv - seed);\n    if (d < dBest) {\n      dSecond = dBest;\n      dBest = d;\n      bestId = fi;\n    } else if (d < dSecond) {\n      dSecond = d;\n    }\n  }\n\n  // Per-seed palette representing converged JFA nearest-seed ID buffer\n  vec3 seedHue = (bestId < 0.5)\n    ? vec3(0.24, 0.78, 0.96)\n    : 0.48 + 0.42 * cos(6.2831853 * (bestId * 0.137 + vec3(0.0, 0.33, 0.67)));\n\n  // Smooth Euclidean distance transform isoline rings + JFA Voronoi cell borders\n  float freq = max(ISO_FREQ, 1.0);\n  float iso = 0.5 + 0.5 * cos(dBest * freq * 6.2831853 - iTime * 2.4);\n  float isoLine = smoothstep(0.86, 0.98, iso);\n  float vorEdge = smoothstep(0.009, 0.002, dSecond - dBest);\n\n  // Wide JFA distance-field outline & exponential glow around the hero contour\n  float outW = max(OUTLINE_WIDTH, 0.004);\n  float wideOutline = smoothstep(outW + 0.004, outW - 0.004, dRing) * (1.0 - smoothstep(0.004, -0.004, dRing));\n  float glow = exp(-max(dRing, 0.0) * max(GLOW_FALLOFF, 0.5));\n\n  vec3 fieldCol = seedHue * (0.18 + 0.42 * exp(-dBest * 3.8));\n  fieldCol += seedHue * isoLine * 0.24 * exp(-dBest * 1.4);\n  fieldCol = mix(fieldCol, vec3(0.92, 0.96, 1.0), vorEdge * 0.42);\n  fieldCol += vec3(0.28, 0.84, 1.0) * glow * 0.55;\n  fieldCol = mix(fieldCol, vec3(1.0, 0.78, 0.28), wideOutline * 0.92);\n\n  // Crisp glowing seed cores\n  float core = smoothstep(0.015, 0.006, dBest);\n  if (insideHero) fieldCol = vec3(0.98, 0.99, 1.0);\n  else if (bestId > 0.5) fieldCol = mix(fieldCol, vec3(1.0), core);\n\n  fragColor = vec4(clamp(fieldCol, 0.0, 1.0), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "jump-flooding-algorithm",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:15:34.232Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4763,
      "std": 0.2062,
      "unique_colors": 1679
     },
     "image": "/specimens/jump-flooding-algorithm-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "exact-euclidean-distance-transform",
  "sdf-csg-smooth-min"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "sdf-csg-smooth-min",
   "why": "JFA bakes arbitrary raster shapes into a field that is combined with analytic SDFs."
  }
 ],
 "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/jump-flooding-algorithm.json"
 },
 "solves": [
  "need a fast gpu distance field from a texture",
  "wide uniform outlines around objects",
  "glow or soft 2d shadows from seed pixels",
  "voronoi diagram on the gpu in few passes",
  "bake a signed distance field quickly"
 ],
 "authority": "Rong & Tan, 2006",
 "url": "https://texelatlas.vercel.app/t/jump-flooding-algorithm/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 5.55,
  "tier": "light",
  "p50_ms": 0.1827,
  "p95_ms": 0.1897,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "jump-flooding-algorithm-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 5.01,
   "tier": "light",
   "p50_ms": 0.0796,
   "p95_ms": 0.0815,
   "speedup_x": 2.3,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 3.28,
   "tier": "light",
   "p50_ms": 0.0945,
   "p95_ms": 0.0953,
   "speedup_x": 1.93,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}