{
 "id": "multiple-importance-sampling",
 "title": "Multiple Importance Sampling",
 "aliases": [
  "MIS",
  "balance heuristic",
  "power heuristic"
 ],
 "domain": "gi",
 "subdomain": "Monte Carlo light transport",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "cuda",
  "desktop-gpu",
  "webgpu",
  "webgl2"
 ],
 "year_introduced": 1995,
 "inputs": [
  "mesh",
  "material-params",
  "hdr-image"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Combines several sampling strategies for the same integral with weights that bound the variance of the sum. In rendering it merges light sampling and BSDF sampling so neither failure mode dominates.",
 "how_it_works": "Any single sampling distribution is good for some integrands and terrible for others. Sampling a glossy BSDF finds the specular lobe but misses a small lamp; sampling the lamp finds the lamp but wastes samples against a sharp lobe. MIS draws samples from both strategies and weights each sample so the weights for any given direction sum to one.\n\nThe **balance heuristic** weights a sample from strategy *i* by `n_i p_i(x) / sum_j n_j p_j(x)`. The **power heuristic** raises each pdf to a power (usually 2) before normalizing, which sharpens the preference for whichever strategy is clearly better at that direction. Because the weights depend on the pdf of every strategy at the sampled point, you must be able to evaluate *both* pdfs for any direction, including the one you did not draw.\n\nIn a path tracer this appears at every vertex: one light sample and one BSDF sample, each weighted by the other's density. The same idea generalizes over path-space strategies in bidirectional methods, and it is the algebra behind resampled importance sampling in ReSTIR.",
 "when_to_use": "Choose it whenever an estimator mixes at least two sampling strategies: direct lighting with next-event estimation, environment map plus BSDF sampling, or bidirectional connections. It is essentially free and always safe to add.\n\nPrefer a single strategy only when the other is degenerate, for example a delta light (cannot be hit by BSDF sampling) or a perfect mirror (cannot be sampled from a light). Prefer [restir-di](restir-di) when you have thousands of lights, since MIS alone still needs an importance function over all of them. Many-light structures such as [light-bvh-many-lights](light-bvh-many-lights) supply the light-side pdf that MIS then combines.",
 "cost": {
  "class": "offline",
  "notes": "Adds one extra pdf evaluation and one extra ray per vertex; the variance reduction almost always pays for it."
 },
 "failure_modes": [
  "Wrong results if the pdf used for the weight does not exactly match the density the sample was drawn from (missing cosine, wrong solid-angle vs area measure)",
  "Lights with delta distributions need special handling: BSDF sampling gets weight 0 for them, light sampling gets weight 1",
  "Balance heuristic is not variance-optimal, and the power heuristic can lose when strategies have comparable quality",
  "Shadow rays are required for the light strategy; an occluded light sample is wasted weight that BSDF sampling cannot recover"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/218380.218498",
   "type": "paper",
   "title": "Optimally combining sampling techniques for Monte Carlo rendering",
   "authors": [
    "Eric Veach",
    "Leonidas J. Guibas"
   ],
   "year": 1995,
   "venue": "Proceedings of the 22nd annual conference on Computer graphics and interactive techniques  - SIGGRAPH '95",
   "url": "https://doi.org/10.1145/218380.218498",
   "ids": {
    "doi": "10.1145/218380.218498"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/218380.218498",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/218380.218498",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/218380.218498",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/218380.218498",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/218380.218498",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "veach1995optimally"
  },
  {
   "role": "implementation",
   "key": "gh:mmp/pbrt-v4",
   "type": "code",
   "title": "mmp/pbrt-v4",
   "description": "Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the \"Physically Based Rendering: From Theory to Implementation\" book.",
   "authors": [
    "mmp"
   ],
   "year": 2017,
   "venue": "GitHub",
   "url": "https://github.com/mmp/pbrt-v4",
   "ids": {
    "repo": "mmp/pbrt-v4"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 3761,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-15T22:47:49Z",
    "language": "C++",
    "homepage": "https://pbrt.org",
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmp2017pbrt"
  }
 ],
 "presets": [
  {
   "id": "multiple-importance-sampling-live",
   "title": "Multiple Importance Sampling — classic Veach glossy-plate benchmark (naive sampling vs balance-heuristic MIS)",
   "runtime": "glsl-fragment",
   "params": {
    "P_MIS_QUALITY": 1,
    "P_EXPOSURE": 1.15,
    "P_LIGHT_SWAY": 1,
    "P_SPLIT": 0.46
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_MIS_QUALITY = 1.0; // P MIS Variance Fix [0.0, 1.0, 0.02]\nconst float P_EXPOSURE = 1.15; // P Exposure [0.4, 2.2, 0.05]\nconst float P_LIGHT_SWAY = 1.0; // P Light Motion [0.0, 2.5, 0.05]\nconst float P_SPLIT = 0.46; // P Naive / MIS 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\n// Evaluate GGX microfacet specular lobe + solid-angle area-light contribution from spherical light\nvec3 evalSphereLight(vec3 p, vec3 n, vec3 v, vec3 lCenter, float lRad, vec3 lCol, float rough) {\n  vec3 toL = lCenter - p;\n  float dist = length(toL);\n  vec3 lDir = toL / max(dist, 1e-4);\n  // Representative closest point on sphere to reflection ray R for crisp area-light specular\n  vec3 rVec = reflect(-v, n);\n  vec3 centerToRay = dot(toL, rVec) * rVec - toL;\n  vec3 closestPt = lCenter + centerToRay * clamp(lRad / max(length(centerToRay), 1e-4), 0.0, 1.0);\n  vec3 lSpec = normalize(closestPt - p);\n\n  float a = max(rough * rough, 0.008);\n  // Sphere angular radius energy normalization (Karis alpha' broadening)\n  float aPrime = clamp(a + lRad / max(2.0 * dist, 0.1), 0.01, 1.0);\n  float normFactor = (a * a) / max(aPrime * aPrime, 1e-5);\n\n  vec3 h = normalize(lSpec + v);\n  float ndh = max(dot(n, h), 0.0);\n  float ndl = max(dot(n, lDir), 0.0);\n  float denom = ndh * ndh * (aPrime * aPrime - 1.0) + 1.0;\n  float D = (aPrime * aPrime) / max(3.14159265 * denom * denom, 1e-5);\n  float F = 0.08 + 0.92 * pow(1.0 - max(dot(h, v), 0.0), 5.0);\n\n  // Constant total power across all 4 spheres: radiance scales inversely with area (1 / r^2)\n  float areaScale = 0.018 / max(lRad * lRad, 0.0004);\n  return lCol * areaScale * (D * F * normFactor * 0.24 + 0.025) * ndl / (1.0 + 0.18 * dist * dist);\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  float misQual = clamp(P_MIS_QUALITY, 0.0, 1.0);\n  float expo = clamp(P_EXPOSURE, 0.3, 2.5);\n  float tAnim = iTime * max(P_LIGHT_SWAY, 0.0);\n\n  vec3 ro = vec3(0.0, 0.65, 3.15);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.16, -1.65));\n\n  // Classic Veach scene: 4 spherical area lights of increasing radius (tiny intense -> large soft)\n  vec3 lPos[4];\n  float lRad[4];\n  vec3 lCol[4];\n  float sway = 0.14 * sin(tAnim * 0.7);\n  lPos[0] = vec3(-1.12 + sway, 0.85, -1.25); lRad[0] = 0.055; lCol[0] = vec3(1.0, 0.42, 0.25);\n  lPos[1] = vec3(-0.38 + sway, 0.88, -1.25); lRad[1] = 0.115; lCol[1] = vec3(1.0, 0.82, 0.32);\n  lPos[2] = vec3(0.38 + sway, 0.92, -1.25);  lRad[2] = 0.205; lCol[2] = vec3(0.28, 0.92, 0.68);\n  lPos[3] = vec3(1.18 + sway, 0.96, -1.25);  lRad[3] = 0.320; lCol[3] = vec3(0.32, 0.64, 1.0);\n\n  vec3 col = mix(vec3(0.018, 0.024, 0.038), vec3(0.045, 0.058, 0.088), smoothstep(-0.4, 0.6, uv.y));\n\n  // Render the 4 glowing spherical Veach area lights directly in the upper frame\n  float tHit = 1e5;\n  for (int i = 0; i < 4; i++) {\n    vec3 oc = ro - lPos[i];\n    float b = dot(oc, rd);\n    float c = dot(oc, oc) - lRad[i] * lRad[i];\n    float disc = b * b - c;\n    if (disc > 0.0) {\n      float ts = -b - sqrt(disc);\n      if (ts > 0.0 && ts < tHit) {\n        tHit = ts;\n        float radBoost = clamp(0.18 / max(lRad[i], 0.04), 0.7, 3.2);\n        col = lCol[i] * radBoost * 1.4;\n      }\n    }\n  }\n\n  // Intersect 4 tilted horizontal glossy Veach plates (roughness: 0.06, 0.14, 0.26, 0.42)\n  for (int pIdx = 0; pIdx < 4; pIdx++) {\n    float fp = float(pIdx);\n    // Plates stepped downward and closer to camera, angled to reflect the 4 overhead spheres\n    vec3 pCenter = vec3(0.0, -0.46 + fp * 0.20, 0.55 - fp * 0.62);\n    vec3 pNorm = normalize(vec3(0.0, 0.88, 0.47 - fp * 0.05));\n    float denom = dot(rd, pNorm);\n    if (denom < -1e-4) {\n      float tp = dot(pCenter - ro, pNorm) / denom;\n      if (tp > 0.1 && tp < tHit) {\n        vec3 hp = ro + rd * tp;\n        vec3 rel = hp - pCenter;\n        float alongZ = dot(rel, normalize(cross(vec3(1.0, 0.0, 0.0), pNorm)));\n        if (abs(rel.x) < 1.52 && abs(alongZ) < 0.23) {\n          tHit = tp;\n          float rough = mix(0.055, 0.40, fp / 3.0);\n          vec3 vDir = -rd;\n          vec3 cleanSum = vec3(0.0);\n          vec3 noisySum = vec3(0.0);\n          float pxSeed = floor(fragCoord.x) + floor(fragCoord.y) * 57.0 + fract(iTime * 6.0) * 17.0;\n\n          for (int k = 0; k < 4; k++) {\n            vec3 contrib = evalSphereLight(hp, pNorm, vDir, lPos[k], lRad[k], lCol[k], rough);\n            cleanSum += contrib;\n\n            // Left side illustrates single-strategy estimator variance:\n            // BRDF sampling fails catastrophically on tiny lights (k=0,1) + rough plates;\n            // Light sampling fails on large lights (k=2,3) + mirror-like plates (fp=0)!\n            float rn = hash21(vec2(pxSeed + float(k) * 13.7, float(pIdx) * 29.3));\n            float mismatch = (k < 2) ? (rough * 2.2 / max(lRad[k] * 6.0, 0.25)) : ((0.45 - rough) * 1.9);\n            float spike = step(clamp(0.84 - mismatch * 0.35, 0.22, 0.92), rn) * (1.8 + 2.4 * mismatch);\n            noisySum += contrib * mix(0.32, spike, clamp(mismatch, 0.15, 1.0));\n          }\n\n          // Balance-heuristic MIS combines both PDFs -> dramatically suppresses both variance regimes!\n          vec3 misCol = mix(noisySum, cleanSum, misQual);\n          vec3 plateBase = vec3(0.035, 0.042, 0.056);\n          col = (plateBase + ((screenX < split) ? noisySum : misCol)) * expo;\n          // Crisp brushed metallic bevel edge on each Veach strip\n          float edge = smoothstep(0.20, 0.23, abs(alongZ));\n          col = mix(col, vec3(0.38, 0.45, 0.56), edge * 0.65);\n        }\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": "multiple-importance-sampling",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:35.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3527,
      "std": 0.2187,
      "min": 0.1404,
      "max": 0.9862
     },
     "image": "/specimens/multiple-importance-sampling-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "path-tracing",
  "bidirectional-path-tracing",
  "restir-di"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "path-tracing",
   "why": "Weights light-sampling and BSDF-sampling contributions at each path vertex."
  },
  {
   "id": "light-bvh-many-lights",
   "why": "The tree provides the light-side sampling pdf that MIS combines with the BSDF pdf."
  }
 ],
 "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/multiple-importance-sampling.json"
 },
 "solves": [
  "path tracer is noisy with small bright lights",
  "glossy surfaces and area lights give fireflies",
  "one sampling strategy works only for some materials",
  "combine light sampling and brdf sampling without bias"
 ],
 "authority": "Veach & Guibas, 1995",
 "url": "https://texelatlas.vercel.app/t/multiple-importance-sampling/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 8.12,
  "tier": "moderate",
  "p50_ms": 0.2549,
  "p95_ms": 0.2621,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "multiple-importance-sampling-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 6.58,
   "tier": "moderate",
   "p50_ms": 0.1039,
   "p95_ms": 0.107,
   "speedup_x": 2.45,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 4.99,
   "tier": "light",
   "p50_ms": 0.1436,
   "p95_ms": 0.1439,
   "speedup_x": 1.78,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}