Ray marching is a class of rendering methods for
3D computer graphics
3D computer graphics, or “3D graphics,” sometimes called CGI, 3D-CGI or three-dimensional computer graphics are graphics that use a three-dimensional representation of geometric data (often Cartesian) that is stored in the computer for t ...
where
rays are traversed iteratively, effectively dividing each ray into smaller ray segments, sampling some function at each step. This function can encode volumetric data for
volume ray casting
Volume ray casting, sometimes called volumetric ray casting, volumetric ray tracing, or volume ray marching, is an image-based volume rendering technique. It computes 2D images from 3D volumetric data sets (3D scalar fields). Volume ray casting, ...
, distance fields for accelerated intersection finding of surfaces, among other information.
Distance-aided ray marching
Sphere tracing

In sphere tracing, or sphere-assisted ray marching an intersection point is approximated between the ray and a surface defined by a
signed distance function
In mathematics and its applications, the signed distance function (or oriented distance function) is the orthogonal distance of a given point ''x'' to the boundary of a set Ω in a metric space, with the sign determined by whether or not ''x' ...
(SDF). The SDF is evaluated for each iteration in order to be able take as large steps as possible without missing any part of the surface. A threshold is used to cancel further iteration when a point has reached that is close enough to the surface. As powerful
GPU
A graphics processing unit (GPU) is a specialized electronic circuit designed to manipulate and alter memory to accelerate the creation of images in a frame buffer intended for output to a display device. GPUs are used in embedded systems, mob ...
hardware became more widely available, this method was popularized by the
demoscene
The demoscene is an international computer art subculture focused on producing demos: self-contained, sometimes extremely small, computer programs that produce audiovisual presentations. The purpose of a demo is to show off programming, visua ...
and Inigo Quilez.
Signed distance functions exist for many primitive 3D shapes. They can be combined using mathematical operations like
modulo and
booleans to form more complex surfaces. For instance, taking the modulus of an SDF's input coordinates tiles its volume across all of space, and taking the maximum of two SDFs gives their volumes' surface of intersection. Because SDFs can be defined for many fractals, sphere tracing is often used for 3D fractal rendering.
Cube-assisted
A similar technique to sphere-assisted ray marching, the use of cubes and
taxicab distance
A taxicab geometry or a Manhattan geometry is a geometry whose usual distance function or metric of Euclidean geometry is replaced by a new metric in which the distance between two points is the sum of the absolute differences of their Cartesian ...
can be used to render voxel volumes.
Volumetric ray marching
In volumetric ray marching, each ray is traced so that color and/or density can be sampled along the ray and then be combined into a final pixel color. This is often used for example when rendering clouds or 3D medical scans.
Deferred shading
When rendering screen space effects, such as
screen space reflection
Reflection in computer graphics is used to emulate reflective objects like mirrors and shiny surfaces.
Accurate reflections can be accomplished e.g. by a ray trace renderer by following a ray from the eye to the mirror and then calculating whe ...
(SSR) and screen space shadows, rays are traced using
G-buffers, where depth and
surface normal
In geometry, a normal is an object such as a line, ray, or vector that is perpendicular to a given object. For example, the normal line to a plane curve at a given point is the (infinite) line perpendicular to the tangent line to the curve ...
data is stored per each 2D pixel.
External links
The 1989 paper Hypertexture
by
Ken Perlin
Kenneth H. Perlin is a professor in the Department of Computer Science at New York University, founding director of the Media Research Lab at NYU, director of the Future Reality Lab at NYU, and the Director of the Games for Learning Institute. He ...
contains an early example of a ray marching method.
References
{{refs
3D imaging
Computer graphics algorithms