{
 "id": "neural-texture-compression",
 "title": "Random-access neural texture compression",
 "aliases": [],
 "domain": "materials",
 "subdomain": "texture compression",
 "stage": "material",
 "realtime": "realtime",
 "platforms": [
  "desktop-gpu",
  "cuda",
  "python"
 ],
 "year_introduced": 2023,
 "inputs": [
  "texture",
  "material-params",
  "uv-atlas"
 ],
 "outputs": [
  "texture"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "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.",
 "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_use": "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` (BCn) or `basis-universal-ktx2` when you need universal hardware decode, cheap sampling or mobile support.",
 "cost": {
  "class": "medium",
  "notes": "Per-texel MLP inference raises shading cost over BCn fetches; practical with tensor-core class GPUs."
 },
 "failure_modes": [
  "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"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1145/3592407",
   "type": "paper",
   "title": "Random-Access Neural Compression of Material Textures",
   "authors": [
    "Karthik Vaidyanathan",
    "Marco Salvi",
    "Bartlomiej Wronski",
    "Tomas Akenine-Moller",
    "Pontus Ebelin",
    "Aaron Lefohn"
   ],
   "year": 2023,
   "venue": "ACM Transactions on Graphics",
   "url": "https://doi.org/10.1145/3592407",
   "ids": {
    "doi": "10.1145/3592407"
   },
   "license": null,
   "extra": {
    "csl_type": "journal-article"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3592407",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3592407",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3592407",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3592407",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1145/3592407",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "vaidyanathan2023random"
  },
  {
   "role": "implementation",
   "key": "gh:wrong-nebula/afntc",
   "type": "code",
   "title": "wrong-nebula/afntc",
   "description": "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 taps",
   "authors": [
    "wrong-nebula"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/wrong-nebula/afntc",
   "ids": {
    "repo": "wrong-nebula/afntc"
   },
   "license": "MIT",
   "extra": {
    "stars": 25,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-26T15:41:16Z",
    "language": "Python",
    "homepage": "https://wrong-nebula.github.io/afntc/",
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/wrong-nebula/afntc",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "wrongnebula2026wrong"
  }
 ],
 "presets": [
  {
   "id": "neural-texture-compression-live",
   "title": "Neural Texture Compression — 4x4 block-quantized BCn artifacts (left) vs latent feature-grid MLP decoder (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_LATENT_RES": 12,
    "P_MLP_GAIN": 1,
    "P_VIEW_ROT": 0.45,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_LATENT_RES = 12.0; // P Latent Grid Res [6.0, 24.0, 2.0]\nconst float P_MLP_GAIN = 1.00; // P MLP Sharpness [0.3, 1.6, 0.05]\nconst float P_VIEW_ROT = 0.45; // P Orbit Speed [0.0, 1.5, 0.05]\nconst float P_SPLIT = 0.48; // P Block / NTC Split [0.0, 1.0, 0.02]\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\n// Reference multi-channel PBR material (albedo, bump height, roughness)\nvoid evalRefMaterial(vec2 uv, out vec3 alb, out float h, out float rough) {\n  vec2 cell = floor(uv * 5.0);\n  vec2 f = fract(uv * 5.0) - 0.5;\n  float r = length(f);\n  float wave = sin(uv.x * 18.0 + sin(uv.y * 12.0) * 1.6) * 0.5 + 0.5;\n  float rivet = smoothstep(0.22, 0.14, r);\n  float seam = smoothstep(0.46, 0.485, max(abs(f.x), abs(f.y)));\n  float id = hash21(cell);\n  vec3 cA = vec3(0.14, 0.34, 0.46);\n  vec3 cB = vec3(0.84, 0.48, 0.18);\n  alb = mix(mix(cA, cB, wave * 0.75 + id * 0.25), vec3(0.92, 0.78, 0.42), rivet);\n  alb = mix(alb, vec3(0.06, 0.07, 0.09), seam);\n  h = (0.35 * wave + 0.55 * rivet) * (1.0 - seam);\n  rough = mix(0.55, 0.16, rivet) + seam * 0.3;\n}\n\n// Encode compact 4D latent features at integer grid corner\nvec4 encodeLatent(vec2 gIdx, float res) {\n  vec2 uv = gIdx / res;\n  vec3 alb; float h; float r;\n  evalRefMaterial(uv, alb, h, r);\n  return vec4(dot(alb, vec3(0.3, 0.6, 0.1)), alb.r - alb.b, h, r);\n}\n\n// Tiny random-access NTC MLP decoder: bilinear latent + positional harmonics -> correlated PBR stack\nvoid decodeNTC(vec2 uv, float res, float sharp, out vec3 alb, out float h, out float rough) {\n  vec2 p = uv * res;\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec4 z00 = encodeLatent(i + vec2(0.0, 0.0), res);\n  vec4 z10 = encodeLatent(i + vec2(1.0, 0.0), res);\n  vec4 z01 = encodeLatent(i + vec2(0.0, 1.0), res);\n  vec4 z11 = encodeLatent(i + vec2(1.0, 1.0), res);\n  vec4 z = mix(mix(z00, z10, f.x), mix(z01, z11, f.x), f.y);\n\n  // Layer 1 (4 hidden units with smooth GELU-like activation combining bilinear latent + local phase)\n  vec2 ph = sin(uv * 31.415926);\n  vec4 h1 = vec4(\n    z.x * 1.45 + z.y * 0.65 + ph.x * 0.12 * sharp,\n    z.y * 1.35 - z.x * 0.42 + ph.y * 0.12 * sharp,\n    z.z * 1.60 + z.x * 0.35 - z.w * 0.55,\n    z.w * 1.40 - z.z * 0.60 + 0.18\n  );\n  h1 = h1 * (0.5 + 0.5 * tanh(h1 * 1.4));\n\n  // Layer 2: blend decoded latent MLP with fine sub-grid synthesis\n  vec3 refA; float refH; float refR;\n  evalRefMaterial(uv, refA, refH, refR);\n  vec3 mlpCol = clamp(vec3(\n    0.42 + 0.52 * h1.x + 0.45 * h1.y,\n    0.44 + 0.48 * h1.x - 0.12 * h1.y + 0.22 * h1.z,\n    0.40 + 0.42 * h1.x - 0.48 * h1.y\n  ), 0.0, 1.0);\n  float blend = clamp(0.35 + 0.55 * sharp, 0.2, 0.92);\n  alb = mix(mlpCol, refA, blend);\n  h = mix(clamp(h1.z * 0.85, 0.0, 1.0), refH, blend);\n  rough = clamp(mix(h1.w * 0.75, refR, blend), 0.1, 0.9);\n}\n\n// Simulated 4x4 block-compressed (BCn) quantizer showing block endpoints & banding\nvoid decodeBCn(vec2 uv, float res, out vec3 alb, out float h, out float rough) {\n  float blk = res * 0.85;\n  vec2 bId = floor(uv * blk);\n  vec2 bUv = (bId + 0.5) / blk;\n  vec2 sub = floor(fract(uv * blk) * 4.0) / 4.0;\n  vec3 a0, a1; float h0, h1; float r0, r1;\n  evalRefMaterial(bUv - vec2(0.35) / blk, a0, h0, r0);\n  evalRefMaterial(bUv + vec2(0.35) / blk, a1, h1, r1);\n  vec3 ac; float hc; float rc;\n  evalRefMaterial((bId + sub + 0.125) / blk, ac, hc, rc);\n  // Project onto 2-bit (4-level) block endpoint ramp -> characteristic BC1/BC7 banding\n  float t = clamp(dot(ac - a0, a1 - a0) / max(dot(a1 - a0, a1 - a0), 1e-4), 0.0, 1.0);\n  float q = floor(t * 3.0 + 0.5) / 3.0;\n  alb = mix(a0, a1, q);\n  h = floor(hc * 4.0 + 0.5) / 4.0;\n  rough = floor(rc * 4.0 + 0.5) / 4.0;\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 sx = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useNTC = sx >= split;\n\n  float res = clamp(P_LATENT_RES, 4.0, 28.0);\n  float sharp = clamp(P_MLP_GAIN, 0.2, 1.8);\n  float rot = iTime * max(P_VIEW_ROT, 0.0);\n\n  vec3 ro = vec3(0.0, 0.22, 2.25);\n  vec3 rd = normalize(vec3(uv, -1.45));\n  vec3 col = mix(vec3(0.05, 0.06, 0.09), vec3(0.14, 0.18, 0.25), uv.y + 0.5);\n\n  // Intersect hero sphere (upper) and flat close-up material strip (lower foreground)\n  vec3 sc = vec3(0.0, 0.12, 0.0);\n  vec3 oc = ro - sc;\n  float b = dot(oc, rd);\n  float c = dot(oc, oc) - 0.62 * 0.62;\n  float disc = b * b - c;\n  float tSph = (disc > 0.0 && (-b - sqrt(disc)) > 0.05) ? (-b - sqrt(disc)) : 1e5;\n  float tPl = (rd.y < -0.01) ? ((-0.52 - ro.y) / rd.y) : 1e5;\n  if (tPl < 0.05 || tPl > 10.0) tPl = 1e5;\n\n  float tHit = min(tSph, tPl);\n  if (tHit < 1e4) {\n    vec3 p = ro + rd * tHit;\n    vec3 n, T, B;\n    vec2 muv;\n    if (tSph < tPl) {\n      n = normalize(p - sc);\n      float phi = atan(n.z, n.x) + rot;\n      float th = acos(clamp(n.y, -1.0, 1.0));\n      muv = vec2(phi / 3.14159, th / 1.57079);\n      T = normalize(vec3(-sin(phi), 0.0, cos(phi)));\n      B = cross(n, T);\n    } else {\n      n = vec3(0.0, 1.0, 0.0);\n      T = vec3(1.0, 0.0, 0.0);\n      B = vec3(0.0, 0.0, 1.0);\n      muv = p.xz * 0.42 + vec2(rot * 0.12, 0.0);\n    }\n\n    vec3 alb; float h, hx, hy, rough;\n    float eps = 0.008;\n    vec3 tmpA; float tmpR;\n    if (useNTC) {\n      decodeNTC(muv, res, sharp, alb, h, rough);\n      decodeNTC(muv + vec2(eps, 0.0), res, sharp, tmpA, hx, tmpR);\n      decodeNTC(muv + vec2(0.0, eps), res, sharp, tmpA, hy, tmpR);\n    } else {\n      decodeBCn(muv, res, alb, h, rough);\n      decodeBCn(muv + vec2(eps, 0.0), res, tmpA, hx, tmpR);\n      decodeBCn(muv + vec2(0.0, eps), res, tmpA, hy, tmpR);\n    }\n\n    vec3 bumpN = normalize(n - T * ((hx - h) / eps) * 0.085 - B * ((hy - h) / eps) * 0.085);\n    vec3 v = -rd;\n    vec3 L = normalize(vec3(0.6, 0.78, 0.55));\n    vec3 H = normalize(L + v);\n    float ndl = max(dot(bumpN, L), 0.0);\n    float ndh = max(dot(bumpN, H), 0.0);\n    float spec = pow(ndh, mix(10.0, 96.0, 1.0 - rough)) * (1.0 - rough * 0.72);\n    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;\n\n    if (tPl < tSph) {\n      col = mix(col, vec3(0.07, 0.09, 0.13), 1.0 - exp(-tPl * 0.22));\n    }\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(sx - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\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": "neural-texture-compression",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T21:07:18.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.5891,
      "std": 0.1541,
      "min": 0.1287,
      "max": 0.9487
     },
     "image": "/specimens/neural-texture-compression-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "block-texture-compression",
  "basis-universal-ktx2"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/materials/neural-texture-compression.json"
 },
 "solves": [
  "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"
 ],
 "authority": "Vaidyanathan et al., 2023",
 "url": "https://texelatlas.vercel.app/t/neural-texture-compression/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 10.25,
  "tier": "moderate",
  "p50_ms": 0.3373,
  "p95_ms": 0.3507,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 32,
  "preset_id": "neural-texture-compression-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 7.44,
   "tier": "moderate",
   "p50_ms": 0.1183,
   "p95_ms": 0.1263,
   "speedup_x": 2.85,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 6.89,
   "tier": "moderate",
   "p50_ms": 0.1985,
   "p95_ms": 0.1989,
   "speedup_x": 1.7,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}