Texel A field guide to 3D techniques

Wave Function Collapse × Voxel Cone Tracing

Generated levels with free voxel GI. Tile-based generated levels get dynamic global illumination with no voxelisation pass: the solver's voxel grid is the cone-tracing volume. Each tile type carries pre-voxelised directional opacity, so thin walls stop leaking light.

Open in StudioReproduced65.3× · 2.03 ms

Wave Function CollapseProcedural · Interactivein: texture, layoutout: texture, voxels, layoutvoxelsVoxel Cone TracingLighting · Real-timein: mesh, voxels, gbufferout: radiance

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of WFC voxels as GI volume (left: direct light + flat ambient, right: 5-cone voxel cone tracing directly on WFC grid)
Cross-proof specimen. WFC voxels as GI volume (left: direct light + flat ambient, right: 5-cone voxel cone tracing directly on WFC grid). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing a Wave Function Collapse modular voxel sanctuary lit by direct sun and flat ambient fill only (left, leaving shaded archways lifeless and grey) against repurposing the identical WFC voxel grid directly as a multi-mip radiance volume for 5-cone voxel cone tracing where emissive lava channels and cyan crystal tiles cast rich bounced GI and soft cone AO (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · reuses WFC modular level tiles directly as an emissive GI clipmap, producing soft cone AO and vivid dual-color bounce light inside shadowed alcoves

Show GLSL proof (195 lines)
const float P_GI_BOUNCE = 1.45; // P VCT Bounce Gain [0.2, 2.8, 0.05]
const float P_CONE_AO = 1.00; // P Cone Occlusion [0.0, 1.8, 0.05]
const float P_EMISSIVE = 1.35; // P Tile Emissive Power [0.2, 2.5, 0.05]
const float P_CAM_SWAY = 0.65; // P Camera Sway [0.0, 1.5, 0.05]

// WFC modular voxel sanctuary: returns tile ID (0=air, 1=limestone block, 2=lava channel, 3=cyan crystal, 4=terracotta trim)
int sampleWFC(ivec3 v) {
  if (v.x < -7 || v.x > 7 || v.y < 0 || v.y > 7 || v.z < -7 || v.z > 7) return 0;
  // Floor slab with recessed glowing lava trench (left) and crystal channel (right)
  if (v.y == 0) {
    if (v.x == -3 && abs(v.z) <= 5) return 2;
    if (v.x == 3 && abs(v.z) <= 5) return 3;
    return 1;
  }
  // Back sanctuary wall with modular archways
  if (v.z == -6) {
    if (v.y <= 5 && (abs(v.x) == 5 || abs(v.x) == 1)) return 1;
    if (v.y == 5 || v.y == 6) return 4;
    if (v.y == 2 && v.x == 0) return 3;
    if (v.y <= 4 && abs(v.x) > 5) return 1;
    return 0;
  }
  // Repeating WFC modular colonnade pillars + overhead lintels
  bool pillarXZ = (abs(v.x) == 5 || abs(v.x) == 1) && (v.z == -2 || v.z == 2 || v.z == 6);
  if (pillarXZ && v.y <= 5) return (v.y == 5) ? 4 : 1;
  if (v.y == 5 && (abs(v.x) == 5 || abs(v.x) == 1) && v.z >= -6 && v.z <= 6) return 4;
  // Emissive shrine braziers perched on plinths
  if (v.y == 1 && abs(v.x) == 3 && v.z == -4) return (v.x < 0) ? 2 : 3;
  if (v.y == 2 && v.x == -3 && v.z == -4) return 2;
  if (v.y == 2 && v.x == 3 && v.z == -4) return 3;
  return 0;
}

// Multi-mip smooth approximation of the WFC voxel volume (opacity + emitted/bounced radiance at cone radius r)
vec4 sampleWFCVolumeMip(vec3 p, float r) {
  // Blend exact voxel sample with smooth analytical coarse-mip radiance of the emissive WFC channels
  ivec3 iv = ivec3(floor(p));
  int m = sampleWFC(iv);
  float occ = (m > 0) ? 1.0 : 0.0;
  vec3 rad = vec3(0.0);
  if (m == 2) rad = vec3(3.4, 0.95, 0.18) * P_EMISSIVE;
  else if (m == 3) rad = vec3(0.22, 2.25, 3.20) * P_EMISSIVE;
  else if (m == 1) rad = vec3(0.14, 0.13, 0.12);
  else if (m == 4) rad = vec3(0.22, 0.12, 0.09);

  // Coarse mip filtering averages nearby emissive tiles smoothly as cone diameter grows
  float spread = max(r * 1.15, 0.45);
  float dLava = length(vec2(p.x + 2.5, max(p.y - 0.8, 0.0)));
  float dCrys = length(vec2(p.x - 3.5, max(p.y - 0.8, 0.0)));
  float dShrineC = length(p - vec3(0.5, 2.5, -5.5));
  vec3 mipRad = vec3(3.2, 0.88, 0.16) * exp(-dLava * dLava / (spread * spread * 1.8))
              + vec3(0.20, 2.15, 3.10) * exp(-dCrys * dCrys / (spread * spread * 1.8))
              + vec3(0.24, 1.85, 2.85) * exp(-dShrineC * dShrineC / (spread * spread * 2.2));
  mipRad *= P_EMISSIVE;

  // Smooth architectural wall occlusion at coarser mip scales
  float floorOcc = smoothstep(spread, -0.1, p.y - 0.85);
  float backOcc = smoothstep(spread, -0.1, -5.2 - p.z);
  float pilOcc = smoothstep(spread, 0.0, abs(abs(p.x) - 5.5) - 0.5) * smoothstep(5.8, 4.8, p.y);
  float coarseOcc = clamp(max(max(floorOcc, backOcc), pilOcc * 0.65), 0.0, 1.0);

  float mipBlend = clamp((r - 0.35) / 1.4, 0.0, 0.85);
  return vec4(mix(rad, mipRad * 0.55 + rad * 0.35, mipBlend), mix(occ, coarseOcc, mipBlend));
}

// Exact 3D DDA traversal of the WFC voxel grid
bool ddaWFC(vec3 ro, vec3 rd, int maxSteps, out vec3 hitPos, out vec3 hitN, out int hitMat) {
  vec3 bMin = vec3(-7.0, 0.0, -7.0);
  vec3 bMax = vec3(8.0, 8.0, 8.0);
  vec3 invD = 1.0 / (rd + vec3(1e-6));
  vec3 t0 = (bMin - ro) * invD;
  vec3 t1 = (bMax - ro) * invD;
  vec3 tMin = min(t0, t1);
  vec3 tMax = max(t0, t1);
  float tEnter = max(max(tMin.x, tMin.y), max(tMin.z, 0.0));
  float tExit = min(min(tMax.x, tMax.y), tMax.z);
  if (tEnter > tExit) return false;

  vec3 p = ro + rd * (tEnter + 0.001);
  ivec3 v = ivec3(floor(p));
  ivec3 stepDir = ivec3(sign(rd));
  vec3 deltaT = abs(1.0 / (rd + vec3(1e-6)));
  vec3 sideT = ((vec3(v) + max(vec3(stepDir), vec3(0.0))) - p) * invD;
  vec3 lastN = vec3(0.0, 1.0, 0.0);
  if (tMin.x >= tMin.y && tMin.x >= tMin.z) lastN = vec3(-float(stepDir.x), 0.0, 0.0);
  else if (tMin.y >= tMin.z) lastN = vec3(0.0, -float(stepDir.y), 0.0);
  else lastN = vec3(0.0, 0.0, -float(stepDir.z));

  for (int i = 0; i < 56; i++) {
    if (i >= maxSteps) break;
    int m = sampleWFC(v);
    if (m > 0) {
      hitMat = m;
      hitN = lastN;
      hitPos = ro + rd * max(tEnter, 0.0);
      return true;
    }
    if (sideT.x < sideT.y && sideT.x < sideT.z) {
      tEnter = sideT.x; sideT.x += deltaT.x; v.x += stepDir.x;
      lastN = vec3(-float(stepDir.x), 0.0, 0.0);
    } else if (sideT.y < sideT.z) {
      tEnter = sideT.y; sideT.y += deltaT.y; v.y += stepDir.y;
      lastN = vec3(0.0, -float(stepDir.y), 0.0);
    } else {
      tEnter = sideT.z; sideT.z += deltaT.z; v.z += stepDir.z;
      lastN = vec3(0.0, 0.0, -float(stepDir.z));
    }
    if (tEnter > tExit) break;
  }
  return false;
}

// Single diffuse voxel cone trace accumulating front-to-back radiance and occlusion
vec4 traceVoxelCone(vec3 origin, vec3 dir) {
  vec3 accumRad = vec3(0.0);
  float accumAlpha = 0.0;
  float dist = 0.55;
  for (int s = 0; s < 7; s++) {
    if (accumAlpha > 0.94) break;
    float radius = max(dist * 0.58, 0.35);
    vec4 smp = sampleWFCVolumeMip(origin + dir * dist, radius);
    float a = clamp(smp.a * 0.42, 0.0, 1.0);
    accumRad += (1.0 - accumAlpha) * smp.rgb * (0.45 + 0.55 * a);
    accumAlpha += (1.0 - accumAlpha) * a;
    dist += max(radius * 1.15, 0.65);
  }
  return vec4(accumRad, accumAlpha);
}

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 useVCT = uv.x > 0.0;
  vec2 suv = vec2(useVCT ? (uv.x - 0.25) : (uv.x + 0.25), uv.y);
  suv.x *= 1.80;

  float sway = sin(iTime * 0.48) * 1.35 * P_CAM_SWAY;
  vec3 ro = vec3(sway, 4.4, 11.2);
  vec3 target = vec3(0.0, 2.2, -2.5);
  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.62 + right * suv.x + up * suv.y);

  vec3 sunDir = normalize(vec3(0.42, 0.85, 0.32));
  vec3 col = mix(vec3(0.03, 0.04, 0.07), vec3(0.08, 0.12, 0.20), clamp(rd.y + 0.45, 0.0, 1.0));

  vec3 hPos, hN;
  int hMat;
  if (ddaWFC(ro, rd, 54, hPos, hN, hMat)) {
    if (hMat == 2) {
      float pulse = 0.88 + 0.12 * sin(iTime * 3.5 + hPos.z * 2.0);
      col = vec3(3.2, 0.92, 0.18) * pulse * P_EMISSIVE;
    } else if (hMat == 3) {
      float pulse = 0.88 + 0.12 * cos(iTime * 2.8 + hPos.z * 1.8);
      col = vec3(0.22, 2.10, 3.15) * pulse * P_EMISSIVE;
    } else {
      vec3 alb = (hMat == 4) ? vec3(0.68, 0.42, 0.32) : vec3(0.64, 0.62, 0.58);
      // Direct moon/sun key light with DDA hard shadow
      vec3 shP, shN; int shM;
      bool inSh = ddaWFC(hPos + hN * 0.06, sunDir, 22, shP, shN, shM);
      float vis = inSh ? 0.0 : 1.0;
      vec3 direct = alb * vec3(0.75, 0.78, 0.85) * max(dot(hN, sunDir), 0.0) * vis;

      if (!useVCT) {
        // Left: direct light + flat constant ambient only (no emissive GI bounce or soft cone AO)
        col = direct + alb * vec3(0.14, 0.15, 0.18);
      } else {
        // Right: 5-cone voxel cone tracing directly over the WFC voxel grid
        vec3 t1 = normalize(abs(hN.y) < 0.9 ? cross(hN, vec3(0.0, 1.0, 0.0)) : cross(hN, vec3(1.0, 0.0, 0.0)));
        vec3 t2 = cross(hN, t1);
        vec3 orig = hPos + hN * 0.18;
        vec4 c0 = traceVoxelCone(orig, hN);
        vec4 c1 = traceVoxelCone(orig, normalize(hN + t1 * 0.72));
        vec4 c2 = traceVoxelCone(orig, normalize(hN - t1 * 0.72));
        vec4 c3 = traceVoxelCone(orig, normalize(hN + t2 * 0.72));
        vec4 c4 = traceVoxelCone(orig, normalize(hN - t2 * 0.72));
        vec3 gi = (c0.rgb * 0.28 + (c1.rgb + c2.rgb + c3.rgb + c4.rgb) * 0.18) * P_GI_BOUNCE;
        float occ = (c0.a * 0.28 + (c1.a + c2.a + c3.a + c4.a) * 0.18);
        float ao = clamp(1.0 - occ * 0.78 * P_CONE_AO, 0.18, 1.0);
        col = direct + alb * (gi + vec3(0.07, 0.09, 0.13) * ao);
      }
      vec3 f = abs(fract(hPos) - 0.5);
      float seam = smoothstep(0.44, 0.495, max(f.x, max(f.y, f.z)));
      col *= (1.0 - 0.12 * seam);
    }
  }

  col = acesTone(col);
  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

