Visibility buffer rendering
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.
Also known as V-buffer, visibility buffer
In the family Performance, LOD & compression, shading architecture
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | |
| Unity | None found | |
| Unreal 5.7 | Built in | Nanite rasterizes cluster and triangle IDs to a Visibility Buffer and shades materials in a subsequent pass docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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.
A 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.
Because 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 choose it
Reach for it when
- 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
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 (G-buffer) 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 (cluster rendering) and GPU-driven rendering for the full pipeline.
Field marks
- 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
Presets
Visibility buffer rendering — compact triangle/instance ID buffer vs decoupled material pass
{
"P_TRI_DENSITY": 10,
"P_SPLIT": 0.45,
"P_WIRE_OVERLAY": 0.65,
"P_ROT_SPEED": 1
}Show GLSL (172 lines)
const float P_TRI_DENSITY = 10.0; // P Triangle Scale [4.0, 20.0, 0.5]
const float P_SPLIT = 0.45; // P VisBuf / Shaded [0.0, 1.0, 0.02]
const float P_WIRE_OVERLAY = 0.65; // P Barycentric Wire [0.0, 1.5, 0.05]
const float P_ROT_SPEED = 1.0; // P Spin Speed [0.0, 2.5, 0.05]
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
vec3 hash31(float x) {
vec3 p = fract(vec3(x) * vec3(0.1031, 0.1030, 0.0973));
p += dot(p, p.yzx + 33.33);
return fract((p.xxy + p.yzz) * p.zyx);
}
float sdTorus(vec3 p, vec2 t) {
vec2 q = vec2(length(p.xz) - t.x, p.y);
return length(q) - t.y;
}
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// Returns vec2(distance, instanceID)
vec2 mapScene(vec3 p, float spin) {
vec2 res = vec2(p.y + 0.85, 1.0); // Instance 1: floor
vec3 q1 = p - vec3(-0.55, 0.05, -0.15);
q1.xz = rot2(spin * 0.5) * q1.xz;
q1.xy = rot2(0.52) * q1.xy;
float d1 = sdTorus(q1, vec2(0.48, 0.19));
if (d1 < res.x) res = vec2(d1, 2.0); // Instance 2: brushed brass torus
vec3 q2 = p - vec3(0.62, -0.18, -0.25);
q2.xz = rot2(-spin * 0.42) * q2.xz;
float d2 = length(q2) - 0.42;
if (d2 < res.x) res = vec2(d2, 3.0); // Instance 3: ceramic sphere
vec3 q3 = p - vec3(0.05, -0.35, -1.15);
q3.xz = rot2(spin * 0.25) * q3.xz;
float d3 = sdBox(q3, vec3(0.32, 0.50, 0.32)) - 0.03;
if (d3 < res.x) res = vec2(d3, 4.0); // Instance 4: monolith
return res;
}
vec3 calcNormal(vec3 p, float spin) {
vec2 e = vec2(0.002, 0.0);
return normalize(vec3(
mapScene(p + e.xyy, spin).x - mapScene(p - e.xyy, spin).x,
mapScene(p + e.yxy, spin).x - mapScene(p - e.yxy, spin).x,
mapScene(p + e.yyx, spin).x - mapScene(p - e.yyx, spin).x
));
}
// Compute surface parametric UV per instance for deterministic triangle IDs & barycentrics
vec2 instanceUV(vec3 p, float instId, float spin) {
if (instId < 1.5) return p.xz * 0.5;
if (instId < 2.5) {
vec3 q = p - vec3(-0.55, 0.05, -0.15);
q.xz = rot2(spin * 0.5) * q.xz;
q.xy = rot2(0.52) * q.xy;
return vec2(atan(q.z, q.x) * 0.5, atan(q.y, length(q.xz) - 0.48) * 0.35);
}
if (instId < 3.5) {
vec3 q = p - vec3(0.62, -0.18, -0.25);
q.xz = rot2(-spin * 0.42) * q.xz;
return vec2(atan(q.z, q.x) * 0.45, asin(clamp(q.y / 0.42, -0.99, 0.99)) * 0.45);
}
vec3 q = p - vec3(0.05, -0.35, -1.15);
q.xz = rot2(spin * 0.25) * q.xz;
return vec2(q.x + q.z, q.y) * 0.9;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float screenX = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
float triDens = clamp(P_TRI_DENSITY, 3.0, 22.0);
float wireAmt = clamp(P_WIRE_OVERLAY, 0.0, 1.5);
float spin = iTime * max(P_ROT_SPEED, 0.0);
vec3 ro = vec3(0.0, 0.45, 2.55);
vec3 rd = normalize(vec3(uv.x, uv.y - 0.14, -1.48));
vec3 col = mix(vec3(0.035, 0.045, 0.065), vec3(0.09, 0.11, 0.16), smoothstep(-0.5, 0.6, uv.y));
float t = 0.0;
float instId = 0.0;
bool hit = false;
for (int i = 0; i < 64; i++) {
vec2 h = mapScene(ro + rd * t, spin);
if (h.x < 0.002) { hit = true; instId = h.y; break; }
t += h.x;
if (t > 12.0) break;
}
if (hit) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p, spin);
vec2 suv = instanceUV(p, instId, spin) * triDens;
// Split each quad cell into two triangles -> exact (triID, barycentric coords)
vec2 cell = floor(suv);
vec2 f = fract(suv);
float upper = step(f.x, f.y);
vec3 bary = (upper > 0.5)
? vec3(1.0 - f.y, f.x, f.y - f.x)
: vec3(1.0 - f.x, f.y, f.x - f.y);
float triId = hash21(cell * 1.31 + vec2(upper * 19.7, instId * 37.3));
// Stage 1: Compact Visibility Buffer (InstanceID + PrimitiveID packed into 32 bits)
vec3 instTint = hash31(instId * 7.13 + 2.4);
vec3 triTint = hash31(triId * 91.7 + instId * 13.0);
vec3 visBufCol = mix(instTint, triTint, 0.62);
float baryMin = min(bary.x, min(bary.y, bary.z));
float triEdge = smoothstep(0.075, 0.015, baryMin);
visBufCol = mix(visBufCol, vec3(0.04, 0.06, 0.09), triEdge * 0.65 * min(wireAmt, 1.2));
// Encode subtle barycentric RGB tint in bottom strip of left side
if (uv.y < -0.26 && screenX < split) {
visBufCol = mix(visBufCol, bary, 0.72);
}
// Stage 2: Decoupled full-screen material pass reconstructing attributes from triangle ID
vec3 l1 = normalize(vec3(0.62, 0.85, 0.52));
vec3 l2 = normalize(vec3(-0.72, 0.30, 0.45));
float diff1 = max(dot(n, l1), 0.0);
float diff2 = max(dot(n, l2), 0.0);
vec3 hVec = normalize(l1 - rd);
vec3 alb;
float specPow = 28.0;
float specGain = 0.35;
if (instId < 1.5) {
float chk = mod(floor(p.x * 2.0) + floor(p.z * 2.0), 2.0);
alb = mix(vec3(0.16, 0.19, 0.24), vec3(0.26, 0.30, 0.36), chk);
} else if (instId < 2.5) {
alb = vec3(0.86, 0.64, 0.24);
specPow = 54.0; specGain = 0.78;
} else if (instId < 3.5) {
float stripes = smoothstep(-0.2, 0.2, sin(suv.y * 2.2));
alb = mix(vec3(0.16, 0.54, 0.78), vec3(0.88, 0.91, 0.94), stripes * 0.45);
specPow = 40.0; specGain = 0.52;
} else {
alb = vec3(0.78, 0.26, 0.32);
specPow = 22.0; specGain = 0.30;
}
float spec = pow(max(dot(n, hVec), 0.0), specPow) * specGain;
float rim = pow(1.0 - max(dot(n, -rd), 0.0), 3.0) * 0.25;
vec3 shaded = alb * (0.20 + 0.88 * diff1 + 0.25 * diff2) + vec3(spec) + vec3(0.45, 0.68, 1.0) * rim;
// Subtle reconstructed triangle wireframe hint when wire slider > 0
shaded = mix(shaded, shaded + vec3(0.14, 0.22, 0.32), triEdge * 0.25 * wireAmt);
float fog = exp(-max(t - 3.0, 0.0) * 0.14);
col = (screenX < split) ? visBufCol : mix(vec3(0.05, 0.07, 0.10), shaded, fog);
}
float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| visibility-buffer-live | Tesla T4 1920x1080 | 27.0× baseline (heavy) · 0.849 ms / 0.897 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| visibility-buffer-live | NVIDIA L4 1920x1080 | 24.5× baseline (heavy) · 0.387 ms / 0.391 ms · 2.2× faster on L4 | opengl-timer-query · Cross-architecture validation |
| visibility-buffer-live | NVIDIA A100-SXM4-40GB 1920x1080 | 18.1× baseline (moderate) · 0.520 ms / 0.529 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
Crosses
- GPU-driven rendering: GPU culling emits the visible instance and triangle ids that the visibility pass writes.
- Meshlets (cluster rendering): Cluster ids give compact primitive ids so the id target stays small and vertex fetch is coherent.
Sources
- primary. The Visibility Buffer: A Cache-Friendly Approach to Deferred Shading. jcgt.org.Verified via live page · 2026-11-29
- talkUlrich Haar, Sebastian Aaltonen. GPU-Driven Rendering Pipelines. SIGGRAPH 2015 Advances in Real-Time Rendering.Verified via live page · 2026-11-29