Texel A field guide to 3D techniques

xatlas × Lightmap Baking × Random-access neural texture compression

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.

Open in StudioReproduced26.7× · 0.827 ms

xatlasGeometry · Offlinein: meshout: uv-atlasuv-atlasLightmap BakingLighting · Real-timein: mesh, uv-atlas, material-paramsout: texturetextureRandom-access neural texture compressionMaterial · Real-timein: texture, material-params, uv-atlasout: texture

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of Neural-compressed directional lightmaps (left: quantized scalar lightmap, right: neural-decoded L1 SH directional lightmap)
Cross-proof specimen. Neural-compressed directional lightmaps (left: quantized scalar lightmap, right: neural-decoded L1 SH directional lightmap). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing a scalar block-quantized baked lightmap with visible chart seams and flattened normal-map relief (left) against a joint neural-decoded L1 spherical-harmonic directional lightmap over padded xatlas UV charts that restores rich normal-mapped stone relief and smooth HDR indirect gradients (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · jointly decodes L0+L1 directional SH lightmaps from compact latent grids without block banding, preserving crisp normal-mapped surface relief

Show GLSL proof (186 lines)
const float P_RELIEF_DEPTH = 1.10; // P Normal-Map Relief [0.2, 2.0, 0.05]
const float P_SH_DIRECTIONAL = 1.00; // P L1 SH Directionality [0.0, 1.6, 0.05]
const float P_BLOCK_QUANT = 14.0; // P Baseline Block Coarseness [6.0, 28.0, 2.0]
const float P_LIGHT_SWEEP = 0.65; // P Skylight Warmth Shift [0.0, 1.5, 0.05]

float hash21(vec2 p) {
  p = fract(p * vec2(123.34, 456.21));
  p += dot(p, p + 45.32);
  return fract(p.x * p.y);
}

float vnoise(vec2 p) {
  vec2 i = floor(p);
  vec2 f = fract(p);
  vec2 u = f * f * (3.0 - 2.0 * f);
  return mix(
    mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),
    mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x),
    u.y
  );
}

// Carved ashlar stone relief height & tangent-space normal map
vec3 masonryNormal(vec2 uv) {
  vec2 brick = vec2(uv.x * 3.0, uv.y * 6.0);
  brick.x += 0.5 * mod(floor(brick.y), 2.0);
  vec2 bf = fract(brick);
  float mortarX = smoothstep(0.0, 0.06, bf.x) * smoothstep(1.0, 0.94, bf.x);
  float mortarY = smoothstep(0.0, 0.09, bf.y) * smoothstep(1.0, 0.91, bf.y);
  float bevel = mortarX * mortarY;
  float e = 0.012;
  float h0 = bevel + 0.16 * vnoise(uv * 24.0) + 0.08 * vnoise(uv * 48.0);
  float hx = (smoothstep(0.0, 0.06, fract(brick.x + e * 3.0)) * smoothstep(1.0, 0.94, fract(brick.x + e * 3.0)) * mortarY
             + 0.16 * vnoise((uv + vec2(e, 0.0)) * 24.0)) - h0;
  float hy = (mortarX * smoothstep(0.0, 0.09, fract(brick.y + e * 6.0)) * smoothstep(1.0, 0.91, fract(brick.y + e * 6.0))
             + 0.16 * vnoise((uv + vec2(0.0, e)) * 24.0)) - h0;
  return normalize(vec3(-hx * 5.2 * P_RELIEF_DEPTH, -hy * 5.2 * P_RELIEF_DEPTH, 1.0));
}

// Multi-resolution neural latent feature encoding + inline 2-layer MLP decoder for L0 + L1 SH lightmap
void decodeNeuralSHLightmap(vec3 wp, vec3 geomN, float t, out vec3 shL0, out vec3 shDirWarm, out vec3 shDirCool) {
  // Analytical latent pyramid features sampled at lightmap chart coordinates (smooth continuous interpolation)
  vec3 warmSrc = vec3(-1.35 + 0.35 * sin(t * 0.55 * P_LIGHT_SWEEP), 0.35, -0.45);
  vec3 coolSrc = vec3(1.35, 1.75, -0.65);
  vec3 dW = warmSrc - wp;
  vec3 dC = coolSrc - wp;
  float rW = length(dW);
  float rC = length(dC);

  // 4-channel latent vector z = [warmAtten, coolAtten, alcoveAO, heightGrad]
  vec4 z = vec4(
    1.0 / (1.0 + rW * rW * 0.82),
    1.0 / (1.0 + rC * rC * 0.65),
    clamp(1.0 - exp(-abs(wp.x) * 0.65) * 0.35, 0.25, 1.0),
    clamp(wp.y * 0.45 + 0.5, 0.0, 1.0)
  );

  // Layer 1 MLP hidden activations (tanh nonlinearity across correlated lighting channels)
  vec4 h = vec4(
    tanh(dot(z, vec4(1.85, -0.25, 0.35, 0.15))),
    tanh(dot(z, vec4(-0.15, 1.95, 0.42, 0.55))),
    tanh(dot(z, vec4(0.65, 0.65, 0.85, -0.20))),
    tanh(dot(z, vec4(0.95, -0.80, 0.10, 0.40)))
  );

  // Layer 2 joint decode -> log-HDR L0 irradiance + directional dominance vectors
  float wGain = exp(h.x * 1.45) - 0.72;
  float cGain = exp(h.y * 1.40) - 0.68;
  vec3 warmCol = vec3(2.45, 0.96, 0.34) * max(wGain, 0.0);
  vec3 coolCol = vec3(0.36, 0.78, 1.65) * max(cGain, 0.0);
  shL0 = (warmCol + coolCol) * (0.42 + 0.35 * h.z);
  shDirWarm = normalize(dW) * max(wGain, 0.0);
  shDirCool = normalize(dC) * max(cGain, 0.0);
}

