{
 "id": "screen-space-gi",
 "title": "Screen-Space Global Illumination",
 "aliases": [
  "SSGI",
  "SSDO",
  "screen-space directional occlusion"
 ],
 "domain": "gi",
 "subdomain": "screen-space GI",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2009,
 "inputs": [
  "gbuffer",
  "depth",
  "normals",
  "radiance"
 ],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "dynamic",
 "summary": "Approximates one-bounce diffuse indirect light by sampling the lit depth buffer around each pixel as if each visible sample were a small light, with the same sampling doubling as directional occlusion.",
 "how_it_works": "Screen-space directional occlusion extends ambient occlusion: for each pixel, instead of just counting occluded samples, it takes a set of directions in the hemisphere (via sample offsets within a screen-space radius). Samples whose reconstructed 3D position lies above the surface are considered **unoccluded** and contribute environment light; samples that lie *below* the surface are occluders.\n\nFor the indirect bounce, each occluding sample's **lit colour** (read from the previous frame's frame buffer) is treated as a small diffuse patch emitting towards the receiver. The contribution is weighted by form-factor-like terms: the cosine at the receiver, the cosine at the emitter, and the squared distance. The sum approximates one bounce of colour bleeding from visible surfaces.\n\nCurrent variants use ray-marched screen-space traces of the depth buffer (hierarchical depth) with a few rays per pixel, feed history through temporal reprojection, and denoise with a spatial filter. The technique only sees what is on screen, so it is often combined with a world-space probe or [ddgi](ddgi) fallback for off-screen light.",
 "when_to_use": "Choose it as an inexpensive extra for colour bleeding and indirect shadowing at contact scale in a deferred renderer, typically layered on top of probes or lightmaps.\n\nPrefer [ddgi](ddgi), [lumen-gi](lumen-gi) or [surfel-gi](surfel-gi) when off-screen light and consistent GI at any view angle matter. Prefer [radiance-cascades](radiance-cascades) for screen-space-based tracing that avoids the noise of per-pixel gather. Prefer [reflective-shadow-maps](reflective-shadow-maps) when the emitter surfaces are known from a light's point of view.",
 "cost": {
  "class": "medium",
  "notes": "Cost scales with samples per pixel plus a denoise and temporal pass; commonly run at half resolution."
 },
 "failure_modes": [
  "Missing light from anything off-screen or hidden behind foreground objects, so indirect light pops when the source leaves the view",
  "Ghosting and smearing from temporal reuse on fast motion and disocclusion",
  "Thin-object problem: depth buffer lacks thickness, so occluders are misjudged and halos appear",
  "Colour bleeding vanishes at screen edges and when the camera turns"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/1507149.1507161",
   "type": "paper",
   "title": "Approximating dynamic global illumination in image space",
   "authors": [
    "Tobias Ritschel",
    "Thorsten Grosch",
    "Hans-Peter Seidel"
   ],
   "year": 2009,
   "venue": "Proceedings of the 2009 symposium on Interactive 3D graphics and games",
   "url": "https://doi.org/10.1145/1507149.1507161",
   "ids": {
    "doi": "10.1145/1507149.1507161"
   },
   "license": null,
   "extra": {
    "csl_type": "proceedings-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1507149.1507161",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1507149.1507161",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1507149.1507161",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1507149.1507161",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/1507149.1507161",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "ritschel2009approximating"
  }
 ],
 "presets": [
  {
   "id": "screen-space-gi-live",
   "title": "Screen-space GI — split direct lighting vs horizon-marching diffuse color bleed",
   "runtime": "glsl-fragment",
   "params": {
    "P_GI_INTENSITY": 1.35,
    "P_SAMPLE_RADIUS": 0.9,
    "P_BOUNCE_SAT": 1.2,
    "P_SPLIT": 0.42
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_GI_INTENSITY = 1.35; // P GI Strength [0.0, 2.5, 0.05]\nconst float P_SAMPLE_RADIUS = 0.9; // P Gather Radius [0.2, 2.0, 0.05]\nconst float P_BOUNCE_SAT = 1.2; // P Color Bleed [0.2, 2.0, 0.05]\nconst float P_SPLIT = 0.42; // P Direct/GI Split [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// Cornell gallery box with crimson left wall, teal right wall, white central column & orb\nvec2 mapRoom(vec3 p) {\n  // Inverted room walls: x in [-1.5,1.5], y in [-1.0,1.0], z in [-1.5, 3.0]\n  vec2 res = vec2(1.0 + p.y, 1.0); // floor\n  float ceilD = 1.0 - p.y; if (ceilD < res.x) res = vec2(ceilD, 1.0);\n  float backD = 1.45 + p.z; if (backD < res.x) res = vec2(backD, 1.0);\n  float leftD = 1.45 + p.x; if (leftD < res.x) res = vec2(leftD, 2.0); // crimson wall\n  float rightD = 1.45 - p.x; if (rightD < res.x) res = vec2(rightD, 3.0); // emerald-teal wall\n\n  // Central sculpted white pedestal & floating matte sphere\n  float dPed = sdBox(p - vec3(0.0, -0.55, -0.25), vec3(0.36, 0.45, 0.36)) - 0.03;\n  if (dPed < res.x) res = vec2(dPed, 4.0);\n\n  vec3 spPos = vec3(0.28 * sin(iTime * 0.7), 0.18 + 0.08 * cos(iTime * 1.1), -0.22);\n  float dSph = length(p - spPos) - 0.34;\n  if (dSph < res.x) res = vec2(dSph, 4.0);\n\n  // Side accent block near crimson wall\n  float dBlk = sdBox(p - vec3(-0.78, -0.68, -0.62), vec3(0.32, 0.32, 0.32)) - 0.02;\n  if (dBlk < res.x) res = vec2(dBlk, 4.0);\n\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapRoom(p + e.xyy).x - mapRoom(p - e.xyy).x,\n    mapRoom(p + e.yxy).x - mapRoom(p - e.yxy).x,\n    mapRoom(p + e.yyx).x - mapRoom(p - e.yyx).x\n  ));\n}\n\nvec3 getAlbedo(float id, float sat) {\n  vec3 c;\n  if (id < 1.5) c = vec3(0.76, 0.76, 0.74);\n  else if (id < 2.5) c = vec3(0.88, 0.14, 0.12);\n  else if (id < 3.5) c = vec3(0.10, 0.76, 0.56);\n  else c = vec3(0.88, 0.87, 0.85);\n  float l = dot(c, vec3(0.299, 0.587, 0.114));\n  return clamp(mix(vec3(l), c, sat), 0.02, 1.0);\n}\n\nfloat softShadow(vec3 ro, vec3 rd, float maxT) {\n  float res = 1.0;\n  float t = 0.04;\n  for (int i = 0; i < 20; i++) {\n    float h = mapRoom(ro + rd * t).x;\n    res = min(res, clamp(5.0 * h / t, 0.0, 1.0));\n    t += max(h, 0.05);\n    if (t > maxT || res < 0.02) break;\n  }\n  return res;\n}\n\nvec3 directShade(vec3 p, vec3 n, float matId, vec3 lPos, float sat) {\n  vec3 toL = lPos - p;\n  float dist = length(toL) + 1e-4;\n  vec3 lDir = toL / dist;\n  float ndl = max(dot(n, lDir), 0.0);\n  float sh = softShadow(p + n * 0.015, lDir, dist - 0.08);\n  float att = 2.6 / (0.4 + dist * dist);\n  vec3 alb = getAlbedo(matId, sat);\n  return alb * vec3(1.15, 1.08, 0.96) * ndl * sh * att;\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  vec2 screenUV = fragCoord / iResolution.xy;\n\n  vec3 ro = vec3(0.0, 0.05, 2.35);\n  vec3 rd = normalize(vec3(uv, -1.32));\n\n  float sat = clamp(P_BOUNCE_SAT, 0.2, 2.2);\n  vec3 lPos = vec3(0.45 * cos(iTime * 0.55), 0.88, -0.2 + 0.35 * sin(iTime * 0.55));\n\n  float t = 0.0;\n  float matId = 1.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapRoom(ro + rd * t);\n    if (h.x < 0.002) { matId = h.y; hit = true; break; }\n    t += h.x;\n    if (t > 9.0) break;\n  }\n\n  vec3 col = vec3(0.02);\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p);\n    vec3 alb = getAlbedo(matId, sat);\n    vec3 direct = directShade(p, n, matId, lPos, sat);\n\n    // Ceiling area light emitter plaque\n    float emitter = smoothstep(0.32, 0.18, length(p.xz - lPos.xz)) * smoothstep(0.95, 0.99, p.y);\n    direct += vec3(3.4, 3.1, 2.6) * emitter;\n\n    // Screen-Space GI gather: march 8 azimuthal horizon rays around surface tangent plane\n    vec3 tangent = normalize(abs(n.y) < 0.9 ? cross(n, vec3(0.0, 1.0, 0.0)) : cross(n, vec3(1.0, 0.0, 0.0)));\n    vec3 bitan = cross(n, tangent);\n    float rad = clamp(P_SAMPLE_RADIUS, 0.2, 2.2);\n    float jitter = fract(sin(dot(fragCoord, vec2(12.9898, 78.233))) * 43758.5453);\n\n    vec3 giAccum = vec3(0.0);\n    float aoAccum = 0.0;\n    for (int k = 0; k < 8; k++) {\n      float ang = (float(k) + jitter * 0.45) * 0.785398;\n      vec3 gDir = normalize(n * 0.55 + (cos(ang) * tangent + sin(ang) * bitan) * 0.835);\n      // Short horizon march in scene proxy (emulates screen-space depth buffer marching)\n      float gt = 0.08;\n      for (int s = 0; s < 6; s++) {\n        vec3 gp = p + n * 0.02 + gDir * gt;\n        vec2 gh = mapRoom(gp);\n        if (gh.x < 0.06 || gt > rad * 1.45) {\n          vec3 gn = calcNormal(gp);\n          // Sample direct radiance of nearby hit surface for 1-bounce color bleed\n          vec3 sampleRad = directShade(gp, gn, gh.y, lPos, sat) + getAlbedo(gh.y, sat) * 0.18;\n          float cosW = max(dot(n, gDir), 0.0);\n          float distW = 1.0 / (0.35 + gt * gt * 1.4);\n          giAccum += sampleRad * cosW * distW;\n          aoAccum += smoothstep(rad * 1.4, 0.05, gt);\n          break;\n        }\n        gt += max(gh.x, rad * 0.22);\n      }\n    }\n    giAccum /= 8.0;\n    float ssao = 1.0 - 0.52 * (aoAccum / 8.0);\n\n    vec3 directOnly = direct + alb * vec3(0.045, 0.048, 0.058);\n    vec3 withSSGI = direct + alb * (giAccum * max(P_GI_INTENSITY, 0.0) * 1.65 + vec3(0.04, 0.045, 0.055) * ssao);\n\n    float splitX = clamp(P_SPLIT, 0.0, 1.0);\n    col = (screenUV.x < splitX) ? directOnly : withSSGI;\n    if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {\n      col = vec3(1.8, 1.5, 0.7);\n    }\n  }\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": "screen-space-gi",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T16:50:13.852Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.587,
      "std": 0.209,
      "unique_colors": 348
     },
     "image": "/specimens/screen-space-gi-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "ddgi",
  "lumen-gi",
  "radiance-cascades",
  "reflective-shadow-maps"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "ddgi",
   "why": "Probes supply off-screen and low-frequency light that the screen-space gather cannot see."
  }
 ],
 "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/screen-space-gi.json"
 },
 "solves": [
  "want cheap colour bleeding in deferred rendering",
  "indirect shadowing at contact scale is missing",
  "need one-bounce diffuse light without probes everywhere",
  "extra indirect detail on top of baked lighting"
 ],
 "authority": "Ritschel et al., 2009",
 "url": "https://texelatlas.vercel.app/t/screen-space-gi/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 244.24,
  "tier": "extreme",
  "p50_ms": 8.0356,
  "p95_ms": 8.218,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "screen-space-gi-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 232.43,
   "tier": "extreme",
   "p50_ms": 3.6956,
   "p95_ms": 3.756,
   "speedup_x": 2.17,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 148.76,
   "tier": "extreme",
   "p50_ms": 4.2844,
   "p95_ms": 4.3182,
   "speedup_x": 1.88,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}