Skip to content
ExtendedSource checked

Ray Marching

Renders by stepping along rays until they hit or pass through scene features.

Quick Facts

Compact metadata for implementation and discovery.

Category
Rendering
Difficulty
Advanced
Family
Ray-Based Rendering
Tier
Extended
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
4
Code example
Not ready
Visualization
Ready

Overview

Ray Marching samples points along a ray, often using distance estimates or volume density to decide how far to step.

Core Concepts

rendered imageray stepgeometric calculationray-based renderingscene representationvisibility testpixel output

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(p)

Average

O(p s)

Worst

O(p s)

Space

O(1)

When to Use

  • Use Ray Marching when you need to advance along camera rays in steps.
  • Use it for volumetric rendering with inputs like ray origin and direction.
  • Use it when the scene representation and quality target match the rendering tradeoff.
  • Use it when the Ray-Based Rendering tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when the cost per pixel or sample is too high for the desired frame rate.
  • Avoid it when the required output is not pixel color or hit result.

What It Does

  • Advances along camera rays in steps
  • Detects surfaces or accumulates volume contributions

Use Cases

  • Volumetric rendering
  • Signed distance fields
  • Procedural scenes

Inputs

  • Ray origin and direction
  • Distance or density function

Outputs

  • Pixel color or hit result

Key Formulas (1)

March step

pointnext = point + stepsize · raydirection
point_next = point + step_size * ray_direction

Samples a ray at regular or adaptive intervals.

Pseudocode

  1. 1.Create a camera ray
  2. 2.Sample or estimate the scene at the current point
  3. 3.Advance the ray by a chosen step
  4. 4.Stop on hit, opacity, or max distance
  5. 5.Shade the result

Canonical Example

Input
scene = one triangle, one camera, one light
Output
image pixels showing the visible triangle
Explanation
Ray Marching: The algorithm converts scene data into visible pixel results.

Implementation Notes

  • Keep the input contract explicit: Ray origin and direction; Distance or density function.
  • Use this step as the implementation spine: Create a camera ray.
  • Then preserve the next state change: Sample or estimate the scene at the current point.
  • Build tiny scenes with known geometry before testing complex materials or lighting.

Common Pitfalls

  • Step strategy controls both image quality and performance.
  • Ignoring coordinate spaces, depth precision, or sampling noise while debugging image artifacts.
  • Returning pixel color or hit result without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show rays advancing through space in repeated steps.

Ray Marching mechanism walkthrough step 1 of 5
Step 1 of 5: Create a camera ray
ray-steps

Notes

Ray Marching operates in O(p s) time and O(1) space within the Ray-Based Rendering family. Key governing relation: point_next = point + step_size * ray_direction. Often compared with Sphere Tracing and Marching Cubes.

Sources (1)

What each reference supports for this entry.

Physically Based Rendering

Book

Rendering reference for light transport, ray tracing, sampling, BRDFs, acceleration structures, and path termination.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toRay Tracing

Ray marching samples along rays rather than solving explicit intersections.

GeneralizesSphere Tracing

Sphere tracing is a distance-field-guided form of ray marching.

Tags

GraphicsRay MarchingGeometry