Jump Flooding Algorithm
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.
Also known as JFA
In the family Geometry, meshing & signed distance fields, distance transform
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 | No built-in Jump Flooding Algorithm compute or shader pass. |
| Unity | Official add-on | Visual Effect Graph > Window > Visual Effects > Utilities > SDF Bake Tool (MeshToSDFBaker.JFA) docs Requires the Visual Effect Graph package. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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 choose it
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
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 Modeling: CSG and Smooth Minimum for analytic shapes that need no baking.
Field marks
- 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
Presets
Jump Flooding Algorithm (JFA) — Voronoi nearest-seed partitioning, Euclidean SDF isolines and glow
{
"ISO_FREQ": 26,
"SEED_COUNT": 12,
"GLOW_FALLOFF": 5.5,
"OUTLINE_WIDTH": 0.032
}Show GLSL (72 lines)
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
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| jump-flooding-algorithm-live | Tesla T4 1920x1080 | 5.55× baseline (light) · 0.183 ms / 0.190 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| jump-flooding-algorithm-live | NVIDIA L4 1920x1080 | 5.01× baseline (light) · 0.080 ms / 0.082 ms · 2.3× faster on L4 | opengl-timer-query · Cross-architecture validation |
| jump-flooding-algorithm-live | NVIDIA A100-SXM4-40GB 1920x1080 | 3.28× baseline (light) · 0.095 ms / 0.095 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- SDF Modeling: CSG and Smooth Minimum: JFA bakes arbitrary raster shapes into a field that is combined with analytic SDFs.
Sources
- primaryGuodong 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.Verified via crossref · 2026-11-29doi:10.1145/1111411.1111431