Wave Function Collapse outputs voxels: one tile label per cell. Each label maps to a small pre-voxelised block (albedo, emission and opacity per face direction) authored with the tile. Voxel Cone Tracing takes voxels as an input: the blocks are stamped into its 3D texture, direct light is injected with shadow maps, the volume is mip-mapped, and cones traced from the G-buffer return diffuse and glossy radiance. Regenerating or editing part of the level only restamps the cells that changed.

How to build it

Godot or Unity with a custom compute path, or WebGPU. For every tile in the WFC set, voxelise its mesh offline at a few subvoxels per tile edge and store opacity per face direction, as in the anisotropic cone-tracing variant. After WFC solves, stamp tile blocks into a camera-centred clipmap; give dynamic actors a small separate voxelisation. Inject direct light, build mips, trace five to nine cones per pixel at half resolution and upsample. Expose a per-tile emissive channel so lava or lamp tiles automatically become GI light sources.

Field marks

  1. Tile-resolution voxels miss small details, so subvoxel stamping is needed.
  2. Large levels need clipmaps and incremental restamping.
  3. Dynamic objects still need their own voxelisation.
  4. Cone tracing remains the heavy part of the frame.

Prior art

No prior art found on 2026-11-29.

Searches run (4)
  • arXiv: all:"wave function collapse" AND all:"global illumination" → 0 results
  • GitHub repos: "wave function collapse" "global illumination" → 0 results
  • arXiv: all:"voxel cone tracing" AND all:"procedural" → 0 results
  • GitHub repos: "voxel cone tracing" procedural → 1 result