{
 "id": "volume-ray-marching",
 "title": "Ray-marched Participating Media",
 "aliases": [
  "volume ray marching",
  "single-scattering volume rendering"
 ],
 "domain": "volumes",
 "subdomain": "ray marching",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "cpu"
 ],
 "year_introduced": 1984,
 "inputs": [
  "volume-density",
  "camera-poses"
 ],
 "outputs": [
  "radiance",
  "ldr-image"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "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.",
 "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_use": "Choose it for any dynamic volume you can sample cheaply: procedural clouds, smoke from a fluid sim, shadertoy-style fog, or volumetric medical data.\n\nPrefer `froxel-volumetric-fog` when the volume is a global fog with many lights. Prefer `delta-tracking` when you need unbiased results and heterogeneous media offline. Prefer `nubis-volumetric-clouds` for sky-scale clouds with an authored pipeline. Prefer `openvdb` or `nanovdb` for sparse simulation data.",
 "cost": {
  "class": "medium",
  "notes": "Scales with steps per pixel times light samples; empty-space skipping and early termination are the key savers."
 },
 "failure_modes": [
  "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1111/cgf.13383",
   "type": "paper",
   "title": "Monte Carlo Methods for Volumetric Light Transport Simulation",
   "authors": [
    "Jan Novák",
    "Iliyan Georgiev",
    "Johannes Hanika",
    "Wojciech Jarosz"
   ],
   "year": 2018,
   "venue": "Computer Graphics Forum",
   "url": "https://doi.org/10.1111/cgf.13383",
   "ids": {
    "doi": "10.1111/cgf.13383"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13383",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13383",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13383",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13383",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1111/cgf.13383",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "novk2018monte"
  },
  {
   "role": "tutorial",
   "key": "url:https://www.pbr-book.org/4ed/Volume_Scattering/Media",
   "type": "tutorial",
   "title": "Media (Physically Based Rendering, 4th ed.)",
   "authors": [
    "Matt Pharr",
    "Wenzel Jakob",
    "Greg Humphreys"
   ],
   "year": null,
   "venue": "pbr-book.org",
   "url": "https://www.pbr-book.org/4ed/Volume_Scattering/Media",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260620200452/https://pbr-book.org/4ed/Volume_Scattering/Media",
     "timestamp": "20260620200452"
    },
    "page_title": "Media",
    "host": "pbr-book.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": true
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://www.pbr-book.org/4ed/Volume_Scattering/Media → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://www.pbr-book.org/4ed/Volume_Scattering/Media → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.2857142857142857,
   "__bib": "pharrmedia"
  },
  {
   "role": "implementation",
   "key": "gh:gokayfem/glsl-studies",
   "ids": {
    "repo": "gokayfem/glsl-studies"
   },
   "type": "code",
   "title": "gokayfem/glsl-studies",
   "authors": [
    "Gökay Aydoğan"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/gokayfem/glsl-studies",
   "license": "MIT",
   "description": "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.",
   "extra": {
    "stars": 924,
    "stars_checked": "2026-11-30",
    "language": "GLSL",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-30T13:13:54Z",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    }
   },
   "status": "verified",
   "title_sim": null,
   "checked_at": "2026-11-30T21:49:39.376Z",
   "__bib": "aydoan2026gokayfem"
  }
 ],
 "presets": [
  {
   "id": "volume-ray-marching-specimen",
   "title": "Emission-absorption volume ray marching of a noisy fireball",
   "runtime": "glsl-fragment",
   "params": {
    "STEPS": 64,
    "SIGMA_T": 5
   },
   "code": "// Emission-absorption volume ray marching: front-to-back accumulation with Beer-Lambert transmittance,\n// 64 fixed steps through a noise-modulated density ball with a hot emissive core.\nconst int STEPS = 64;\nconst float SIGMA_T = 5.0;\n\nfloat h31(vec3 p) { p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nfloat vn(vec3 x) {\n  vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);\n  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),\n             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);\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  vec3 ro = vec3(0.0, 0.0, 3.5), rd = normalize(vec3(uv, -1.8));\n  vec3 bg = mix(vec3(0.02, 0.02, 0.04), vec3(0.08, 0.1, 0.16), uv.y + 0.5);\n  float b = dot(ro, rd); float hh = b * b - dot(ro, ro) + 1.44;\n  vec3 col = bg;\n  if (hh > 0.0) {\n    float t0 = -b - sqrt(hh), t1 = -b + sqrt(hh); float ds = (t1 - t0) / float(STEPS);\n    float T = 1.0; vec3 L = vec3(0.0);\n    for (int i = 0; i < STEPS; i++) {\n      vec3 p = ro + rd * (t0 + (float(i) + 0.5) * ds);\n      float r = length(p);\n      vec3 q = p * 2.2 + vec3(0.0, -iTime * 0.6, 0.0);\n      float n = 0.55 * vn(q) + 0.3 * vn(q * 2.1) + 0.15 * vn(q * 4.3);\n      float d = clamp((1.0 - r / 1.2) * 1.6 + (n - 0.5) * 1.2, 0.0, 1.0) * SIGMA_T;\n      float heat = clamp(1.0 - r / 0.8, 0.0, 1.0) * n * 2.0;\n      vec3 em = mix(vec3(0.15, 0.1, 0.09), vec3(2.2, 0.9, 0.25), heat) * d;\n      L += T * em * ds;\n      T *= exp(-d * ds);\n    }\n    col = bg * T + L;\n  }\n  col = 1.0 - exp(-col * 1.6);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "original",
   "license_note": "written for this index",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "volume-ray-marching",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4935,
      "std": 0.0893,
      "unique_colors": 69
     },
     "image": "/specimens/volume-ray-marching-specimen.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "delta-tracking",
  "froxel-volumetric-fog",
  "nubis-volumetric-clouds",
  "multiple-scattering-octaves",
  "openvdb"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "openvdb",
   "why": "Reads density from sparse grids with ray-grid traversal that skips inactive space."
  },
  {
   "id": "henyey-greenstein-phase-function",
   "why": "Weights the in-scattered light at each step."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/volume-ray-marching.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Novák et al., 2018",
 "url": "https://texelatlas.vercel.app/t/volume-ray-marching/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 390.5,
  "tier": "extreme",
  "p50_ms": 12.8474,
  "p95_ms": 13.0307,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 20,
  "preset_id": "volume-ray-marching-specimen",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 328.42,
   "tier": "extreme",
   "p50_ms": 5.2219,
   "p95_ms": 5.3735,
   "speedup_x": 2.46,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 273.19,
   "tier": "extreme",
   "p50_ms": 7.8679,
   "p95_ms": 7.9442,
   "speedup_x": 1.63,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}