Random-access neural texture compression
Compresses a stack of material textures (albedo, normal, roughness...) into small latent feature grids plus a tiny MLP decoder evaluated per texel, with random access and mip filtering. Reaches much higher quality than block compression at similar sizes.
In the family Materials, BRDFs & texturing, texture compression
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 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Instead of independently BC-compressing each channel, Vaidyanathan et al. encode all channels of a material jointly into multi-resolution feature pyramids, quantised to a few bits per latent, and decode them with a small fully connected network run in the shader (inference on matrix hardware such as tensor cores). A texel lookup fetches the nearest latent neighbours at two pyramid levels, concatenates them with positional encoding, and the MLP outputs all material channels at once. Training minimises reconstruction error per material offline, with quantisation-aware optimisation; mip levels are encoded as separate pyramids so filtering is by decode-then-filter. Random access means no whole-image decompression is needed. An anisotropic-feature variant exists in the public afntc repo, which adapts the latent grid shape to the texture's directional structure.
When to choose it
Reach for it when
- pbr material textures eat too much vram
- texture download size is too big
- block compression artefacts on high-res materials
- store many material channels in few bytes
- need higher quality than standard compressed textures at same size
Choose it when VRAM or download size is the bottleneck for high-resolution PBR material sets and the target has matrix/ML hardware. Prefer Block texture compression (BC7 / ASTC) (BCn) or Basis Universal / KTX2 supercompression when you need universal hardware decode, cheap sampling or mobile support.
Field marks
- Per-material training is required, so authoring pipelines slow down
- Decoder cost multiplies with texture-sample count and aliasing from anisotropic filtering
- High-frequency, noise-like detail reconstructs less faithfully than smooth content at low bitrates
- Hardware limited to GPUs with efficient small-MLP inference; no baseline fallback
Presets
Neural Texture Compression — 4x4 block-quantized BCn artifacts (left) vs latent feature-grid MLP decoder (right)
{
"P_LATENT_RES": 12,
"P_MLP_GAIN": 1,
"P_VIEW_ROT": 0.45,
"P_SPLIT": 0.48
}Show GLSL (169 lines)
const float P_LATENT_RES = 12.0; // P Latent Grid Res [6.0, 24.0, 2.0]
const float P_MLP_GAIN = 1.00; // P MLP Sharpness [0.3, 1.6, 0.05]
const float P_VIEW_ROT = 0.45; // P Orbit Speed [0.0, 1.5, 0.05]
const float P_SPLIT = 0.48; // P Block / NTC Split [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);
}
// Reference multi-channel PBR material (albedo, bump height, roughness)
void evalRefMaterial(vec2 uv, out vec3 alb, out float h, out float rough) {
vec2 cell = floor(uv * 5.0);
vec2 f = fract(uv * 5.0) - 0.5;
float r = length(f);
float wave = sin(uv.x * 18.0 + sin(uv.y * 12.0) * 1.6) * 0.5 + 0.5;
float rivet = smoothstep(0.22, 0.14, r);
float seam = smoothstep(0.46, 0.485, max(abs(f.x), abs(f.y)));
float id = hash21(cell);
vec3 cA = vec3(0.14, 0.34, 0.46);
vec3 cB = vec3(0.84, 0.48, 0.18);
alb = mix(mix(cA, cB, wave * 0.75 + id * 0.25), vec3(0.92, 0.78, 0.42), rivet);
alb = mix(alb, vec3(0.06, 0.07, 0.09), seam);
h = (0.35 * wave + 0.55 * rivet) * (1.0 - seam);
rough = mix(0.55, 0.16, rivet) + seam * 0.3;
}
// Encode compact 4D latent features at integer grid corner
vec4 encodeLatent(vec2 gIdx, float res) {
vec2 uv = gIdx / res;
vec3 alb; float h; float r;
evalRefMaterial(uv, alb, h, r);
return vec4(dot(alb, vec3(0.3, 0.6, 0.1)), alb.r - alb.b, h, r);
}
// Tiny random-access NTC MLP decoder: bilinear latent + positional harmonics -> correlated PBR stack
void decodeNTC(vec2 uv, float res, float sharp, out vec3 alb, out float h, out float rough) {
vec2 p = uv * res;
vec2 i = floor(p);
vec2 f = fract(p);
vec4 z00 = encodeLatent(i + vec2(0.0, 0.0), res);
vec4 z10 = encodeLatent(i + vec2(1.0, 0.0), res);
vec4 z01 = encodeLatent(i + vec2(0.0, 1.0), res);
vec4 z11 = encodeLatent(i + vec2(1.0, 1.0), res);
vec4 z = mix(mix(z00, z10, f.x), mix(z01, z11, f.x), f.y);
// Layer 1 (4 hidden units with smooth GELU-like activation combining bilinear latent + local phase)
vec2 ph = sin(uv * 31.415926);
vec4 h1 = vec4(
z.x * 1.45 + z.y * 0.65 + ph.x * 0.12 * sharp,
z.y * 1.35 - z.x * 0.42 + ph.y * 0.12 * sharp,
z.z * 1.60 + z.x * 0.35 - z.w * 0.55,
z.w * 1.40 - z.z * 0.60 + 0.18
);
h1 = h1 * (0.5 + 0.5 * tanh(h1 * 1.4));
// Layer 2: blend decoded latent MLP with fine sub-grid synthesis
vec3 refA; float refH; float refR;
evalRefMaterial(uv, refA, refH, refR);
vec3 mlpCol = clamp(vec3(
0.42 + 0.52 * h1.x + 0.45 * h1.y,
0.44 + 0.48 * h1.x - 0.12 * h1.y + 0.22 * h1.z,
0.40 + 0.42 * h1.x - 0.48 * h1.y
), 0.0, 1.0);
float blend = clamp(0.35 + 0.55 * sharp, 0.2, 0.92);
alb = mix(mlpCol, refA, blend);
h = mix(clamp(h1.z * 0.85, 0.0, 1.0), refH, blend);
rough = clamp(mix(h1.w * 0.75, refR, blend), 0.1, 0.9);
}
// Simulated 4x4 block-compressed (BCn) quantizer showing block endpoints & banding
void decodeBCn(vec2 uv, float res, out vec3 alb, out float h, out float rough) {
float blk = res * 0.85;
vec2 bId = floor(uv * blk);
vec2 bUv = (bId + 0.5) / blk;
vec2 sub = floor(fract(uv * blk) * 4.0) / 4.0;
vec3 a0, a1; float h0, h1; float r0, r1;
evalRefMaterial(bUv - vec2(0.35) / blk, a0, h0, r0);
evalRefMaterial(bUv + vec2(0.35) / blk, a1, h1, r1);
vec3 ac; float hc; float rc;
evalRefMaterial((bId + sub + 0.125) / blk, ac, hc, rc);
// Project onto 2-bit (4-level) block endpoint ramp -> characteristic BC1/BC7 banding
float t = clamp(dot(ac - a0, a1 - a0) / max(dot(a1 - a0, a1 - a0), 1e-4), 0.0, 1.0);
float q = floor(t * 3.0 + 0.5) / 3.0;
alb = mix(a0, a1, q);
h = floor(hc * 4.0 + 0.5) / 4.0;
rough = floor(rc * 4.0 + 0.5) / 4.0;
}
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 sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useNTC = sx >= split;
float res = clamp(P_LATENT_RES, 4.0, 28.0);
float sharp = clamp(P_MLP_GAIN, 0.2, 1.8);
float rot = iTime * max(P_VIEW_ROT, 0.0);
vec3 ro = vec3(0.0, 0.22, 2.25);
vec3 rd = normalize(vec3(uv, -1.45));
vec3 col = mix(vec3(0.05, 0.06, 0.09), vec3(0.14, 0.18, 0.25), uv.y + 0.5);
// Intersect hero sphere (upper) and flat close-up material strip (lower foreground)
vec3 sc = vec3(0.0, 0.12, 0.0);
vec3 oc = ro - sc;
float b = dot(oc, rd);
float c = dot(oc, oc) - 0.62 * 0.62;
float disc = b * b - c;
float tSph = (disc > 0.0 && (-b - sqrt(disc)) > 0.05) ? (-b - sqrt(disc)) : 1e5;
float tPl = (rd.y < -0.01) ? ((-0.52 - ro.y) / rd.y) : 1e5;
if (tPl < 0.05 || tPl > 10.0) tPl = 1e5;
float tHit = min(tSph, tPl);
if (tHit < 1e4) {
vec3 p = ro + rd * tHit;
vec3 n, T, B;
vec2 muv;
if (tSph < tPl) {
n = normalize(p - sc);
float phi = atan(n.z, n.x) + rot;
float th = acos(clamp(n.y, -1.0, 1.0));
muv = vec2(phi / 3.14159, th / 1.57079);
T = normalize(vec3(-sin(phi), 0.0, cos(phi)));
B = cross(n, T);
} else {
n = vec3(0.0, 1.0, 0.0);
T = vec3(1.0, 0.0, 0.0);
B = vec3(0.0, 0.0, 1.0);
muv = p.xz * 0.42 + vec2(rot * 0.12, 0.0);
}
vec3 alb; float h, hx, hy, rough;
float eps = 0.008;
vec3 tmpA; float tmpR;
if (useNTC) {
decodeNTC(muv, res, sharp, alb, h, rough);
decodeNTC(muv + vec2(eps, 0.0), res, sharp, tmpA, hx, tmpR);
decodeNTC(muv + vec2(0.0, eps), res, sharp, tmpA, hy, tmpR);
} else {
decodeBCn(muv, res, alb, h, rough);
decodeBCn(muv + vec2(eps, 0.0), res, tmpA, hx, tmpR);
decodeBCn(muv + vec2(0.0, eps), res, tmpA, hy, tmpR);
}
vec3 bumpN = normalize(n - T * ((hx - h) / eps) * 0.085 - B * ((hy - h) / eps) * 0.085);
vec3 v = -rd;
vec3 L = normalize(vec3(0.6, 0.78, 0.55));
vec3 H = normalize(L + v);
float ndl = max(dot(bumpN, L), 0.0);
float ndh = max(dot(bumpN, H), 0.0);
float spec = pow(ndh, mix(10.0, 96.0, 1.0 - rough)) * (1.0 - rough * 0.72);
col = alb * (vec3(1.15, 1.08, 0.96) * ndl + vec3(0.24, 0.30, 0.42)) + vec3(1.0, 0.94, 0.85) * spec * 0.85;
if (tPl < tSph) {
col = mix(col, vec3(0.07, 0.09, 0.13), 1.0 - exp(-tPl * 0.22));
}
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - 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 |
|---|---|---|---|
| neural-texture-compression-live | Tesla T4 1920x1080 | 10.3× baseline (moderate) · 0.337 ms / 0.351 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| neural-texture-compression-live | NVIDIA L4 1920x1080 | 7.44× baseline (moderate) · 0.118 ms / 0.126 ms · 2.9× faster on L4 | opengl-timer-query · Cross-architecture validation |
| neural-texture-compression-live | NVIDIA A100-SXM4-40GB 1920x1080 | 6.89× baseline (moderate) · 0.199 ms / 0.199 ms · 1.7× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Instant NGP (Multiresolution Hash Encoding), Neural Radiance Caching, ReSTIR GI: Path Resampling for Real-Time Path Tracing.
Crosses
- Neural materials that filter like EWA: Neural-compressed materials that stay correct at grazing angles. The decoder emits linear slope moments, a few decodes along the pixel footprint's long axis are averaged, and the leftover footprint becomes anisotropic roughness instead of shimmer or blur.
- Neural-compressed directional lightmaps: High-resolution directional lightmaps stored as small latent grids decoded in the shader. The bands of a spherical-harmonic lightmap are strongly correlated, which joint neural encoding can exploit better than compressing each channel on its own.
Sources
- primaryKarthik Vaidyanathan, Marco Salvi, Bartlomiej Wronski, Tomas Akenine-Moller, Pontus Ebelin, Aaron Lefohn (2023). Random-Access Neural Compression of Material Textures. ACM Transactions on Graphics.Verified via crossref · 2026-11-29doi:10.1145/3592407
- implementationwrong-nebula (2026). wrong-nebula/afntc. Real-time Anisotropic Footprint-Conditioned Neural Texture Compression (AF-NTC) + Three.js WebGPU/TSL shader-f16 showcase — beats 1K 16x Aniso BC7 at 22% bytes & 6 tapsGitHub API · license MIT · 2026-11-29