Ray-marched Participating Media
Step along each view ray through a density field, accumulating emitted and in-scattered light weighted by transmittance; the general-purpose way to draw smoke, fog, clouds and fire.
Also known as volume ray marching, single-scattering volume rendering
In the family Atmosphere, water & volumes, ray marching
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { VolumeShader } from 'three/addons/shaders/VolumeShader.js'; TSL: RaymarchingBox from tsl/utils/Raymarching.js docs |
| Babylon.js 9.38.0 | None found | Built-in scene fog is analytic distance/exponential fog; general volumetric ray marching requires a custom shader. |
| Godot 4.7 | Built in | Environment.volumetric_fog_enabled = true with FogVolume and FogMaterial (density, density_texture, albedo) docs |
| Unity | Built in | HDRP Volume > Add Override > Fog > Volumetric Fog (VolumetricLighting.compute integrates density and scattering along jittered view rays) docs HDRP only. |
| Unreal 5.7 | Built in | Heterogeneous Volume component (volumetric material ray marched); also Volumetric Cloud docs |
| Blender 5.2 | Built in | Properties > Render > Volumes > Biased (enable), then Step Rate / Max Steps (Cycles) docs |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
At each step of length dt the ray gains radiance equal to the in-scattered light times local density, attenuated by the transmittance accumulated so far; the transmittance then decays by exp(-sigma_t dt). The in-scattered light at a point is the light's radiance reduced by a secondary march toward the light (or a shadow map or cached shadow volume), times a phase function. Choose step size from density and distance, add per-pixel jitter (blue noise) to turn banding into noise, and stop early when transmittance falls under a threshold. For a density that comes from a 3D texture you can skip empty space with a coarse occupancy or min/max grid. Emission is added for fire. Because density is sampled along a ray this is a Riemann-sum solution of the radiative transfer equation and is biased by step size, unlike unbiased delta tracking.
When to choose it
Reach for it when
- need to draw smoke, fog or fire from a density field
- want procedural clouds in a shader
- visualise medical or simulation volume data
- light should scatter through participating media
Choose it for any dynamic volume you can sample cheaply: procedural clouds, smoke from a fluid sim, shadertoy-style fog, or volumetric medical data.
Prefer Froxel Volumetric Fog when the volume is a global fog with many lights. Prefer Delta (Woodcock) Tracking when you need unbiased results and heterogeneous media offline. Prefer Nubis-style Ray-marched Volumetric Clouds for sky-scale clouds with an authored pipeline. Prefer OpenVDB or NanoVDB for sparse simulation data.
Field marks
- Banding stripes from regular step spacing when jitter is missing
- Missed thin features when step size exceeds the feature width
- Lighting that is only single-scatter, so thick media look too dark
- Cost explosion in dense media because secondary light marches multiply the step count
- Inconsistent results when step size varies with distance and density is not integrated analytically per step
Presets
Emission-absorption volume ray marching of a noisy fireball
{
"STEPS": 64,
"SIGMA_T": 5
}Show GLSL (37 lines)
// Emission-absorption volume ray marching: front-to-back accumulation with Beer-Lambert transmittance,
// 64 fixed steps through a noise-modulated density ball with a hot emissive core.
const int STEPS = 64;
const float SIGMA_T = 5.0;
float h31(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }
float vn(vec3 x) {
vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
return mix(mix(mix(h31(i), h31(i + vec3(1, 0, 0)), f.x), mix(h31(i + vec3(0, 1, 0)), h31(i + vec3(1, 1, 0)), f.x), f.y),
mix(mix(h31(i + vec3(0, 0, 1)), h31(i + vec3(1, 0, 1)), f.x), mix(h31(i + vec3(0, 1, 1)), h31(i + vec3(1, 1, 1)), f.x), f.y), f.z);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, 3.5), rd = normalize(vec3(uv, -1.8));
vec3 bg = mix(vec3(0.02, 0.02, 0.04), vec3(0.08, 0.1, 0.16), uv.y + 0.5);
float b = dot(ro, rd); float hh = b * b - dot(ro, ro) + 1.44;
vec3 col = bg;
if (hh > 0.0) {
float t0 = -b - sqrt(hh), t1 = -b + sqrt(hh); float ds = (t1 - t0) / float(STEPS);
float T = 1.0; vec3 L = vec3(0.0);
for (int i = 0; i < STEPS; i++) {
vec3 p = ro + rd * (t0 + (float(i) + 0.5) * ds);
float r = length(p);
vec3 q = p * 2.2 + vec3(0.0, -iTime * 0.6, 0.0);
float n = 0.55 * vn(q) + 0.3 * vn(q * 2.1) + 0.15 * vn(q * 4.3);
float d = clamp((1.0 - r / 1.2) * 1.6 + (n - 0.5) * 1.2, 0.0, 1.0) * SIGMA_T;
float heat = clamp(1.0 - r / 0.8, 0.0, 1.0) * n * 2.0;
vec3 em = mix(vec3(0.15, 0.1, 0.09), vec3(2.2, 0.9, 0.25), heat) * d;
L += T * em * ds;
T *= exp(-d * ds);
}
col = bg * T + L;
}
col = 1.0 - exp(-col * 1.6);
fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}
Attribution: written for this index
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| volume-ray-marching-specimen | Tesla T4 1920x1080 | 391× baseline (extreme) · 12.8 ms / 13.0 ms | opengl-timer-query · 20 frames · GPU Weight Atlas · Colab T4 sweep |
| volume-ray-marching-specimen | NVIDIA L4 1920x1080 | 328× baseline (extreme) · 5.22 ms / 5.37 ms · 2.5× faster on L4 | opengl-timer-query · Cross-architecture validation |
| volume-ray-marching-specimen | NVIDIA A100-SXM4-40GB 1920x1080 | 273× baseline (extreme) · 7.87 ms / 7.94 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Henyey-Greenstein Phase Function, Instant Radiosity (Virtual Point Lights), Delta (Woodcock) Tracking, Multi-Scale 3D Diffusive Volumetric Irradiance, Deep shadow maps, Practical Path Guiding, OpenVDB, Lightcuts, Continuous-Wavelength Hero and Single-Wavelength Spectral Dispersion.
Crosses
- OpenVDB: Reads density from sparse grids with ray-grid traversal that skips inactive space.
- Henyey-Greenstein Phase Function: Weights the in-scattered light at each step.
Sources
- primaryJan Novák, Iliyan Georgiev, Johannes Hanika, Wojciech Jarosz (2018). Monte Carlo Methods for Volumetric Light Transport Simulation. Computer Graphics Forum.Verified via crossref · 2026-11-29doi:10.1111/cgf.13383
- tutorialMatt Pharr, Wenzel Jakob, Greg Humphreys. Media (Physically Based Rendering, 4th ed.). pbr-book.org.Verified via live page · 2026-11-29
- implementationGökay Aydoğan (2026). gokayfem/glsl-studies. 454 procedural graphics studies in GLSL ES 3.00 for WebGL2, from woven cloth and animal fur to glacial terrain and atmospheric optics. Each study includes shader source and a rendered preview.GitHub API · license MIT · 2026-11-30