Segment Tracing
Ray marching that uses local Lipschitz bounds over ray segments instead of a global bound, so it can safely trace fields that are not distance functions (warped, displaced, procedural) with long, efficient steps.
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 | No built-in Lipschitz-bounded segment tracer. |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Sphere tracing needs the global Lipschitz constant of the field to be 1. For general functions F, a safe step along the ray is the field value divided by a Lipschitz bound valid on the segment that will be covered. Segment tracing computes that bound locally: it estimates the bound over a segment starting at the current point (from the function's structure, e.g. through interval-friendly primitives and operators that propagate local bounds), and uses it to jump while still not missing the root. Because the bound only needs to hold in the region the step could reach, it is far tighter than a global constant, and long steps are possible far from the surface. It also gives a clean way to handle blending, displacement and domain deformations with provable correctness.
When to choose it
Reach for it when
- ray marching overshoots on warped or noisy fields
- distance function isn't exact so marching artefacts appear
- displaced sdf needs tiny steps and runs slowly
- smooth blends with large radii break the marcher
- trace non-distance fields safely with long steps
Choose it when your function is built from operators that break exact distances (smooth blends with large radii, warps, noise displacement) and sphere tracing either overshoots or needs very small step factors. Prefer Sphere Tracing or Enhanced Sphere Tracing for exact SDF primitives and Marching Cubes when you want a mesh rather than per-pixel evaluation.
Field marks
- Requires the modelling language to expose local Lipschitz bounds for every operator
- Implementation is more complex than a one-line step
- Bound estimation can be conservative and eat the speed-up on rough noise displacements
- Needs per-primitive analysis to avoid very loose bounds
Presets
Segment Tracing — global-Lipschitz sphere tracing steps (left) vs accelerated local-Lipschitz segment tracing (right)
{
"P_LIPSCHITZ_GAIN": 1,
"P_HEATMAP": 0.78,
"P_SPLIT": 0.48,
"P_WAVE_AMP": 0.85
}Show GLSL (123 lines)
const float P_LIPSCHITZ_GAIN = 1.0; // P Local Bound Gain [0.2, 1.5, 0.04]
const float P_HEATMAP = 0.78; // P Step Heatmap Mix [0.0, 1.0, 0.02]
const float P_SPLIT = 0.48; // P Sphere / Segment [0.0, 1.0, 0.02]
const float P_WAVE_AMP = 0.85; // P Field Gradient [0.2, 1.5, 0.04]
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
// Non-unit-Lipschitz implicit surface f(p) = 0 (gyroid-modulated metaball cluster with steep local gradient!)
float evalField(vec3 p, float amp, float spin) {
vec3 q = p;
q.xz = rot2(spin * 0.32) * q.xz;
q.yz = rot2(0.25) * q.yz;
float dBase = length(q) - 0.82;
// High-frequency gyroid displacement whose global Lipschitz constant is large (~1 + 4.5*amp),
// but whose local directional gradient |grad(f).rd| is tiny in empty space and along tangent rays!
float freq = 5.2;
float g = sin(q.x * freq) * cos(q.y * freq) + sin(q.y * freq) * cos(q.z * freq) + sin(q.z * freq) * cos(q.x * freq);
float env = exp(-max(dBase, 0.0) * 1.4);
return dBase + 0.14 * amp * g * env;
}
// Analytical directional gradient magnitude |grad(f) . rd| along ray segment for Segment Tracing bound
float localDirLipschitz(vec3 p, vec3 rd, float amp, float spin) {
float e = 0.025;
float df = abs(evalField(p + rd * e, amp, spin) - evalField(p - rd * e, amp, spin)) / (2.0 * e);
// Conservative safety floor over segment interval
return max(df * 1.18, 0.72);
}
vec3 calcNormal(vec3 p, float amp, float spin) {
vec2 e = vec2(0.0025, 0.0);
return normalize(vec3(
evalField(p + e.xyy, amp, spin) - evalField(p - e.xyy, amp, spin),
evalField(p + e.yxy, amp, spin) - evalField(p - e.yxy, amp, spin),
evalField(p + e.yyx, amp, spin) - evalField(p - e.yyx, amp, spin)
));
}
// Turbo-like step-count heatmap (deep blue = few fast steps, cyan/green = moderate, amber/red = heavy iteration cost)
vec3 stepHeatmap(float s) {
s = clamp(s, 0.0, 1.0);
vec3 c0 = vec3(0.06, 0.14, 0.38);
vec3 c1 = vec3(0.10, 0.72, 0.84);
vec3 c2 = vec3(0.96, 0.78, 0.16);
vec3 c3 = vec3(0.98, 0.18, 0.24);
if (s < 0.35) return mix(c0, c1, s / 0.35);
if (s < 0.70) return mix(c1, c2, (s - 0.35) / 0.35);
return mix(c2, c3, (s - 0.70) / 0.30);
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
float lipGain = clamp(P_LIPSCHITZ_GAIN, 0.15, 1.6);
float heatMix = clamp(P_HEATMAP, 0.0, 1.0);
float amp = clamp(P_WAVE_AMP, 0.15, 1.6);
float spin = iTime;
vec3 ro = vec3(0.0, 0.05, 2.48);
vec3 rd = normalize(vec3(uv, -1.52));
bool isSegment = screenX >= split;
// Global worst-case Lipschitz constant required for conservative Sphere Tracing
float globalLip = 1.0 + 2.45 * amp;
float t = 0.0;
bool hit = false;
int steps = 0;
const int MAX_STEPS = 72;
for (int i = 0; i < MAX_STEPS; i++) {
steps = i + 1;
vec3 p = ro + rd * t;
float f = evalField(p, amp, spin);
if (f < 0.0025) { hit = true; break; }
float stepSize;
if (!isSegment) {
// Standard Sphere Tracing: forced to divide by global worst-case Lipschitz bound everywhere!
stepSize = f / globalLip;
} else {
// Segment Tracing: compute tight local directional Lipschitz bound over candidate segment!
float locLip = mix(globalLip, localDirLipschitz(p, rd, amp, spin), clamp(lipGain, 0.0, 1.0));
stepSize = f / max(locLip, 0.55);
}
t += max(stepSize, 0.004);
if (t > 6.0) break;
}
float stepNorm = float(steps) / float(MAX_STEPS);
vec3 heatCol = stepHeatmap(stepNorm);
// Background shows the marching step-count cost in empty silhouette space (where Segment Tracing shines brightest!)
vec3 bgCol = mix(vec3(0.03, 0.04, 0.068), vec3(0.08, 0.11, 0.16), smoothstep(-0.55, 0.55, uv.y));
vec3 col = mix(bgCol, heatCol * 0.72, heatMix * 0.85);
if (hit) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p, amp, spin);
vec3 l1 = normalize(vec3(0.62, 0.86, 0.55));
vec3 l2 = normalize(vec3(-0.75, -0.22, 0.52));
float diff1 = max(dot(n, l1), 0.0);
float diff2 = max(dot(n, l2), 0.0);
vec3 hVec = normalize(l1 - rd);
float spec = pow(max(dot(n, hVec), 0.0), 42.0) * 0.48;
float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.28;
vec3 surfBase = mix(vec3(0.76, 0.78, 0.82), heatCol, heatMix * 0.78);
col = surfBase * (0.26 + 0.84 * diff1 + 0.24 * diff2) + vec3(spec) + vec3(0.45, 0.75, 1.0) * rim;
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| segment-tracing-live | Tesla T4 1920x1080 | 24.8× baseline (heavy) · 0.778 ms / 0.794 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| segment-tracing-live | NVIDIA L4 1920x1080 | 23.8× baseline (heavy) · 0.376 ms / 0.380 ms · 2.1× faster on L4 | opengl-timer-query · Cross-architecture validation |
| segment-tracing-live | NVIDIA A100-SXM4-40GB 1920x1080 | 15.5× baseline (moderate) · 0.445 ms / 0.458 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- SDF Modeling: CSG and Smooth Minimum: Provides the operators whose local bounds it propagates.
Sources
- primaryEric Galin, Eric Guérin, Axel Paris, Adrien Peytavie (2020). Segment Tracing Using Local Lipschitz Bounds. Computer Graphics Forum.Verified via crossref · 2026-11-29doi:10.1111/cgf.13951