// Vaulted atrium room SDF (negative inside room)
float mapAtrium(vec3 p, out int matId) {
  // Box interior [-1.9, 1.9] x [-1.0, 1.6] x [-3.2, 2.0]
  float wallX = 1.90 - abs(p.x);
  float floorY = p.y + 1.00;
  float ceilY = 1.55 - p.y;
  float backZ = p.z + 2.85;
  // Arched barrel vault ceiling
  float vault = 1.95 - length(vec2(p.x, p.y - 0.35));
  float room = min(min(wallX, min(floorY, max(ceilY, vault))), backZ);

  // Central carved fluted stone pillar
  float pil = length(p.xz - vec2(0.0, -1.25)) - 0.44;
  pil = max(pil, abs(p.y - 0.25) - 1.35);
  // Left & right side pilasters
  float pL = max(length(p.xz - vec2(-1.62, -1.35)) - 0.30, abs(p.y - 0.25) - 1.35);
  float pR = max(length(p.xz - vec2(1.62, -1.35)) - 0.30, abs(p.y - 0.25) - 1.35);
  float d = min(room, min(pil, min(pL, pR)));
  matId = (d == pil || d == pL || d == pR) ? 2 : 1;
  return d;
}

vec3 calcNormal(vec3 p) {
  float e = 0.004;
  int m;
  return normalize(vec3(
    mapAtrium(p + vec3(e, 0.0, 0.0), m) - mapAtrium(p - vec3(e, 0.0, 0.0), m),
    mapAtrium(p + vec3(0.0, e, 0.0), m) - mapAtrium(p - vec3(0.0, e, 0.0), m),
    mapAtrium(p + vec3(0.0, 0.0, e), m) - mapAtrium(p - vec3(0.0, 0.0, e), m)
  ));
}

