{
 "id": "surfel-gi",
 "title": "Surfel-Based Global Illumination (GIBS)",
 "aliases": [
  "GIBS",
  "surfel cache"
 ],
 "domain": "gi",
 "subdomain": "hybrid tracing GI",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "desktop-gpu"
 ],
 "year_introduced": 2021,
 "inputs": [
  "gbuffer",
  "depth",
  "mesh"
 ],
 "outputs": [
  "radiance",
  "irradiance-probes"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Covers visible geometry with small oriented discs (surfels) that cache irradiance, updated by hardware ray tracing and reused across frames; pixels shade by gathering nearby surfels. No bake, no UVs.",
 "how_it_works": "Surfels are position, normal and radius records spawned on demand from the G-buffer. Each frame the pipeline tests screen tiles for coverage by existing surfels; where coverage is insufficient, new surfels are spawned (and ones that fall out of use are recycled), so the cache follows the camera. A spatial hash or grid lets any point quickly find the surfels around it.\n\nEach surfel owns a small budget of rays per frame. It traces them with hardware ray tracing, shading hits using the surfel cache itself as a source of multi-bounce light, and blends the new samples into the stored irradiance (stored as a low-order basis or a small octahedral map). Allocating more rays to surfels that are new or whose result changed concentrates work where it matters.\n\nAt shading time, a pixel finds nearby surfels whose disks contain its position, weights them by distance and normal, and sums their irradiance. The result is combined with other contributors in a lighting buffer.",
 "when_to_use": "Choose it for fully dynamic diffuse GI in an engine where baking or UV unwrapping is not acceptable, you can afford hardware ray tracing, and the camera sees a bounded amount of geometry.\n\nPrefer [ddgi](ddgi) when you want a regular grid with simple lookups and a fixed memory footprint. Prefer [lumen-gi](lumen-gi) for SDF-based software tracing and large scenes. Prefer [restir-gi](restir-gi) when you need per-pixel indirect accuracy. Prefer [lightmap-baking](lightmap-baking) when the scene is static and you need the lowest runtime cost.",
 "cost": {
  "class": "medium",
  "notes": "Cost scales with the surfel count times rays per surfel plus spatial hash lookups in shading; the cache is capped for a fixed memory budget."
 },
 "failure_modes": [
  "Surfel popping and temporal instability when surfels spawn or retire as the camera moves",
  "Light leaking at thin walls or corners where a surfel disk spans two surfaces",
  "Coverage gaps and noise in fast-moving or newly revealed areas until the cache converges",
  "Large dynamic moving objects can invalidate surfels and produce trailing lighting"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://advances.realtimerendering.com/s2021/index.html",
   "type": "web",
   "title": "Global Illumination Based on Surfels",
   "authors": [
    "Henrik Halen",
    "Andreas Brinck",
    "Kyle Hayward",
    "Xiangshun Bei"
   ],
   "year": null,
   "venue": "SIGGRAPH 2021 Advances in Real-Time Rendering",
   "url": "https://advances.realtimerendering.com/s2021/index.html",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261107170833/https://advances.realtimerendering.com/s2021/index.html",
     "timestamp": "20261107170833"
    },
    "page_title": null,
    "host": "advances.realtimerendering.com",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "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://advances.realtimerendering.com/s2021/index.html → 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": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "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": null,
   "__bib": "halenglobal"
  }
 ],
 "presets": [
  {
   "id": "surfel-gi-live",
   "title": "Surfel GI (GIBS) — world-space oriented surfel disks (left) vs filtered surfel irradiance (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_SURFEL_SIZE": 0.16,
    "P_BOUNCE_GAIN": 1.3,
    "P_DISK_EDGE": 0.85,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_SURFEL_SIZE = 0.16; // P Surfel Radius [0.08, 0.28, 0.01]\nconst float P_BOUNCE_GAIN = 1.30; // P Indirect GI [0.3, 2.2, 0.05]\nconst float P_DISK_EDGE = 0.85; // P Disk Outlines [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Surfels / GI Split [0.0, 1.0, 0.02]\n\nvec3 hash33(vec3 p) {\n  p = fract(p * vec3(0.1031, 0.1030, 0.0973));\n  p += dot(p, p.yxz + 33.33);\n  return fract((p.xxy + p.yxx) * p.zyx);\n}\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\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.85, 1.0);\n  float dC = 1.05 - p.y; if (dC < res.x) res = vec2(dC, 1.0);\n  float dB = p.z + 1.42; if (dB < res.x) res = vec2(dB, 1.0);\n  float dL = p.x + 1.30; if (dL < res.x) res = vec2(dL, 2.0);\n  float dR = 1.30 - p.x; if (dR < res.x) res = vec2(dR, 3.0);\n\n  float dSph = length(p - vec3(-0.32, -0.45, -0.20)) - 0.39;\n  if (dSph < res.x) res = vec2(dSph, 4.0);\n  float dBlk = sdBox(p - vec3(0.50, -0.50, -0.32), vec3(0.28, 0.35, 0.28)) - 0.02;\n  if (dBlk < res.x) res = vec2(dBlk, 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\nvec3 evalBounce(vec3 p, vec3 n, float t) {\n  vec3 sunHit = vec3(0.42 * sin(t * 0.6), -0.84, -0.25);\n  float dSun = length(p - sunHit);\n  vec3 warmBounce = vec3(1.25, 0.72, 0.28) * exp(-dSun * 1.15) * (0.35 + 0.65 * max(dot(n, normalize(sunHit - p)), 0.0));\n  vec3 redWall = vec3(0.90, 0.22, 0.20) * clamp(1.0 - (p.x + 1.30) * 0.5, 0.0, 1.0) * 0.55;\n  vec3 tealWall = vec3(0.14, 0.76, 0.82) * clamp(1.0 - (1.30 - p.x) * 0.5, 0.0, 1.0) * 0.55;\n  float ao = clamp(0.38 + 0.62 * mapScene(p + n * 0.26).x / 0.26, 0.18, 1.0);\n  return (warmBounce + redWall + tealWall + vec3(0.14, 0.16, 0.22)) * ao;\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 sRad = clamp(P_SURFEL_SIZE, 0.07, 0.30);\n  float giGain = clamp(P_BOUNCE_GAIN, 0.2, 2.4);\n  float edgeVis = clamp(P_DISK_EDGE, 0.0, 1.5);\n\n  vec3 ro = vec3(0.0, 0.04, 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    vec3 alb = vec3(0.76, 0.76, 0.78);\n    if (matId > 1.5 && matId < 2.5) alb = vec3(0.90, 0.24, 0.20);\n    if (matId > 2.5 && matId < 3.5) alb = vec3(0.14, 0.74, 0.80);\n\n    vec3 lPos = vec3(0.42 * sin(iTime * 0.6), 0.94, -0.20);\n    vec3 lDir = normalize(lPos - p);\n    float ndl = max(dot(n, lDir), 0.0);\n\n    // Allocate world-space surfels in a 3D uniform hash grid and gather Mahalanobis disk weights\n    float cell = sRad * 1.15;\n    vec3 cid = floor(p / cell);\n\n    vec3 surfelIrr = vec3(0.0);\n    float wTot = 0.0;\n    float bestD = 1e5;\n    vec3 bestIdCol = vec3(0.5);\n    vec3 bestIrr = vec3(0.0);\n    float diskRim = 0.0;\n\n    for (int dz = -1; dz <= 1; dz++) {\n      for (int dy = -1; dy <= 1; dy++) {\n        for (int dx = -1; dx <= 1; dx++) {\n          vec3 nb = cid + vec3(float(dx), float(dy), float(dz));\n          vec3 rnd = hash33(nb);\n          vec3 sp = (nb + 0.18 + 0.64 * rnd) * cell;\n          // Project surfel disk onto surface plane so disks tile cleanly across geometry\n          vec3 sOnSurf = sp - n * dot(sp - p, n);\n          float d = length(p - sOnSurf);\n          float q = d / max(sRad, 0.04);\n          if (q < 1.0) {\n            // Smooth cubic surfel kernel weight (1 - q)^2\n            float w = (1.0 - q) * (1.0 - q);\n            vec3 irr = evalBounce(sOnSurf, n, iTime) * giGain;\n            surfelIrr += irr * w;\n            wTot += w;\n            diskRim = max(diskRim, smoothstep(0.09, 0.015, abs(q - 0.86)));\n          }\n          if (d < bestD) {\n            bestD = d;\n            bestIdCol = 0.35 + 0.65 * hash33(nb + 19.7);\n            bestIrr = evalBounce(sOnSurf, n, iTime) * giGain;\n          }\n        }\n      }\n    }\n\n    vec3 filteredGI = (wTot > 1e-4) ? (surfelIrr / wTot) : evalBounce(p, n, iTime) * giGain;\n\n    if (!isSmooth) {\n      // Left: raw discrete world-space surfel disks showing cached radiance & allocation tiling\n      float inDisk = smoothstep(sRad * 0.94, sRad * 0.84, bestD);\n      vec3 diskFill = mix(bestIrr * 0.85, bestIdCol * 0.45 + bestIrr * 0.65, 0.25);\n      col = mix(vec3(0.05, 0.07, 0.10), diskFill, inDisk);\n      col = mix(col, vec3(0.95, 0.97, 1.0), diskRim * 0.42 * min(edgeVis, 1.2));\n    } else {\n      // Right: smoothly filtered surfel GI + direct key light\n      col = alb * (ndl * 0.55 + filteredGI);\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": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "surfel-gi",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:37.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.8302,
      "std": 0.0562,
      "min": 0.1255,
      "max": 0.9014
     },
     "image": "/specimens/surfel-gi-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ddgi",
  "lumen-gi",
  "sharc",
  "irradiance-caching"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "restir-gi",
   "why": "Surfel irradiance gives a stable low-frequency fallback while resampling adds detail."
  }
 ],
 "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/surfel-gi.json"
 },
 "solves": [
  "dynamic gi without probes or baked data",
  "indirect light on large open worlds in real time",
  "diffuse bounce that follows geometry detail",
  "gi must work with fully dynamic scenes cheaply"
 ],
 "authority": "Halen et al.",
 "url": "https://texelatlas.vercel.app/t/surfel-gi/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 69.78,
  "tier": "extreme",
  "p50_ms": 2.1631,
  "p95_ms": 2.3056,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "surfel-gi-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 59.99,
   "tier": "heavy",
   "p50_ms": 0.9539,
   "p95_ms": 0.9738,
   "speedup_x": 2.27,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 47.93,
   "tier": "heavy",
   "p50_ms": 1.3804,
   "p95_ms": 1.3825,
   "speedup_x": 1.57,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}