Ray Marching
Ray marching renders 3D scenes by stepping rays forward through space. At each step, a signed distance function (SDF) tells us the distance to the nearest surface — we can safely advance by that amount without missing anything. The left panel shows a 2D cross-section: watch the marching circles grow as rays approach surfaces. The right panel renders the full 3D scene with lighting and shadows computed entirely from SDFs.
pn+1 = pn + d(pn) · r̂ · SDF(p) < ε ⇒ surface hit · n̂ = ∇SDF(p) / |∇SDF(p)|
What is ray marching?
Ray marching (also called sphere tracing) is a rendering technique where each pixel's color is determined by casting a ray from the camera and stepping it forward through the scene. Unlike ray tracing, which computes exact ray-surface intersections, ray marching uses a signed distance function (SDF) to determine how far it can safely step without passing through any surface. At each point along the ray, the SDF returns the distance to the nearest surface. We advance the ray by this distance, then query the SDF again. When the SDF returns a value below a small epsilon, we've hit a surface.
Signed distance functions
An SDF maps every point in space to the signed distance to the nearest surface: positive outside, negative inside, zero on the surface. Simple shapes have elegant SDFs — a sphere of radius r centered at the origin is simply |p| − r. A box is max(|p.x|−b.x, |p.y|−b.y, |p.z|−b.z). The beauty of SDFs is that they compose: the union of two shapes is min(d1, d2), intersection is max(d1, d2), and subtraction is max(d1, −d2). Smooth blending uses log-sum-exp or polynomial smooth minimum functions.
Computing normals and lighting
The surface normal at a hit point is simply the gradient of the SDF, computed by finite differences: sample the SDF at small offsets along each axis and take the normalized result. This gives perfect smooth normals even for complex implicit surfaces. With the normal in hand, standard Phong or Blinn-Phong lighting models apply. Shadows are computed by marching a ray from the hit point toward the light — if it hits another surface before reaching the light, the point is in shadow. Soft shadows use the ratio of SDF values to march distances.
Why the circles?
In the 2D cross-section view, each marching step is shown as a circle whose radius equals the SDF value at that point. This is the key insight of sphere tracing: since the SDF gives the distance to the nearest surface, a sphere (circle in 2D) of that radius centered at the current point is guaranteed to be empty. We can safely jump to the edge of this sphere along our ray direction. Near surfaces, the circles shrink rapidly, giving sub-pixel precision. Far from surfaces, the circles are large, allowing fast traversal of empty space.