{
 "id": "photon-mapping",
 "title": "Photon Mapping",
 "aliases": [
  "PM"
 ],
 "domain": "gi",
 "subdomain": "Density-estimation light transport",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "cuda"
 ],
 "year_introduced": 1996,
 "inputs": [
  "mesh",
  "material-params"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Shoots photons from lights into the scene, stores where they land, then estimates indirect and caustic radiance at shading points by looking at nearby photons. Biased but smooth and excellent for caustics.",
 "how_it_works": "Photon mapping splits rendering into two passes. In the **photon pass**, packets of flux are emitted from light sources and scattered through the scene by Russian roulette; each time a photon lands on a diffuse surface, its position, incoming direction and power are stored in a spatial structure (a kd-tree or a hash grid). A dedicated **caustic map** holds photons that went through specular bounces; a coarser **global map** holds the rest.\n\nIn the **render pass**, rays from the camera hit surfaces. At a hit, the renderer gathers the `k` nearest photons (or those within a radius), and divides their summed flux by the area of the search disk. That is a kernel density estimate of irradiance, multiplied by the BSDF. Caustics are read directly from the caustic map. Indirect diffuse is usually evaluated at one extra bounce (**final gathering**) so the photon map's low-frequency noise does not appear on screen.\n\nThe estimate is biased: radius blurs detail, and error only vanishes in the limit.",
 "when_to_use": "Choose it for caustics, light concentrated by glass or water, and smooth diffuse interreflection, especially where unbiased methods show intense noise.\n\nPrefer [progressive-photon-mapping](progressive-photon-mapping) when memory or fixed photon counts are a problem and you want convergence to the right answer. Prefer [path-tracing](path-tracing) for general scenes where a reference is needed. Prefer [vertex-connection-and-merging](vertex-connection-and-merging) when you want photon-style merging inside an MIS framework. Prefer [instant-radiosity](instant-radiosity) when only diffuse GI at interactive rates is needed.",
 "cost": {
  "class": "offline",
  "notes": "Photon tracing is cheap; the cost is in nearest-neighbour gathering and final gathering. GPU variants use grid hashing."
 },
 "failure_modes": [
  "Blotchy low-frequency noise and light leaking across thin walls or at corners because the search disk crosses geometry",
  "Fixed photon count fails to resolve fine caustic detail; sharp caustic edges are blurred",
  "Memory grows with photon count, and a map has to be rebuilt for any moving light or object",
  "Specular surfaces seen directly require explicit ray tracing; the map only represents diffuse reflectors"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1007/978-3-7091-7484-5_3",
   "type": "chapter",
   "title": "Global Illumination using Photon Maps",
   "authors": [
    "Henrik Wann Jensen"
   ],
   "year": 1996,
   "venue": "Eurographics",
   "url": "https://doi.org/10.1007/978-3-7091-7484-5_3",
   "ids": {
    "doi": "10.1007/978-3-7091-7484-5_3"
   },
   "license": null,
   "extra": {
    "csl_type": "book-chapter"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-7091-7484-5_3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-7091-7484-5_3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-7091-7484-5_3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-7091-7484-5_3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-7091-7484-5_3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "jensen1996global"
  },
  {
   "role": "tutorial",
   "key": "url:https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping",
   "type": "tutorial",
   "title": "Stochastic Progressive Photon Mapping (Physically Based Rendering, 3rd edition)",
   "authors": [
    "Matt Pharr",
    "Wenzel Jakob",
    "Greg Humphreys"
   ],
   "year": null,
   "venue": "pbr-book.org",
   "url": "https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260728205317/https://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping",
     "timestamp": "20260728205317"
    },
    "page_title": "Stochastic Progressive Photon Mapping",
    "host": "pbr-book.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping → 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://pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Stochastic_Progressive_Photon_Mapping → 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.95,
   "__bib": "pharrstochastic"
  },
  {
   "role": "implementation",
   "key": "gh:mmp/pbrt-v3",
   "type": "code",
   "title": "mmp/pbrt-v3",
   "description": "Source code for pbrt, the renderer described in the third edition of \"Physically Based Rendering: From Theory To Implementation\", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.",
   "authors": [
    "mmp"
   ],
   "year": 2015,
   "venue": "GitHub",
   "url": "https://github.com/mmp/pbrt-v3",
   "ids": {
    "repo": "mmp/pbrt-v3"
   },
   "license": "BSD-2-Clause",
   "extra": {
    "stars": 5094,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2023-09-03T11:38:00Z",
    "language": "C++",
    "homepage": "http://pbrt.org",
    "license_name": "BSD 2-Clause \"Simplified\" License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v3",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmp2015pbrt"
  }
 ],
 "presets": [
  {
   "id": "photon-mapping-live",
   "title": "Photon Mapping — sparse photon splats (left) vs cone-filtered k-NN caustic & GI gather (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_GATHER_RAD": 0.55,
    "P_CAUSTIC_GAIN": 1.35,
    "P_LIGHT_SWEEP": 0.75,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_GATHER_RAD = 0.55; // P Gather Radius [0.15, 1.2, 0.03]\nconst float P_CAUSTIC_GAIN = 1.35; // P Caustic Power [0.2, 2.5, 0.05]\nconst float P_LIGHT_SWEEP = 0.75; // P Light Motion [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Splats / Gather Split [0.0, 1.0, 0.02]\n\nfloat hash21(vec2 p) {\n  p = fract(p * vec2(127.1, 311.7));\n  p += dot(p, p + 34.5);\n  return fract(p.x * p.y);\n}\n\nvec2 hash22(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy);\n}\n\n// Cornell box with central dielectric glass sphere (matId=4) focusing a refractive caustic on floor\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.85, 1.0); // floor\n  float dCeil = 1.05 - p.y; if (dCeil < res.x) res = vec2(dCeil, 1.0);\n  float dBack = p.z + 1.35; if (dBack < res.x) res = vec2(dBack, 1.0);\n  float dLeft = p.x + 1.28; if (dLeft < res.x) res = vec2(dLeft, 2.0); // warm crimson wall\n  float dRight = 1.28 - p.x; if (dRight < res.x) res = vec2(dRight, 3.0); // cool teal wall\n\n  // Glass crystal sphere resting on floor\n  float dGlass = length(p - vec3(0.0, -0.43, -0.15)) - 0.42;\n  if (dGlass < res.x) res = vec2(dGlass, 4.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0022, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// Focused refractive caustic density from glass sphere at (0, -0.43, -0.15)\nvec3 evalCaustic(vec3 p, vec3 lPos, float gatherR) {\n  vec3 sphC = vec3(0.0, -0.43, -0.15);\n  vec3 toSph = normalize(sphC - lPos);\n  // Intersection of refracted chief ray with floor plane y = -0.85\n  float tF = (-0.85 - sphC.y) / min(toSph.y, -0.15);\n  vec2 focusXZ = sphC.xz + toSph.xz * tF * 0.82;\n\n  vec2 d = p.xz - focusXZ;\n  float r = length(d);\n  float sigma = 0.075 + 0.14 * gatherR;\n  // Subtle chromatic dispersion across R, G, B wavelengths (IOR 1.50, 1.52, 1.55)\n  float cR = exp(-pow(length(d - toSph.xz * 0.025) / (sigma * 0.95), 2.0));\n  float cG = exp(-pow(r / sigma, 2.0));\n  float cB = exp(-pow(length(d + toSph.xz * 0.025) / (sigma * 1.05), 2.0));\n  // Bright cusp ring typical of spherical aberration caustic\n  float ring = exp(-pow((r - 0.14) / (0.04 + 0.04 * gatherR), 2.0)) * 0.55;\n  float floorMask = smoothstep(-0.72, -0.84, p.y);\n  return (vec3(cR, cG, cB) * 1.65 + vec3(0.95, 0.88, 1.0) * ring) * floorMask;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isSmooth = screenX >= split;\n  float gatherR = clamp(P_GATHER_RAD, 0.12, 1.3);\n  float causGain = clamp(P_CAUSTIC_GAIN, 0.1, 2.8);\n  float sweep = iTime * max(P_LIGHT_SWEEP, 0.0);\n\n  vec3 lPos = vec3(0.42 * sin(sweep * 0.85), 0.96, -0.10 + 0.25 * cos(sweep * 0.6));\n\n  vec3 ro = vec3(0.0, -0.02, 2.28);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  vec3 col = vec3(0.02);\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.002) { hit = true; matId = h.y; break; }\n    t += h.x;\n    if (t > 9.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n\n    if (matId > 3.5) {\n      // Refractive glass sphere with Schlick Fresnel + internal caustic glint\n      vec3 v = -rd;\n      float nv = max(dot(n, v), 0.0);\n      float F = 0.04 + 0.96 * pow(1.0 - nv, 5.0);\n      vec3 rDir = reflect(rd, n);\n      vec3 tDir = refract(rd, n, 1.0 / 1.52);\n\n      // Sample room walls along reflected and refracted directions\n      vec3 envRefl = mix(vec3(0.14, 0.18, 0.24), vec3(0.95, 0.92, 0.85), smoothstep(0.1, 0.85, rDir.y));\n      vec3 wallTint = mix(vec3(0.88, 0.24, 0.18), vec3(0.14, 0.72, 0.78), smoothstep(-0.7, 0.7, tDir.x));\n      vec3 lDir = normalize(lPos - p);\n      float spec = pow(max(dot(n, normalize(lDir + v)), 0.0), 96.0);\n      col = mix(wallTint * 0.62 + vec3(0.22, 0.30, 0.36), envRefl, F) + vec3(1.4) * spec;\n    } else {\n      vec3 alb = vec3(0.76, 0.75, 0.73);\n      if (matId > 1.5 && matId < 2.5) alb = vec3(0.86, 0.22, 0.18);\n      if (matId > 2.5) alb = vec3(0.16, 0.70, 0.74);\n\n      vec3 lVec = lPos - p;\n      float lDist = length(lVec);\n      vec3 lDir = lVec / max(lDist, 1e-4);\n      float diff = max(dot(n, lDir), 0.0) / (0.65 + lDist * lDist * 0.38);\n\n      // Sphere shadow on floor (dark under glass except where focused caustic lands!)\n      vec3 oc = p - vec3(0.0, -0.43, -0.15);\n      float bS = dot(oc, lDir);\n      float cS = dot(oc, oc) - 0.42 * 0.42;\n      float sh = (bS < 0.0 && (bS * bS - cS) > 0.0) ? 0.16 : 1.0;\n\n      // Indirect diffuse photon-map bounce from red & teal walls\n      float leftProx = clamp(1.0 - (p.x + 1.28) * 0.55, 0.0, 1.0);\n      float rightProx = clamp(1.0 - (1.28 - p.x) * 0.55, 0.0, 1.0);\n      vec3 indirect = vec3(0.86, 0.22, 0.18) * leftProx * 0.28 + vec3(0.16, 0.70, 0.74) * rightProx * 0.28 + vec3(0.14);\n\n      vec3 caustic = evalCaustic(p, lPos, gatherR) * causGain;\n\n      if (!isSmooth) {\n        // Left side: discrete stored photon splats in the 3D photon map (visualizing pass-1 deposition)\n        vec2 cell = floor(p.xz * 24.0 + p.y * 12.0);\n        vec2 jitter = hash22(cell);\n        vec2 local = fract(p.xz * 24.0 + p.y * 12.0) - jitter;\n        float rDot = length(local);\n        float photonDot = smoothstep(0.24, 0.08, rDot);\n        float densityProb = clamp(length(caustic) * 0.55 + 0.18, 0.0, 1.0);\n        float keep = step(1.0 - densityProb, hash21(cell + 17.1));\n        vec3 splatCol = (length(caustic) > 0.12) ? (caustic * 2.2 + vec3(0.8, 0.85, 1.0) * 0.4) : (indirect * 2.4);\n        col = alb * (diff * sh * 0.72 + indirect * 0.35) + splatCol * photonDot * keep * 1.15;\n      } else {\n        // Right side: cone-filtered k-NN radiance estimate over the photon map\n        col = alb * (diff * sh * 0.85 + indirect * 0.92) + caustic * (0.45 + 0.55 * alb);\n      }\n\n      // Ceiling area emitter quad\n      if (p.y > 1.03 && length(p.xz - lPos.xz) < 0.28) {\n        col = vec3(3.2, 3.0, 2.7);\n      }\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "photon-mapping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:33.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.7197,
      "std": 0.1276,
      "min": 0.1255,
      "max": 0.9608
     },
     "image": "/specimens/photon-mapping-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "progressive-photon-mapping",
  "vertex-connection-and-merging",
  "instant-radiosity",
  "path-tracing"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "path-tracing",
   "why": "The camera pass uses ordinary path tracing for direct light and final gathering on the photon map."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/photon-mapping.json"
 },
 "solves": [
  "caustics under glass or water are missing",
  "path tracing struggles with light through specular surfaces",
  "need efficient indirect lighting with focused light paths",
  "pool of light patterns through refractive objects"
 ],
 "authority": "Jensen, 1996",
 "url": "https://texelatlas.vercel.app/t/photon-mapping/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 12.44,
  "tier": "moderate",
  "p50_ms": 0.3856,
  "p95_ms": 0.4101,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "photon-mapping-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 11.43,
   "tier": "moderate",
   "p50_ms": 0.1817,
   "p95_ms": 0.1834,
   "speedup_x": 2.12,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 7.24,
   "tier": "moderate",
   "p50_ms": 0.2086,
   "p95_ms": 0.209,
   "speedup_x": 1.85,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}