---
id: "jump-flooding-algorithm"
title: "Jump Flooding Algorithm"
aliases: [JFA]
domain: "geometry"
stage: "geometry"
realtime: "realtime"
platforms: [webgl2, webgpu, desktop-gpu, cuda, mobile-gpu]
year_introduced: 2006
inputs: [texture]
outputs: [sdf, texture]
style: "both"
dynamic: "dynamic"
cost: "cheap"
authority: "Rong & Tan, 2006"
url: "https://texelatlas.vercel.app/t/jump-flooding-algorithm/"
sources_verified_at: "2026-11-29"
---
# Jump Flooding Algorithm (Rong & Tan, 2006)

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

## Reach for it when

- 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

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

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](https://texelatlas.vercel.app/t/exact-euclidean-distance-transform.md) when you need exact values and are happy on CPU or with a compute pass, and [SDF Modeling: CSG and Smooth Minimum](https://texelatlas.vercel.app/t/sdf-csg-smooth-min.md) for analytic shapes that need no baking.

## Cost

cheap — A fixed log2(resolution) number of full-screen passes; each is nine texture reads per pixel.
Measured GPU Weight: 5.55× baseline (light) — 0.1827 ms median / 0.1897 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 5.01× baseline (light) — 0.0796 ms median (2.3× faster on L4).
Ampere A100 scaling: 3.28× baseline (light) — 0.0945 ms median (1.93× faster on A100).

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

## Engine support

- unity: official — `Visual Effect Graph > Window > Visual Effects > Utilities > SDF Bake Tool (MeshToSDFBaker.JFA)` (evidence: https://github.com/Unity-Technologies/Graphics/blob/557f6ac22b948284f57ffae6a789751fd1f63620/Packages/com.unity.visualeffectgraph/Runtime/Utilities/SDF/MeshToSDFBaker.cs, checked 2026-12-01) — Requires the Visual Effect Graph package.

## Dataflow

- Inputs: texture
- Outputs: sdf, texture
- Platforms: webgl2, webgpu, desktop-gpu, cuda, mobile-gpu

## Presets

### Jump Flooding Algorithm (JFA) — Voronoi nearest-seed partitioning, Euclidean SDF isolines and glow (glsl-fragment; rendered 2026-11-30)

```json
{
  "ISO_FREQ": 26,
  "SEED_COUNT": 12,
  "GLOW_FALLOFF": 5.5,
  "OUTLINE_WIDTH": 0.032
}
```

```glsl
const float ISO_FREQ = 26.0; // P
const int SEED_COUNT = 12; // P
const float GLOW_FALLOFF = 5.5; // P
const float OUTLINE_WIDTH = 0.032; // P

float sdArc(vec2 p, vec2 sc, float ra, float rb) {
  p.x = abs(p.x);
  return ((sc.y * p.x > sc.x * p.y) ? length(p - sc * ra) : abs(length(p) - ra)) - rb;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  int nSeeds = clamp(SEED_COUNT, 3, 24);

  // Hero geometric seed contour (rotating segmented ring) + orbiting point seeds
  float a0 = iTime * 0.45;
  mat2 rot = mat2(cos(a0), -sin(a0), sin(a0), cos(a0));
  vec2 rp = rot * uv;
  float dRing = sdArc(rp, vec2(sin(2.15), cos(2.15)), 0.21, 0.016);
  float dBest = max(dRing, 0.0);
  float dSecond = 10.0;
  float bestId = 0.0;
  bool insideHero = (dRing < 0.0);

  for (int i = 1; i <= 24; i++) {
    if (i > nSeeds) break;
    float fi = float(i);
    float ang = fi * 2.39996 + iTime * (0.25 + 0.04 * mod(fi, 4.0));
    float rad = 0.14 + 0.30 * fract(fi * 0.381966);
    vec2 seed = vec2(cos(ang), sin(ang)) * rad;
    if (i == 1 && (iMouse.z > 0.5 || length(iMouse.xy) > 1.0)) {
      seed = (iMouse.xy - 0.5 * iResolution.xy) / iResolution.y;
    }
    float d = length(uv - seed);
    if (d < dBest) {
      dSecond = dBest;
      dBest = d;
      bestId = fi;
    } else if (d < dSecond) {
      dSecond = d;
    }
  }

  // Per-seed palette representing converged JFA nearest-seed ID buffer
  vec3 seedHue = (bestId < 0.5)
    ? vec3(0.24, 0.78, 0.96)
    : 0.48 + 0.42 * cos(6.2831853 * (bestId * 0.137 + vec3(0.0, 0.33, 0.67)));

  // Smooth Euclidean distance transform isoline rings + JFA Voronoi cell borders
  float freq = max(ISO_FREQ, 1.0);
  float iso = 0.5 + 0.5 * cos(dBest * freq * 6.2831853 - iTime * 2.4);
  float isoLine = smoothstep(0.86, 0.98, iso);
  float vorEdge = smoothstep(0.009, 0.002, dSecond - dBest);

  // Wide JFA distance-field outline & exponential glow around the hero contour
  float outW = max(OUTLINE_WIDTH, 0.004);
  float wideOutline = smoothstep(outW + 0.004, outW - 0.004, dRing) * (1.0 - smoothstep(0.004, -0.004, dRing));
  float glow = exp(-max(dRing, 0.0) * max(GLOW_FALLOFF, 0.5));

  vec3 fieldCol = seedHue * (0.18 + 0.42 * exp(-dBest * 3.8));
  fieldCol += seedHue * isoLine * 0.24 * exp(-dBest * 1.4);
  fieldCol = mix(fieldCol, vec3(0.92, 0.96, 1.0), vorEdge * 0.42);
  fieldCol += vec3(0.28, 0.84, 1.0) * glow * 0.55;
  fieldCol = mix(fieldCol, vec3(1.0, 0.78, 0.28), wideOutline * 0.92);

  // Crisp glowing seed cores
  float core = smoothstep(0.015, 0.006, dBest);
  if (insideHero) fieldCol = vec3(0.98, 0.99, 1.0);
  else if (bestId > 0.5) fieldCol = mix(fieldCol, vec3(1.0), core);

  fragColor = vec4(clamp(fieldCol, 0.0, 1.0), 1.0);
}
```

Attribution: MIT — written for this index

## Combines with

- [SDF Modeling: CSG and Smooth Minimum](https://texelatlas.vercel.app/t/sdf-csg-smooth-min.md): JFA bakes arbitrary raster shapes into a field that is combined with analytic SDFs.

## Sources

1. [primary] Guodong Rong, Tiow-Seng Tan (2006) Jump flooding in GPU with applications to Voronoi diagram and distance transform. Proceedings of the 2006 symposium on Interactive 3D graphics and games  - SI3D '06. https://doi.org/10.1145/1111411.1111431 (verified via crossref on 2026-11-29)
2. [tutorial] Ryan Kaplan Voronoi diagrams on the GPU. rykap.com. https://www.rykap.com/graphics/skew/2016/02/25/voronoi-diagrams (verified via http on 2026-11-29)

## Cite this entry

Texel. "Jump Flooding Algorithm." https://texelatlas.vercel.app/t/jump-flooding-algorithm/ (accessed 2026-12-01).
