Home▸Articles▸Rendering & Computer Graphics

2D Ray Marching: Sphere Tracing & Signed Distance Field Rendering

A powerful technique in computer graphics for rendering 3D scenes in real-time with high detail and efficiency.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What is Ray Marching?

Ray marching, a technique in computer graphics, involves tracing rays from the viewer through the scene to determine what objects they intersect. Each ray is marched along its path, checking for intersections with objects at regular intervals until it either hits an object or reaches a predefined distance.

In 2D, this process can be used to render shapes and scenes by calculating distances to surfaces using signed distance fields (SDFs), which represent the shortest distance from any point in space to the nearest surface of an object.

Signed Distance Fields (SDFs)

A signed distance field is a mathematical function that assigns to each point in 3D space the shortest distance to the boundary of an object, with positive values for points outside and negative values for points inside. This concept allows for precise and efficient rendering of complex shapes.

In ray marching, SDFs are used to determine how far along a ray one needs to march before hitting an object, enabling accurate visualization without needing to explicitly trace the entire path.

live demo · related simulation● LIVE

Sphere Tracing

Sphere tracing is a method for rendering 3D scenes by using spheres as proxies for objects. Instead of marching rays directly through the scene, sphere tracing checks if a ray intersects with a bounding sphere around an object and then calculates the exact intersection point.

This technique can be highly efficient because it only requires checking intersections with bounding spheres, which are simpler to compute than detailed 3D models.

CSG Operations in Ray Marching

Boolean operations like union, subtract, and intersect are used to combine different shapes in ray marching. These operations allow for the creation of complex scenes from simple geometric primitives.

By applying these operations on SDFs representing individual objects, the resulting SDF can be used to render the combined shape accurately.

Frequently asked questions

How does sphere tracing improve rendering efficiency?

Sphere tracing improves efficiency by using bounding spheres to quickly determine if a ray intersects with an object. This reduces the number of detailed intersection calculations needed, making the process faster and more efficient.

What is the role of signed distance fields in ray marching?

Signed distance fields provide a way to efficiently calculate distances from any point to the nearest surface of an object. This information is crucial for determining where rays intersect with objects, enabling precise rendering without complex geometry.

Can sphere tracing be used for 3D scenes?

Yes, sphere tracing can be extended to 3D scenes by using bounding spheres around 3D objects. This technique is particularly useful in real-time applications where performance and efficiency are critical.

How does CSG (Constructive Solid Geometry) work with ray marching?

CSG operations combine simple geometric shapes to create more complex scenes. In the context of ray marching, these operations are applied on SDFs to generate a new SDF that represents the combined shape, allowing for efficient rendering of intricate 3D models.

Try it live

Everything above runs in your browser — open 2D Ray Marching — Sphere Tracing & SDF Explainer and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open 2D Ray Marching — Sphere Tracing & SDF Explainer simulation

What did you find?

Add reproduction steps (optional)