Sparse virtual texturing
Treat a huge texture address space as virtual memory: only the tiles the camera actually samples are streamed into a small physical cache, found through a page table or indirection texture.
Also known as virtual textures, megatexture, SVT
In the family Performance, LOD & compression, texture streaming
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 | Built in | HDRP Asset > Streaming Virtual Texturing; Shader Graph Sample Virtual Texture node docs HDRP. |
| Unreal 5.7 | Built in | Project Settings > Engine > Rendering > Virtual Textures; Streaming (SVT) and Runtime (RVT) virtual textures docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | Built in | MTLSparseTextureMappingMode via MTLResourceStateCommandEncoder.updateTextureMapping; sparse heaps docs Sparse residency is an API primitive; page table, feedback pass and streaming are yours. |
How it works
Surfaces sample from a single enormous virtual texture, split into fixed-size pages (e.g. 128x128 texels) per mip level. A small physical texture or atlas holds the resident pages, and an indirection (page table) texture maps virtual page coordinates and mip to a location in that cache.
To know which pages are needed, a feedback pass renders the scene at low resolution writing each pixel's virtual page and mip into a target. The CPU or a compute pass reads it back, requests missing pages, loads and decodes them (often transcoding to a block compressed format), and updates the page table with an LRU eviction policy.
The shader samples the page table, computes the physical UV including border or padding handling, and falls back to a coarser resident mip while a requested page is still loading.
When to choose it
Reach for it when
- textures too big to fit in gpu memory
- unique texture detail across a huge terrain
- too many texture bindings for large worlds
- texture streaming causes visible pop-in
- need per-pixel unique painted surface at world scale
Choose it for terrain, large worlds or unique-texel assets (decals, painted surfaces, baked lightmaps) that exceed GPU memory or would need hundreds of texture bindings. Prefer ordinary mipmapped textures with streaming of whole mip chains for modest scenes. Combine with Block texture compression (BC7 / ASTC) or Basis Universal / KTX2 supercompression for page payloads; Virtual Shadow Maps applies the same paging idea to shadow depth.
Field marks
- Texture pop-in or blurry surfaces while pages stream in, especially on fast camera cuts
- Anisotropic and trilinear filtering across page borders need padding or manual filtering, otherwise visible seams
- Feedback buffer latency of a few frames lets fast motion outrun the cache
- Cache thrash when the working set exceeds the physical pool causes constant reloads
- Page-table lookup breaks hardware derivative-based mip selection if gradients are not passed carefully
Presets
Sparse Virtual Texturing — mip feedback & resident page-table cache (left) vs streamed megatexture (right)
{
"P_PAGE_DENS": 6,
"P_MIP_BIAS": 0,
"P_CACHE_HUD": 1,
"P_SPLIT": 0.5
}Show GLSL (129 lines)
const float P_PAGE_DENS = 6.0; // P Virtual Pages [3.0, 12.0, 1.0]
const float P_MIP_BIAS = 0.0; // P Mip LOD Bias [-1.0, 1.5, 0.1]
const float P_CACHE_HUD = 1.0; // P Page Table HUD [0.0, 1.0, 0.05]
const float P_SPLIT = 0.50; // P Feedback / Stream [0.0, 1.0, 0.02]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
// High-detail procedural megatexture (unique non-repeating terrain + architectural decals)
vec3 megatexture(vec2 uv, float lod) {
float scale = 1.0 / pow(2.0, clamp(lod, 0.0, 4.0));
vec2 q = uv * 8.0;
float n1 = sin(q.x * 1.4 + sin(q.y * 1.1)) * 0.5 + 0.5;
float n2 = sin(q.x * 5.2 * scale + q.y * 4.8 * scale) * 0.5 + 0.5;
float masonry = smoothstep(0.06, 0.12, min(abs(fract(q.x * 2.0 * scale) - 0.5), abs(fract(q.y * 2.0 * scale) - 0.5)));
vec3 stone = mix(vec3(0.32, 0.28, 0.24), vec3(0.68, 0.62, 0.52), n1);
vec3 moss = vec3(0.18, 0.44, 0.24);
vec3 base = mix(stone, moss, smoothstep(0.55, 0.85, sin(uv.x * 3.1 - uv.y * 2.3) * 0.5 + 0.5));
return base * (0.72 + 0.28 * masonry) * (0.85 + 0.15 * n2);
}
vec3 mipColor(float m) {
if (m < 0.5) return vec3(0.95, 0.24, 0.22); // Mip 0 highest detail
if (m < 1.5) return vec3(0.98, 0.68, 0.18); // Mip 1
if (m < 2.5) return vec3(0.18, 0.88, 0.56); // Mip 2
if (m < 3.5) return vec3(0.20, 0.64, 0.98); // Mip 3
return vec3(0.62, 0.34, 0.92); // Mip 4+ coarse fallback
}
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;
vec2 uv01 = fragCoord / max(iResolution.xy, vec2(1.0));
float screenX = uv01.x;
float split = clamp(P_SPLIT, 0.0, 1.0);
bool isStream = screenX >= split;
float pageDens = clamp(floor(P_PAGE_DENS + 0.5), 3.0, 14.0);
float mipBias = clamp(P_MIP_BIAS, -1.0, 1.8);
float hudVis = clamp(P_CACHE_HUD, 0.0, 1.0);
vec3 ro = vec3(0.25 * sin(iTime * 0.4), 1.15, 2.2 - iTime * 0.55);
vec3 rd = normalize(vec3(uv - vec2(0.0, 0.14), -1.35));
vec3 sky = mix(vec3(0.08, 0.12, 0.20), vec3(0.20, 0.30, 0.48), smoothstep(-0.1, 0.5, uv.y));
vec3 col = sky;
// Perspective textured ground plane + side walls forming an infinite virtual-textured canyon
if (rd.y < -0.01) {
float t = -ro.y / rd.y;
if (t > 0.0 && t < 38.0) {
vec3 p = ro + rd * t;
vec2 vUV = p.xz * 0.25;
// Analytical screen-space mip level from ray distance & grazing angle (feedback pass)
float footprint = t / max(abs(rd.y) * 2.2, 0.12);
float mipFloat = clamp(log2(max(footprint * 0.45, 0.25)) + mipBias, 0.0, 4.2);
float mipIdx = floor(mipFloat);
// Virtual page coordinates at this mip level
float pagesAtMip = max(pageDens / pow(2.0, mipIdx * 0.5), 1.5);
vec2 pageCoord = floor(vUV * pagesAtMip);
vec2 pageFrac = fract(vUV * pagesAtMip);
// Simulate sparse physical page cache residency (a few newly visible tiles streaming in!)
float pageHash = hash21(pageCoord + mipIdx * 13.7);
float resident = step(0.14, fract(pageHash + floor(iTime * 0.8) * 0.07));
float effectiveMip = (resident > 0.5) ? mipIdx : min(mipIdx + 2.0, 4.0);
vec3 texCol = megatexture(vUV, effectiveMip);
float diff = 0.72 + 0.28 * sin(p.x * 0.8) * cos(p.z * 0.8);
// Page border grid
vec2 pf = abs(pageFrac - 0.5);
float pEdge = smoothstep(0.45, 0.495, max(pf.x, pf.y));
if (!isStream) {
// Left: GPU feedback buffer showing requested (pageX, pageY, mip) + sparse cache miss indicators
vec3 fbCol = mipColor(mipIdx);
col = mix(texCol * 0.35, fbCol * 0.92, 0.72);
// Highlight streaming-miss tiles flashing white-cyan while falling back to coarser mip
if (resident < 0.5) {
col = mix(col, vec3(0.95, 0.98, 1.0), 0.55);
}
col = mix(col, vec3(0.04, 0.06, 0.10), pEdge * 0.82);
} else {
// Right: final megatexture sampled via indirection page table -> physical cache atlas
col = texCol * diff;
if (resident < 0.5) {
// Subtle coarser fallback blur tint on newly streamed tile
col = mix(col, megatexture(vUV, 3.5) * diff, 0.65);
}
col = mix(col, vec3(0.15, 0.25, 0.38), pEdge * 0.16);
}
float fog = 1.0 - exp(-t * t * 0.0028);
col = mix(col, sky, clamp(fog, 0.0, 0.92));
}
}
// Bottom-left physical page-cache atlas inset showing packed resident 8x8 tiles
vec2 hudMin = vec2(0.03, 0.05);
vec2 hudSize = vec2(0.24, 0.30);
vec2 hUV = (uv01 - hudMin) / hudSize;
if (hudVis > 0.05 && hUV.x > 0.0 && hUV.x < 1.0 && hUV.y > 0.0 && hUV.y < 1.0) {
vec2 tileId = floor(hUV * 6.0);
vec2 tileF = fract(hUV * 6.0);
float hVal = hash21(tileId + floor(iTime * 0.7) * 0.11);
float slotMip = floor(hVal * 4.5);
float isUsed = step(0.18, hash21(tileId * 3.7 + 2.1));
vec3 slotCol = (isUsed > 0.5) ? mix(mipColor(slotMip), megatexture(tileF + tileId * 0.3, slotMip), 0.45) : vec3(0.06, 0.08, 0.12);
float tBorder = smoothstep(0.44, 0.49, max(abs(tileF.x - 0.5), abs(tileF.y - 0.5)));
slotCol = mix(slotCol, vec3(0.03, 0.04, 0.07), tBorder);
float outerB = min(min(hUV.x, 1.0 - hUV.x), min(hUV.y, 1.0 - hUV.y));
slotCol = mix(slotCol, vec3(0.75, 0.88, 1.0), smoothstep(0.03, 0.008, outerB));
col = mix(col, slotCol, 0.92 * hudVis);
}
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: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| virtual-texturing-live | Tesla T4 1920x1080 | 3.73× baseline (light) · 0.116 ms / 0.118 ms | opengl-timer-query · 36 frames · GPU Weight Atlas · Colab T4 sweep |
| virtual-texturing-live | NVIDIA L4 1920x1080 | 3.09× baseline (light) · 0.049 ms / 0.049 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| virtual-texturing-live | NVIDIA A100-SXM4-40GB 1920x1080 | 2.22× baseline (light) · 0.064 ms / 0.064 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Block-compressed tile streaming inside a hardware-filtered virtual texture cache: Packing gigapixel worlds into block-aligned BC7/ASTC 128x128 tiles with 4-texel (1-block) border gutters streams 4x-6x more unique surface detail into a fixed virtual-texture physical page cache while keeping hardware anisotropic filtering seam-free.
- Basis Universal / KTX2 supercompression: Pages are stored in a supercompressed form and transcoded to the GPU format as they are streamed into the cache.
Sources
- primaryJ.M.P. van Waveren. Software Virtual Textures. mrelusive.com.Verified via live page · 2026-11-29
- tutorialSean Barrett. Sparse Virtual Textures. silverspaceship.com.Verified via live page · 2026-11-29