Enhanced Sphere Tracing
Sphere tracing with over-relaxation: step slightly beyond the safe distance and fall back only when consecutive spheres fail to overlap. Cuts iteration counts, especially for near-grazing rays, with a pixel-exact result.
In the family Geometry, meshing & signed distance fields, ray marching
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 | SDFGI uses standard distance-stepped sphere tracing rather than over-relaxation enhanced sphere tracing. |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Standard sphere tracing steps exactly by the distance d. Enhanced sphere tracing multiplies the step by a relaxation factor omega (around 1.2 to 1.6). After the step, it checks whether the new sphere still overlaps the previous one: the sum of the two radii must be at least the step length. If the check fails, it undoes the relaxation for that step and falls back to the safe step. It also uses the unrelaxed ray parameter with the smallest error to pick the best hit estimate. Automatic variants adapt omega per ray using the local curvature estimate. Some versions add a final refinement from the last spheres so grazing hits are resolved more precisely.
When to choose it
Reach for it when
- ray marching is slow at grazing angles
- too many iterations per pixel on distance fields
- want faster raymarcher without changing the result
- shader steps crawl along surfaces seen at a slant
- reduce march step count in an sdf scene
Choose it as a drop-in speed-up for any sphere-traced scene where fields are exact or conservative and you see slow grazing pixels. Prefer plain Sphere Tracing when your field is far from 1-Lipschitz and fall-backs would be constant, and Segment Tracing when you can supply local Lipschitz constants for warped or animated fields.
Field marks
- Overstep followed by backtrack wastes work on cluttered scenes
- Poorly chosen omega leads to rejected relaxations on every step and no gain
- Still assumes a Lipschitz-1 field; warps break the overlap test's guarantees
- Divergent step counts across a warp reduce GPU efficiency
Presets
Over-relaxed sphere tracing step counts vs plain sphere tracing
{
"MAX_STEPS": 48,
"OMEGA": 1.6,
"EPS": 0.001
}Show GLSL (33 lines)
// Over-relaxed sphere tracing (omega 1.6 with fallback): left = plain tracing steps, right = relaxed steps, same heat scale.
const int MAX_STEPS = 48;
const float OMEGA = 1.6;
const float EPS = 0.001;
float map(vec3 p) {
float s = length(p - vec3(-0.9, 0.0, 0.0)) - 0.8;
vec2 q = vec2(length(p.xz - vec2(1.0, 0.2)) - 0.8, p.y);
float t = length(q) - 0.25;
float b = p.y + 0.9;
return min(min(s, t), b);
}
vec3 heat(float x) { return clamp(vec3(1.5 * x, 1.5 - abs(3.0 * x - 1.5), 1.5 - 1.5 * x), 0.0, 1.0); }
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 1.0, -4.0), rd = normalize(vec3(uv.x, uv.y - 0.12, 1.4));
float om = uv.x > 0.0 ? OMEGA : 1.0;
float t = 0.0, prevR = 0.0, stepLen = 0.0; int n = 0; bool hit = false;
for (int i = 0; i < MAX_STEPS; i++) {
n = i;
float r = map(ro + rd * t);
if (om > 1.0 && stepLen > prevR + r) { // overshoot: back up to the last safe step
t += prevR - stepLen; stepLen = 0.0; prevR = 0.0; continue;
}
if (r < EPS * t + 0.0005) { hit = true; break; }
stepLen = om * r; prevR = r; t += stepLen;
if (t > 20.0) break;
}
vec3 col = heat(float(n) / float(MAX_STEPS));
if (!hit && t > 20.0) col *= 0.35;
col = mix(col, vec3(1.0), smoothstep(0.003, 0.0, abs(uv.x)));
fragColor = vec4(pow(col, vec3(0.6)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| enhanced-sphere-tracing-specimen | Tesla T4 1920x1080 | 11.7× baseline (moderate) · 0.383 ms / 0.390 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| enhanced-sphere-tracing-specimen | NVIDIA L4 1920x1080 | 10.1× baseline (moderate) · 0.161 ms / 0.168 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| enhanced-sphere-tracing-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 7.12× baseline (moderate) · 0.205 ms / 0.206 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- SDF Modeling: CSG and Smooth Minimum: Step bounds rely on the SDF being close to exact.
Sources
- primaryBenjamin Keinert, Henry Schäfer, Johann Korndörfer, Urs Ganse, Marc Stamminger (2014). Enhanced Sphere Tracing. Smart Tools and Apps for Graphics - Eurographics Italian Chapter Conference.Verified via doi.org · 2026-11-29doi:10.2312/stag.20141233