{
 "id": "radiosity",
 "title": "Radiosity (Hemicube Form Factors)",
 "aliases": [
  "classical radiosity",
  "finite-element GI"
 ],
 "domain": "gi",
 "subdomain": "finite element GI",
 "stage": "lighting",
 "realtime": "offline",
 "platforms": [
  "cpu",
  "desktop-gpu"
 ],
 "year_introduced": 1984,
 "inputs": [
  "mesh",
  "material-params"
 ],
 "outputs": [
  "texture"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Divides surfaces into patches and solves a linear system for diffuse light exchange using form factors. View-independent; the solution can be stored in vertex colors or lightmaps.",
 "how_it_works": "Radiosity assumes every surface is a perfect diffuser, so the light leaving a patch does not depend on the viewer. Each patch `i` has a radiosity `B_i` equal to its emission plus its reflectance times the light arriving from every other patch, `sum_j F_ij B_j`. `F_ij` are **form factors**: the fraction of light leaving `i` that lands directly on `j`. That is a linear system `B = E + R F B`.\n\nForm factors come from geometry. The **hemicube** method places a half cube on patch `i`, renders the scene onto its five faces with each patch painted its own ID, and sums per-pixel weights (delta form factors) for each ID, using the GPU's visibility sorting. Solving the system by Gauss-Seidel, or by **progressive refinement** (repeatedly \"shooting\" the patch with the most unshot energy), gives a usable image after a few iterations.\n\nThe mesh is typically adaptively subdivided where radiosity changes quickly, such as at shadow boundaries. The result is stored per vertex or per lightmap texel, and any camera can render it with ordinary Gouraud or texture mapping.",
 "when_to_use": "Choose it for a quick, conceptually simple baker of diffuse-only static lighting, and for teaching: it is the origin of lightmaps and precomputed GI.\n\nPrefer [lightmap-baking](lightmap-baking) with [path-tracing](path-tracing) as the integrator for production, since it handles non-diffuse materials and complex lights. Prefer [instant-radiosity](instant-radiosity) when you want a GPU-friendly approximation with light-path sampling. Prefer [photon-mapping](photon-mapping) when glossy and caustic transport matter.",
 "cost": {
  "class": "offline",
  "notes": "Form-factor computation scales quadratically in patch count without hierarchies; progressive refinement trades time for visible convergence."
 },
 "failure_modes": [
  "Diffuse-only: no specular, glossy or caustic transport",
  "Visible mesh artifacts (blocky shading, light leaks at patch edges) when the patch mesh is too coarse relative to lighting detail",
  "Hemicube aliasing and missed small patches because of pixel resolution",
  "Memory and time grow quickly with patch count, motivating hierarchical radiosity"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/964965.808601",
   "type": "paper",
   "title": "Modeling the interaction of light between diffuse surfaces",
   "authors": [
    "Cindy M. Goral",
    "Kenneth E. Torrance",
    "Donald P. Greenberg",
    "Bennett Battaile"
   ],
   "year": 1984,
   "venue": "ACM SIGGRAPH Computer Graphics",
   "url": "https://doi.org/10.1145/964965.808601",
   "ids": {
    "doi": "10.1145/964965.808601"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964965.808601",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964965.808601",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964965.808601",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964965.808601",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/964965.808601",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "goral1984modeling"
  },
  {
   "role": "primary",
   "key": "doi:10.1145/325334.325171",
   "type": "paper",
   "title": "The hemi-cube",
   "authors": [
    "Michael F. Cohen",
    "Donald P. Greenberg"
   ],
   "year": 1985,
   "venue": "Proceedings of the 12th annual conference on Computer graphics and interactive techniques  - SIGGRAPH '85",
   "url": "https://doi.org/10.1145/325334.325171",
   "ids": {
    "doi": "10.1145/325334.325171"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/325334.325171",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/325334.325171",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/325334.325171",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/325334.325171",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/325334.325171",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "cohen1985hemi"
  }
 ],
 "presets": [
  {
   "id": "radiosity-live",
   "title": "Radiosity (Hemicube Form Factors) — 0-bounce direct (left) vs patch-to-patch diffuse radiosity (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_PATCH_RES": 7,
    "P_BOUNCE_GAIN": 1.25,
    "P_PATCH_GRID": 0.75,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_PATCH_RES = 7.0; // P Patch Subdiv [3.0, 14.0, 1.0]\nconst float P_BOUNCE_GAIN = 1.25; // P Multi-Bounce [0.2, 2.2, 0.05]\nconst float P_PATCH_GRID = 0.75; // P Patch Outlines [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Direct / Radiosity [0.0, 1.0, 0.02]\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Classic Cornell box scene with tall + short diffuse boxes\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 1.0, 1.0); // floor\n  float dC = 1.0 - p.y; if (dC < res.x) res = vec2(dC, 1.0);\n  float dB = p.z + 1.4; if (dB < res.x) res = vec2(dB, 1.0);\n  float dL = p.x + 1.25; if (dL < res.x) res = vec2(dL, 2.0); // red wall\n  float dR = 1.25 - p.x; if (dR < res.x) res = vec2(dR, 3.0); // green-cyan wall\n\n  float dTall = sdBox(p - vec3(-0.38, -0.44, -0.45), vec3(0.32, 0.56, 0.32));\n  if (dTall < res.x) res = vec2(dTall, 4.0);\n  float dShort = sdBox(p - vec3(0.42, -0.68, -0.05), vec3(0.30, 0.32, 0.30));\n  if (dShort < res.x) res = vec2(dShort, 4.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 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// Analytical diffuse form factor F_ij = cos(theta_i)*cos(theta_j) / (pi * r^2 + A_j)\nfloat formFactor(vec3 pi, vec3 ni, vec3 pj, vec3 nj, float areaJ) {\n  vec3 v = pj - pi;\n  float r2 = dot(v, v);\n  float r = sqrt(max(r2, 1e-5));\n  vec3 dir = v / r;\n  float ci = max(dot(ni, dir), 0.0);\n  float cj = max(dot(nj, -dir), 0.0);\n  return (ci * cj * areaJ) / (3.1415926 * r2 + areaJ + 0.15);\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 isRad = screenX >= split;\n  float patchN = clamp(floor(P_PATCH_RES + 0.5), 3.0, 14.0);\n  float bGain = clamp(P_BOUNCE_GAIN, 0.1, 2.4);\n  float gridVis = clamp(P_PATCH_GRID, 0.0, 1.5);\n\n  vec3 ro = vec3(0.0, 0.02, 2.35);\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    // Quantize surface position to discrete radiosity patch centers on the right (classic piecewise-constant patches)\n    float patchStep = 2.0 / patchN;\n    vec3 pPatch = (floor(p / patchStep) + 0.5) * patchStep;\n    // Keep patch center on the actual surface along normal axis\n    vec3 evalP = isRad ? mix(p, pPatch, 0.55) : p;\n\n    vec3 alb = vec3(0.78, 0.76, 0.72);\n    if (matId > 1.5 && matId < 2.5) alb = vec3(0.86, 0.18, 0.15);\n    if (matId > 2.5 && matId < 3.5) alb = vec3(0.14, 0.72, 0.58);\n\n    // Ceiling patch emitter\n    vec3 emitP = vec3(0.0, 0.99, -0.35);\n    if (p.y > 0.98 && abs(p.x) < 0.36 && abs(p.z + 0.35) < 0.32) {\n      col = vec3(3.4, 3.1, 2.6);\n    } else {\n      // Direct emitter form factor F(patch -> ceiling light)\n      float fLight = formFactor(evalP, n, emitP, vec3(0.0, -1.0, 0.0), 0.72);\n      // Soft geometric visibility test toward ceiling patch\n      vec3 toL = normalize(emitP - p);\n      float vis = 1.0;\n      float tSh = 0.04;\n      for (int s = 0; s < 16; s++) {\n        float ds = mapScene(p + toL * tSh).x;\n        if (ds < 0.004) { vis = 0.08; break; }\n        tSh += max(ds, 0.04);\n        if (tSh > length(emitP - p) - 0.08) break;\n      }\n      vec3 direct = alb * vec3(2.8, 2.55, 2.15) * fLight * vis;\n\n      if (!isRad) {\n        // Left: direct illumination only (black shadows, zero color bleeding)\n        col = direct + alb * vec3(0.03);\n      } else {\n        // Right: 2-bounce patch-to-patch form-factor exchange from all 5 surrounding walls\n        vec3 bounce = vec3(0.0);\n        // Sample 3 patches on left red wall\n        for (int k = 0; k < 3; k++) {\n          float yk = -0.55 + float(k) * 0.55;\n          float fL = formFactor(evalP, n, vec3(-1.24, yk, -0.35), vec3(1.0, 0.0, 0.0), 0.95);\n          bounce += vec3(0.86, 0.18, 0.15) * fL * 1.15;\n          float fR = formFactor(evalP, n, vec3(1.24, yk, -0.35), vec3(-1.0, 0.0, 0.0), 0.95);\n          bounce += vec3(0.14, 0.72, 0.58) * fR * 1.15;\n        }\n        // Floor & back wall neutral bounce\n        bounce += vec3(0.76, 0.74, 0.68) * formFactor(evalP, n, vec3(0.0, -0.99, -0.35), vec3(0.0, 1.0, 0.0), 2.2) * 0.75;\n        bounce += vec3(0.74, 0.72, 0.68) * formFactor(evalP, n, vec3(0.0, 0.0, -1.39), vec3(0.0, 0.0, 1.0), 2.0) * 0.62;\n\n        // Ambient occlusion darkening inside corners for realistic patch shadowing\n        float ao = clamp(0.45 + 0.55 * mapScene(p + n * 0.24).x / 0.24, 0.22, 1.0);\n        col = direct + alb * (bounce * bGain * ao + vec3(0.08, 0.075, 0.07));\n\n        // Patch mesh grid overlay showing discrete radiosity elements\n        vec3 pf = abs(fract(p / patchStep - 0.5) - 0.5);\n        vec3 an = abs(n);\n        float dEdge = (an.x > an.y && an.x > an.z) ? min(pf.y, pf.z) : ((an.y > an.z) ? min(pf.x, pf.z) : min(pf.x, pf.y));\n        float wire = smoothstep(0.045, 0.010, dEdge);\n        col = mix(col, col * 0.42 + vec3(0.04, 0.06, 0.09), wire * 0.45 * min(gridVis, 1.2));\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": "radiosity",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:34.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.3943,
      "std": 0.2283,
      "min": 0.1255,
      "max": 0.9807
     },
     "image": "/specimens/radiosity-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "lightmap-baking",
  "instant-radiosity",
  "irradiance-caching",
  "path-tracing"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "lightmap-baking",
   "why": "Radiosity solutions are written into lightmap texels that the real-time shader samples."
  }
 ],
 "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/radiosity.json"
 },
 "solves": [
  "diffuse interiors look flat with direct light only",
  "need soft color bleeding between walls",
  "precompute view independent lighting for architecture",
  "smooth light bounce in static room scenes"
 ],
 "authority": "Goral et al., 1984",
 "url": "https://texelatlas.vercel.app/t/radiosity/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 26.3,
  "tier": "heavy",
  "p50_ms": 0.8154,
  "p95_ms": 0.8542,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "radiosity-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 27.18,
   "tier": "heavy",
   "p50_ms": 0.4321,
   "p95_ms": 0.4362,
   "speedup_x": 1.89,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 15.99,
   "tier": "moderate",
   "p50_ms": 0.4604,
   "p95_ms": 0.4615,
   "speedup_x": 1.77,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}