home/ atoms/ raymarching-sphere-tracing

Raymarching finds ray–surface intersections by stepping along the ray using the SDF value as the safe step distance

A signed distance field (SDF) is a function that returns, for any point in space, the signed distance to the nearest surface (positive outside, negative inside). Raymarching (sphere tracing) renders SDF scenes with no polygon mesh: for each pixel a ray is cast from the camera, and at each step the SDF is evaluated at the current position. Its value is the minimum safe step size — nothing can be nearer than that — so advancing the ray by exactly that amount guarantees never overshooting a surface. The loop terminates when the distance falls below a small threshold (a hit) or the accumulated distance exceeds a far value (a miss); a typical loop runs up to ~128–255 steps. This brute-force spatial query replaces analytic ray–object intersection math, so it handles blended and procedural geometry that has no closed-form intersection formula — the scene is defined purely by its SDF. Surface normals at a hit are computed by finite differences of the SDF. As an implicit-surface method its lineage runs back to Ricci’s 1972 work on boolean implicit surfaces and early fractal raymarching, with IQ’s modern SDF results from 2007.

Examples

GLSL raymarch loop: float rayMarch(vec3 ro, vec3 rd) { float d = 0.0; for (int i = 0; i < 255; i++) { vec3 p = ro + rd * d; float dist = map(p); d += dist; if (dist < 0.001 || d > 100.0) break; } return d; } Each iteration steps by the SDF value at the current point; camera at (0,0,3) looking -Z toward a unit sphere at the origin converges after a few large-then-small steps.

Assessment

Explain why stepping by the SDF value never overshoots the surface, and name the two exit conditions of the marching loop. For a unit sphere at the origin with a camera at (0,0,3) looking -Z, trace the values t takes over the first three steps. Distinguish raymarching from analytic ray tracing and from rasterisation, and describe the max-step/threshold quality–performance trade-off.

“re-matching. Re-matching is basically the way I see it, it's a way to explore activity scene when you don't have a mathematical way to do queries to it”
corpus · inigo-quilez-live-coding-happy-jumping-video · chunk 3
“Raymarching SDFs (Signed Distance Fields) is slowly getting popular, because it's a simple, elegant and powerful way to represent 3D objects and even render 3D scenes.”
corpus · inigo-quilez-raymarching-signed-distance-fields-article · chunk 1
“A ray consists of an origin and direction”