{
 "id": "visibility-buffer",
 "title": "Visibility buffer rendering",
 "aliases": [
  "V-buffer",
  "visibility buffer"
 ],
 "domain": "performance",
 "subdomain": "shading architecture",
 "stage": "performance",
 "realtime": "realtime",
 "platforms": [
  "webgpu",
  "desktop-gpu",
  "unreal"
 ],
 "year_introduced": 2013,
 "inputs": [
  "mesh",
  "material-params",
  "texture"
 ],
 "outputs": [
  "gbuffer",
  "radiance"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Rasterize only a triangle and instance id per pixel, then fetch vertices and evaluate materials in a later compute or full-screen pass, trading G-buffer bandwidth for shader-side attribute interpolation.",
 "how_it_works": "The geometry pass writes a single 32-bit value per pixel: an instance or draw id plus a primitive id. Nothing else is stored, so the pass is cheap and bandwidth-light, and hardware MSAA stays affordable.\n\nA shading pass then, per pixel, looks up the triangle's three vertices from bindless or unified vertex and index buffers, reconstructs the barycentrics by intersecting the camera ray with the triangle analytically, interpolates attributes itself, and computes UV derivatives from the same math so mipmapping works. It then evaluates the material and lighting.\n\nBecause pixels are grouped by material (via tile classification or a material-id depth trick), each material runs coherently over a screen region instead of being scattered across draws, and many materials can be shaded without many draw calls.",
 "when_to_use": "Choose it with GPU-driven pipelines, dense small triangles, many materials, or when MSAA matters and a fat G-buffer is too heavy. Prefer `deferred-shading` when engine tooling, decals and legacy post-effects all assume a classic G-buffer, or on hardware without bindless access. It is the shading model behind `nanite-virtualized-geometry`; pair with `meshlets` and `gpu-driven-rendering` for the full pipeline.",
 "cost": {
  "class": "medium",
  "notes": "Cheap geometry pass, heavier shading pass because of vertex fetch and manual interpolation; wins grow with triangle density. Qualitative."
 },
 "failure_modes": [
  "Texture sampling needs analytically derived UV gradients; getting them wrong gives over-blurred or aliased textures at silhouettes",
  "Alpha-tested and transparent geometry cannot be resolved from a single id, so they need a separate path or per-pixel discard in the id pass",
  "Shading pass reads scattered vertex data, causing cache pressure and divergent shaders if materials are not binned",
  "Needs bindless/unified buffers, which limits older or WebGL-class targets",
  "Vertex-shader features such as skinning and morphs must be done before the id pass or replayed in shading"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://jcgt.org/published/0002/02/04",
   "type": "web",
   "title": "The Visibility Buffer: A Cache-Friendly Approach to Deferred Shading",
   "authors": [],
   "year": null,
   "venue": "jcgt.org",
   "url": "https://jcgt.org/published/0002/02/04",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261105084756/https://jcgt.org/published/0002/02/04/",
     "timestamp": "20261105084756"
    },
    "page_title": null,
    "host": "jcgt.org",
    "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://jcgt.org/published/0002/02/04 → 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://jcgt.org/published/0002/02/04 → 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": null,
   "__bib": "anonvisibility"
  },
  {
   "role": "talk",
   "key": "url:https://advances.realtimerendering.com/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf",
   "type": "talk",
   "title": "GPU-Driven Rendering Pipelines",
   "authors": [
    "Ulrich Haar",
    "Sebastian Aaltonen"
   ],
   "year": null,
   "venue": "SIGGRAPH 2015 Advances in Real-Time Rendering",
   "url": "https://advances.realtimerendering.com/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261118083333/https://advances.realtimerendering.com/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf",
     "timestamp": "20261118083333"
    },
    "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/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf → 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": "haardriven"
  }
 ],
 "presets": [
  {
   "id": "visibility-buffer-live",
   "title": "Visibility buffer rendering — compact triangle/instance ID buffer vs decoupled material pass",
   "runtime": "glsl-fragment",
   "params": {
    "P_TRI_DENSITY": 10,
    "P_SPLIT": 0.45,
    "P_WIRE_OVERLAY": 0.65,
    "P_ROT_SPEED": 1
   },
   "basis": "original",
   "license_note": "Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).",
   "code": "const float P_TRI_DENSITY = 10.0; // P Triangle Scale [4.0, 20.0, 0.5]\nconst float P_SPLIT = 0.45; // P VisBuf / Shaded [0.0, 1.0, 0.02]\nconst float P_WIRE_OVERLAY = 0.65; // P Barycentric Wire [0.0, 1.5, 0.05]\nconst float P_ROT_SPEED = 1.0; // P Spin Speed [0.0, 2.5, 0.05]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\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\nvec3 hash31(float x) {\n  vec3 p = fract(vec3(x) * vec3(0.1031, 0.1030, 0.0973));\n  p += dot(p, p.yzx + 33.33);\n  return fract((p.xxy + p.yzz) * p.zyx);\n}\n\nfloat sdTorus(vec3 p, vec2 t) {\n  vec2 q = vec2(length(p.xz) - t.x, p.y);\n  return length(q) - t.y;\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\n// Returns vec2(distance, instanceID)\nvec2 mapScene(vec3 p, float spin) {\n  vec2 res = vec2(p.y + 0.85, 1.0); // Instance 1: floor\n\n  vec3 q1 = p - vec3(-0.55, 0.05, -0.15);\n  q1.xz = rot2(spin * 0.5) * q1.xz;\n  q1.xy = rot2(0.52) * q1.xy;\n  float d1 = sdTorus(q1, vec2(0.48, 0.19));\n  if (d1 < res.x) res = vec2(d1, 2.0); // Instance 2: brushed brass torus\n\n  vec3 q2 = p - vec3(0.62, -0.18, -0.25);\n  q2.xz = rot2(-spin * 0.42) * q2.xz;\n  float d2 = length(q2) - 0.42;\n  if (d2 < res.x) res = vec2(d2, 3.0); // Instance 3: ceramic sphere\n\n  vec3 q3 = p - vec3(0.05, -0.35, -1.15);\n  q3.xz = rot2(spin * 0.25) * q3.xz;\n  float d3 = sdBox(q3, vec3(0.32, 0.50, 0.32)) - 0.03;\n  if (d3 < res.x) res = vec2(d3, 4.0); // Instance 4: monolith\n\n  return res;\n}\n\nvec3 calcNormal(vec3 p, float spin) {\n  vec2 e = vec2(0.002, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy, spin).x - mapScene(p - e.xyy, spin).x,\n    mapScene(p + e.yxy, spin).x - mapScene(p - e.yxy, spin).x,\n    mapScene(p + e.yyx, spin).x - mapScene(p - e.yyx, spin).x\n  ));\n}\n\n// Compute surface parametric UV per instance for deterministic triangle IDs & barycentrics\nvec2 instanceUV(vec3 p, float instId, float spin) {\n  if (instId < 1.5) return p.xz * 0.5;\n  if (instId < 2.5) {\n    vec3 q = p - vec3(-0.55, 0.05, -0.15);\n    q.xz = rot2(spin * 0.5) * q.xz;\n    q.xy = rot2(0.52) * q.xy;\n    return vec2(atan(q.z, q.x) * 0.5, atan(q.y, length(q.xz) - 0.48) * 0.35);\n  }\n  if (instId < 3.5) {\n    vec3 q = p - vec3(0.62, -0.18, -0.25);\n    q.xz = rot2(-spin * 0.42) * q.xz;\n    return vec2(atan(q.z, q.x) * 0.45, asin(clamp(q.y / 0.42, -0.99, 0.99)) * 0.45);\n  }\n  vec3 q = p - vec3(0.05, -0.35, -1.15);\n  q.xz = rot2(spin * 0.25) * q.xz;\n  return vec2(q.x + q.z, q.y) * 0.9;\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 triDens = clamp(P_TRI_DENSITY, 3.0, 22.0);\n  float wireAmt = clamp(P_WIRE_OVERLAY, 0.0, 1.5);\n  float spin = iTime * max(P_ROT_SPEED, 0.0);\n\n  vec3 ro = vec3(0.0, 0.45, 2.55);\n  vec3 rd = normalize(vec3(uv.x, uv.y - 0.14, -1.48));\n\n  vec3 col = mix(vec3(0.035, 0.045, 0.065), vec3(0.09, 0.11, 0.16), smoothstep(-0.5, 0.6, uv.y));\n\n  float t = 0.0;\n  float instId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 64; i++) {\n    vec2 h = mapScene(ro + rd * t, spin);\n    if (h.x < 0.002) { hit = true; instId = h.y; break; }\n    t += h.x;\n    if (t > 12.0) break;\n  }\n\n  if (hit) {\n    vec3 p = ro + rd * t;\n    vec3 n = calcNormal(p, spin);\n    vec2 suv = instanceUV(p, instId, spin) * triDens;\n\n    // Split each quad cell into two triangles -> exact (triID, barycentric coords)\n    vec2 cell = floor(suv);\n    vec2 f = fract(suv);\n    float upper = step(f.x, f.y);\n    vec3 bary = (upper > 0.5)\n      ? vec3(1.0 - f.y, f.x, f.y - f.x)\n      : vec3(1.0 - f.x, f.y, f.x - f.y);\n    float triId = hash21(cell * 1.31 + vec2(upper * 19.7, instId * 37.3));\n\n    // Stage 1: Compact Visibility Buffer (InstanceID + PrimitiveID packed into 32 bits)\n    vec3 instTint = hash31(instId * 7.13 + 2.4);\n    vec3 triTint = hash31(triId * 91.7 + instId * 13.0);\n    vec3 visBufCol = mix(instTint, triTint, 0.62);\n    float baryMin = min(bary.x, min(bary.y, bary.z));\n    float triEdge = smoothstep(0.075, 0.015, baryMin);\n    visBufCol = mix(visBufCol, vec3(0.04, 0.06, 0.09), triEdge * 0.65 * min(wireAmt, 1.2));\n    // Encode subtle barycentric RGB tint in bottom strip of left side\n    if (uv.y < -0.26 && screenX < split) {\n      visBufCol = mix(visBufCol, bary, 0.72);\n    }\n\n    // Stage 2: Decoupled full-screen material pass reconstructing attributes from triangle ID\n    vec3 l1 = normalize(vec3(0.62, 0.85, 0.52));\n    vec3 l2 = normalize(vec3(-0.72, 0.30, 0.45));\n    float diff1 = max(dot(n, l1), 0.0);\n    float diff2 = max(dot(n, l2), 0.0);\n    vec3 hVec = normalize(l1 - rd);\n    vec3 alb;\n    float specPow = 28.0;\n    float specGain = 0.35;\n    if (instId < 1.5) {\n      float chk = mod(floor(p.x * 2.0) + floor(p.z * 2.0), 2.0);\n      alb = mix(vec3(0.16, 0.19, 0.24), vec3(0.26, 0.30, 0.36), chk);\n    } else if (instId < 2.5) {\n      alb = vec3(0.86, 0.64, 0.24);\n      specPow = 54.0; specGain = 0.78;\n    } else if (instId < 3.5) {\n      float stripes = smoothstep(-0.2, 0.2, sin(suv.y * 2.2));\n      alb = mix(vec3(0.16, 0.54, 0.78), vec3(0.88, 0.91, 0.94), stripes * 0.45);\n      specPow = 40.0; specGain = 0.52;\n    } else {\n      alb = vec3(0.78, 0.26, 0.32);\n      specPow = 22.0; specGain = 0.30;\n    }\n    float spec = pow(max(dot(n, hVec), 0.0), specPow) * specGain;\n    float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.25;\n    vec3 shaded = alb * (0.20 + 0.88 * diff1 + 0.25 * diff2) + vec3(spec) + vec3(0.45, 0.68, 1.0) * rim;\n    // Subtle reconstructed triangle wireframe hint when wire slider > 0\n    shaded = mix(shaded, shaded + vec3(0.14, 0.22, 0.32), triEdge * 0.25 * wireAmt);\n\n    float fog = exp(-max(t - 3.0, 0.0) * 0.14);\n    col = (screenX < split) ? visBufCol : mix(vec3(0.05, 0.07, 0.10), shaded, fog);\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": "visibility-buffer",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:04:38.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.573,
      "std": 0.1857,
      "min": 0.2239,
      "max": 0.9213
     },
     "image": "/specimens/visibility-buffer-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "deferred-shading",
  "nanite-virtualized-geometry",
  "meshlets",
  "gpu-driven-rendering",
  "tiled-deferred-shading"
 ],
 "extends": [
  "deferred-shading"
 ],
 "supersedes": [],
 "combines_with": [
  {
   "id": "gpu-driven-rendering",
   "why": "GPU culling emits the visible instance and triangle ids that the visibility pass writes."
  },
  {
   "id": "meshlets",
   "why": "Cluster ids give compact primitive ids so the id target stays small and vertex fetch is coherent."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/performance/visibility-buffer.json"
 },
 "solves": [
  "g-buffer bandwidth is my bottleneck",
  "small triangles waste shading work in forward rendering",
  "want msaa without a huge g-buffer",
  "many materials cause too many draw calls",
  "pixel quads shade tiny triangles inefficiently"
 ],
 "authority": "",
 "url": "https://texelatlas.vercel.app/t/visibility-buffer/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 27.03,
  "tier": "heavy",
  "p50_ms": 0.8487,
  "p95_ms": 0.8971,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "visibility-buffer-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 24.5,
   "tier": "heavy",
   "p50_ms": 0.3871,
   "p95_ms": 0.3907,
   "speedup_x": 2.19,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 18.05,
   "tier": "moderate",
   "p50_ms": 0.5199,
   "p95_ms": 0.5293,
   "speedup_x": 1.63,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}