vec3 acesTone(vec3 x) {
  return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
  bool useNTC = uv.x > 0.0;
  vec2 suv = vec2(useNTC ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
  suv.x *= 1.82;

  float sway = sin(iTime * 0.38) * 0.22;
  vec3 ro = vec3(sway, 0.12, 1.55);
  vec3 target = vec3(0.0, 0.05, -1.55);
  vec3 fwd = normalize(target - ro);
  vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), fwd));
  vec3 up = cross(fwd, right);
  vec3 rd = normalize(fwd * 1.48 + right * suv.x + up * suv.y);

  float t = 0.0;
  int matId = 0;
  for (int i = 0; i < 64; i++) {
    vec3 p = ro + rd * t;
    float d = mapAtrium(p, matId);
    if (d < 0.003 || t > 9.0) break;
    t += d * 0.85;
  }

  vec3 col = vec3(0.02, 0.03, 0.05);
  if (t < 8.8) {
    vec3 wp = ro + rd * t;
    vec3 N = calcNormal(wp);
    // Triplanar / xatlas UV chart coordinates
    vec2 chartUV = abs(N.y) > 0.7 ? wp.xz : (abs(N.x) > 0.7 ? wp.zy : wp.xy);
    vec3 T = normalize(abs(N.y) > 0.7 ? vec3(1.0, 0.0, 0.0) : cross(N, vec3(0.0, 1.0, 0.0)));
    vec3 B = cross(N, T);

    vec3 nMap = masonryNormal(chartUV * 0.85);
    vec3 detailN = normalize(T * nMap.x + B * nMap.y + N * nMap.z);
    vec3 stoneAlb = (matId == 2) ? vec3(0.66, 0.61, 0.54) : vec3(0.58, 0.55, 0.50);
    stoneAlb *= (0.86 + 0.24 * vnoise(chartUV * 9.0));

    if (!useNTC) {
      // Left: coarse block-quantized scalar lightmap (no L1 directionality -> flat relief + BC blocky artifacts + chart seam bleed)
      vec3 qWp = floor(wp * P_BLOCK_QUANT) / P_BLOCK_QUANT;
      vec3 l0, dw, dc;
      decodeNeuralSHLightmap(qWp, N, iTime, l0, dw, dc);
      // Simulate 5-bit scalar quantization banding & unpadded xatlas chart border bleed
      vec3 bandL0 = floor(l0 * 9.0) / 9.0;
      vec2 chartEdge = abs(fract(chartUV * 0.5) - 0.5);
      float seamBleed = smoothstep(0.45, 0.495, max(chartEdge.x, chartEdge.y));
      col = stoneAlb * mix(bandL0, vec3(0.08, 0.07, 0.09), seamBleed * 0.72);
    } else {
      // Right: continuous neural-decoded L0 + L1 directional SH lightmap driving crisp normal-mapped stone relief
      vec3 shL0, shDirW, shDirC;
      decodeNeuralSHLightmap(wp, N, iTime, shL0, shDirW, shDirC);
      float wLen = length(shDirW);
      float cLen = length(shDirC);
      vec3 wDir = shDirW / max(wLen, 1e-4);
      vec3 cDir = shDirC / max(cLen, 1e-4);

      // Evaluate L1 spherical harmonic directional irradiance against detail normal
      float shWarm = (0.35 + 0.65 * max(dot(detailN, wDir), 0.0) * P_SH_DIRECTIONAL);
      float shCool = (0.35 + 0.65 * max(dot(detailN, cDir), 0.0) * P_SH_DIRECTIONAL);
      vec3 irr = vec3(2.35, 0.94, 0.34) * wLen * shWarm + vec3(0.36, 0.80, 1.72) * cLen * shCool;
      // Directional grazing specular sheen reconstructed from L1 dominant direction
      vec3 V = -rd;
      float specW = pow(max(dot(detailN, normalize(wDir + V)), 0.0), 28.0) * wLen;
      float specC = pow(max(dot(detailN, normalize(cDir + V)), 0.0), 28.0) * cLen;
      col = stoneAlb * (shL0 * 0.28 + irr * 0.78) + vec3(1.1, 0.65, 0.32) * specW * 0.22 + vec3(0.42, 0.74, 1.1) * specC * 0.20;
    }
    // Emissive warm lantern & cool skylight accents visible in atrium
    float dWarm = length(wp - vec3(-1.35 + 0.35 * sin(iTime * 0.55 * P_LIGHT_SWEEP), 0.35, -0.45));
    col += vec3(2.8, 1.1, 0.35) * exp(-dWarm * dWarm * 8.0) * 0.45;
  }

  col = acesTone(col * 1.15);
  if (abs(uv.x) < 0.003) col = vec3(0.95, 0.93, 0.89);
  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}

Why they connect

xatlas outputs a uv-atlas with charts and padding for every static mesh. Lightmap Baking consumes the mesh, that atlas and the materials, and outputs a texture set: irradiance plus directional coefficients per texel. Random-access neural texture compression takes those textures (and the atlas, which matters for padding) as its input and trains one latent pyramid and decoder for all channels together. At runtime the shader decodes the lightmap channels at the lightmap UV in one network evaluation and reconstructs directional irradiance for the normal-mapped surface.

How to build it

Offline tool: unwrap with xatlas, bake L1 spherical-harmonic lightmaps (one RGB term plus three directional RGB terms) with a path tracer and denoiser, then log-encode the HDR values. Train NTC latents per scene or per lighting zone, masking out padding texels and weighting chart borders so interpolation does not bleed across charts. Export latents and decoder weights. In a D3D12 or Vulkan renderer with cooperative-matrix support, decode at the lightmap UV and evaluate SH irradiance with the normal map. Compare size and error against BC6H for each band at equal quality before committing.

Field marks

  1. Latent interpolation bleeds across chart borders and shows as seams.
  2. HDR range needs careful encoding or bright areas clip.
  3. Per-scene training lengthens the bake-and-iterate loop.
  4. Needs matrix hardware; other platforms need a block-compressed fallback.

Prior art

  1. Furinasd/tgac-pipelines. Same idea, extended in time: stores each lightmap as learned feature grids plus a small decoder reconstructed in the UE5 lightmap path, conditioned on position and time of day (per its README).
Searches run (4)
  • arXiv: all:"neural texture compression" AND all:"lightmap" → 0 results
  • GitHub repos: "neural texture compression" lightmap → 0 results
  • arXiv: all:"lightmap compression" AND all:"neural" → 0 results
  • GitHub repos: "lightmap compression" neural → 1 result