Ray Marching and Signed Distance Fields
Render implicit shapes by stepping along a ray according to the nearest safe distance reported by an SDF.
Interactive playground
Tweak the operator or scene live so the article connects to an immediate visual result.
Ray marching and SDFs
Advance along a ray by the nearest safe distance reported by the signed distance field until you reach the surface.
Scene and step circles
Scene viewDistance field view
Result viewChanging the ray angle alters every step size because the distance field changes along the ray path.
Family
Rendering pipeline
Rasterization, visibility, and alternate image synthesis strategies such as ray marching.
Builds on
1 topic
Read these first if you want the surrounding pipeline context.
Unlocks
0 next topics
Use these follow-ups when you want to keep turning the image-processing pipeline forward.
Learning paths
1
This topic appears in curated graphics progressions so the next step is obvious.
Choose this over that
March implicit surfaces only when that representation helps
Ray marching is powerful for procedural implicit scenes, but it is not a replacement for every raster task.
Ray Marching and Signed Distance Fields
Choose this when: The scene is naturally described by distance fields or procedural signed-distance operations.
Choose something else when: Explicit triangles and the standard raster pipeline are the main setting.
Rasterization
Choose this when: You want the mainstream triangle pipeline with interpolation and depth buffering.
Choose something else when: Implicit distance estimates are the central abstraction.
Bezier Curves
Choose this when: The focus is still geometric shape construction rather than final image synthesis from an SDF.
Choose something else when: You are ready to render those shapes through an implicit field pipeline.
Problem
Triangles are not the only way to describe geometry. Procedural and implicit scenes can be easier to express as distance-to-surface functions, but then the renderer needs a different strategy to find hits.
Intuition
A signed distance field tells you how far you are from the nearest surface, with sign indicating inside versus outside. Ray marching uses that value as a safe step size, advancing along the ray until the distance becomes tiny enough to count as a hit.
Core idea
- Cast a ray through the scene.
- Query the SDF at the current point to get a conservative step size.
- Advance by that step and repeat until you either hit the surface or exceed a maximum distance or step count.
- Estimate normals from the SDF nearby once you have a hit point.
Worked example
A circle or rounded box can be described analytically by an SDF. Ray marching repeatedly jumps toward the surface, often requiring only a modest number of steps when the field is well-behaved.
Complexity
The cost depends on the number of steps per ray, which depends on scene structure, epsilon thresholds, and maximum distance limits. It is not as predictably fixed as triangle rasterization.
When to choose it
- Choose it for implicit or procedural scenes where SDFs are a natural representation.
- Choose rasterization for traditional triangle-heavy real-time pipelines.
- It is great for smooth constructive shape logic, but not a drop-in replacement for every geometry workflow.
Key takeaways
- Ray marching relies on the distance field to pick safe step sizes.
- SDFs make constructive implicit modeling elegant.
- The method can produce beautiful procedural results with relatively compact code.
- Its performance profile depends on how many steps rays need to converge.
Practice ideas
- Implement a 2D ray marcher for circles and boxes.
- Estimate normals from the SDF and add simple shading.
- Compare the representation trade-off between a triangle scene and an implicit SDF scene.
Relation to other topics
- Rasterization is the mainstream explicit-geometry alternative.
- Bezier curves describe explicit parametric geometry, not implicit distance fields.
- Shadow logic can also be phrased in ray-marched terms for SDF scenes, though the tooling differs from shadow mapping.
Build on these first
These topics supply the mental model or preceding stage that this page assumes.
Related directions
These topics live nearby conceptually, even if they are not strict prerequisites.
Bezier Curves
Describe smooth parametric curves with control points so paths and shapes can be edited intuitively.
Rasterization
Turn geometric primitives such as triangles into covered screen pixels so the rendering pipeline can shade actual fragments.
Shadow Mapping
Use a depth map from the light’s point of view to decide whether a visible surface point is blocked from that light.
More from Rendering pipeline
Stay in the same family when you want parallel operators built from the same mental model.
Rasterization
Turn geometric primitives such as triangles into covered screen pixels so the rendering pipeline can shade actual fragments.
Barycentric Interpolation
Blend per-vertex attributes across a triangle so every covered fragment gets a sensible color, depth, or texture coordinate.
Z-Buffer
Resolve which fragment is actually visible at each pixel by keeping only the smallest depth seen so far.
Paths that include this topic
Follow one of these sequences if you want a guided next step instead of open-ended browsing.
Geometry and alternate rendering
Bridge parametric geometry with implicit surfaces and ray-marched rendering ideas.
From the blog
Pair the graphics atlas with recent writing from the broader site whenever you want a wider engineering lens.