Texel A field guide to 3D techniques

Owen-scrambled Sobol and low-discrepancy sampling × Irradiance Caching

Owen-scrambled Sobol hemisphere sampling for blotch-free irradiance caches. Replacing stratified jittered hemisphere grids in Ward-style irradiance caching with hash-based Owen-scrambled Sobol sequences cuts per-cache-point ray counts by 2-4x while eliminating correlated low-frequency GI blotches.

Open in StudioReproduced151× · 4.67 ms

Owen-scrambled Sobol and low-discrepancy samplingLighting · Interactivein: —out: radiancecompositeIrradiance CachingLighting · Offlinein: mesh, material-paramsout: irradiance-probes

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of Owen-scrambled Sobol + irradiance cache (left: blotchy random-sampled cache, right: clean Owen-Sobol cache)
Cross-proof specimen. Owen-scrambled Sobol + irradiance cache (left: blotchy random-sampled cache, right: clean Owen-Sobol cache). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing Ward-style irradiance caching driven by low-count unstratified pseudo-random hemisphere rays showing mottled GI blotches (left) against hash-based Owen-scrambled Sobol 2D low-discrepancy hemisphere sampling delivering clean, blotch-free cached irradiance at the exact same ray count (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · eliminates mottled low-frequency GI cache blotches by replacing pseudo-random hemisphere rays with Owen-scrambled Sobol low-discrepancy sampling at equal ray budget

Show GLSL proof (201 lines)
const float P_GI_GAIN = 1.25; // P Indirect GI Gain [0.4, 2.2, 0.05]
const float P_CACHE_CELL = 1.00; // P Cache Spacing [0.5, 1.8, 0.05]
const float P_CACHE_DOTS = 0.30; // P Cache Record Dots [0.0, 1.0, 0.05]
const float P_PORTAL_ORBIT = 0.65; // P Portal Animation [0.0, 1.5, 0.05]

// Bit-reversal and Laine-Karras Owen scrambling hash in pure GLSL ES 3.00 / OpenGL 3.30
uint reverseBits32(uint x) {
  x = ((x & 0x55555555u) << 1u) | ((x >> 1u) & 0x55555555u);
  x = ((x & 0x33333333u) << 2u) | ((x >> 2u) & 0x33333333u);
  x = ((x & 0x0F0F0F0Fu) << 4u) | ((x >> 4u) & 0x0F0F0F0Fu);
  x = ((x & 0x00FF00FFu) << 8u) | ((x >> 8u) & 0x00FF00FFu);
  return (x << 16u) | (x >> 16u);
}

uint laineKarrasHash(uint x, uint seed) {
  x += seed;
  x ^= x * 0x6c50b47cu;
  x ^= x * 0xb82f1e52u;
  x ^= x * 0xc7afe638u;
  x ^= x * 0x8d22f6e6u;
  return x;
}

uint owenScramble(uint x, uint seed) {
  return reverseBits32(laineKarrasHash(reverseBits32(x), seed));
}

// 2D Sobol point (dimension 0: radical inverse base 2, dimension 1: Sobol Gray-code matrix)
vec2 owenSobol2D(uint idx, uint seed) {
  uint x = reverseBits32(idx);
  uint y = 0u;
  uint v = 0x80000000u;
  uint n = idx;
  for (int b = 0; b < 8; b++) {
    if ((n & 1u) != 0u) y ^= v;
    v ^= v >> 1u;
    n >>= 1u;
  }
  uint sx = owenScramble(x, seed);
  uint sy = owenScramble(y, seed ^ 0x9e3779b9u);
  return vec2(float(sx >> 8u), float(sy >> 8u)) * (1.0 / 16777216.0);
}

// Unstratified hash PRNG for baseline comparison
vec2 prng2D(uint idx, uint seed) {
  uint h1 = laineKarrasHash(idx * 1664525u + 1013904223u, seed);
  uint h2 = laineKarrasHash(h1, seed ^ 0x27d4eb2du);
  return vec2(float(h1 >> 8u), float(h2 >> 8u)) * (1.0 / 16777216.0);
}

// Analytic gallery room radiance along bounce ray dir (warm orange portal left, cyan portal right)
vec3 roomIncident(vec3 pos, vec3 dir, float t) {
  float py = 0.25 + 0.22 * sin(t * 0.8 * P_PORTAL_ORBIT);
  vec3 warmDir = normalize(vec3(-1.4, py, -0.4) - pos);
  vec3 coolDir = normalize(vec3(1.4, 0.45 - py * 0.4, -0.5) - pos);
  float wHit = smoothstep(0.68, 0.94, dot(dir, warmDir));
  float cHit = smoothstep(0.68, 0.94, dot(dir, coolDir));
  float ceilHit = smoothstep(0.35, 0.95, dir.y);
  vec3 warmRad = vec3(3.4, 1.35, 0.42) * wHit;
  vec3 coolRad = vec3(0.45, 1.65, 2.95) * cHit;
  vec3 skyRad = vec3(0.32, 0.36, 0.46) * ceilHit;
  return warmRad + coolRad + skyRad + vec3(0.12, 0.13, 0.15);
}

// Evaluate one irradiance cache record at spatial cell center with 16 hemisphere rays
vec3 evalCacheRecord(vec3 recPos, vec3 N, uint recSeed, float t, bool useOwenSobol) {
  vec3 upRef = abs(N.y) < 0.9 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0);
  vec3 T = normalize(cross(upRef, N));
  vec3 B = cross(N, T);
  vec3 accum = vec3(0.0);
  for (int i = 0; i < 16; i++) {
    vec2 u = useOwenSobol ? owenSobol2D(uint(i), recSeed) : prng2D(uint(i), recSeed);
    // Malley cosine-weighted hemisphere projection
    float r = sqrt(max(u.x, 1e-5));
    float phi = 6.2831853 * u.y;
    vec3 localD = vec3(r * cos(phi), r * sin(phi), sqrt(max(1.0 - u.x, 1e-5)));
    vec3 worldD = normalize(T * localD.x + B * localD.y + N * localD.z);
    // Column shadow occlusion inside the room
    vec3 toCol = vec3(0.0, recPos.y, -0.55) - recPos;
    float proj = dot(toCol, worldD);
    float occ = 1.0;
    if (proj > 0.05) {
      vec2 perp = (recPos.xz + worldD.xz * proj) - vec2(0.0, -0.55);
      if (length(perp) < 0.30) occ = 0.15;
    }
    accum += roomIncident(recPos, worldD, t) * occ;
  }
  return (accum / 16.0) * P_GI_GAIN;
}

vec2 mapGallery(vec3 p) {
  float dFloor = p.y + 0.95;
  float dCeil = 1.25 - p.y;
  float dLeft = p.x + 1.65;
  float dRight = 1.65 - p.x;
  float dBack = p.z + 1.95;
  float dCol = length(p.xz - vec2(0.0, -0.55)) - 0.28;
  float d = dFloor; float mat = 1.0;
  if (dCeil < d) { d = dCeil; mat = 2.0; }
  if (dLeft < d) { d = dLeft; mat = 3.0; }
  if (dRight < d) { d = dRight; mat = 4.0; }
  if (dBack < d) { d = dBack; mat = 5.0; }
  if (dCol < d) { d = dCol; mat = 6.0; }
  return vec2(d, mat);
}

vec3 calcNormal(vec3 p) {
  vec2 e = vec2(0.003, -0.003);
  return normalize(
    e.xyy * mapGallery(p + e.xyy).x +
    e.yyx * mapGallery(p + e.yyx).x +
    e.yxy * mapGallery(p + e.yxy).x +
    e.xxx * mapGallery(p + e.xxx).x
  );
}

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 res = max(iResolution.xy, vec2(1.0));
  vec2 uvN = fragCoord / res;
  float splitX = iMouse.z > 0.0 ? clamp(iMouse.x / res.x, 0.05, 0.95) : 0.5;
  bool useOwenSobol = uvN.x > splitX;

  vec2 p = (fragCoord - 0.5 * res) / res.y;
  float t = iTime;
  vec3 ro = vec3(sin(t * 0.24) * 0.18, 0.08, 1.85);
  vec3 rd = normalize(vec3(p.x * 1.15, p.y - 0.02, -1.35));

  float d = 0.05;
  float mat = -1.0;
  for (int i = 0; i < 64; i++) {
    vec2 h = mapGallery(ro + rd * d);
    if (h.x < 0.002) { mat = h.y; break; }
    d += h.x;
    if (d > 7.5) break;
  }

  vec3 col = vec3(0.04);
  if (mat > 0.0) {
    vec3 wp = ro + rd * d;
    vec3 N = calcNormal(wp);
    vec3 alb = mat > 5.5 ? vec3(0.76, 0.74, 0.70) : vec3(0.70, 0.69, 0.67);

    // Emissive warm & cool light portals on left/right walls
    float py = 0.25 + 0.22 * sin(t * 0.8 * P_PORTAL_ORBIT);
    bool onWarm = (mat > 2.5 && mat < 3.5) && abs(wp.y - py) < 0.34 && abs(wp.z + 0.4) < 0.36;
    bool onCool = (mat > 3.5 && mat < 4.5) && abs(wp.y - (0.45 - py * 0.4)) < 0.34 && abs(wp.z + 0.5) < 0.36;
    if (onWarm) {
      col = vec3(3.4, 1.45, 0.48);
    } else if (onCool) {
      col = vec3(0.48, 1.75, 3.10);
    } else {
      // Ward spatial irradiance cache lookup & smooth interpolation over 2x2 nearest cache records
      float cellSize = 0.36 * P_CACHE_CELL;
      vec2 planeUV = abs(N.y) > 0.5 ? wp.xz : (abs(N.x) > 0.5 ? wp.zy : wp.xy);
      vec2 gCoord = planeUV / cellSize;
      vec2 baseCell = floor(gCoord - 0.5);
      vec2 fracW = gCoord - (baseCell + 0.5);

      vec3 irrSum = vec3(0.0);
      float wSum = 1e-4;
      float minRecD = 9.0;
      for (int iy = 0; iy <= 1; iy++) {
        for (int ix = 0; ix <= 1; ix++) {
          vec2 cId = baseCell + vec2(float(ix), float(iy));
          vec2 recCenter = (cId + 0.5) * cellSize;
          vec2 deltaUV = planeUV - recCenter;
          float rDist = length(deltaUV) / cellSize;
          minRecD = min(minRecD, rDist);
          // Ward-like smooth distance weight across neighboring cache records
          float w = max(0.0, 1.0 - rDist * 0.88);
          w = w * w;
          vec3 recWP = wp;
          if (abs(N.y) > 0.5) recWP.xz = recCenter;
          else if (abs(N.x) > 0.5) recWP.zy = recCenter;
          else recWP.xy = recCenter;
          uint seed = uint(abs(cId.x * 73.0 + cId.y * 151.0 + mat * 313.0)) + 17u;
          vec3 recIrr = evalCacheRecord(recWP + N * 0.015, N, seed, t, useOwenSobol);
          irrSum += recIrr * w;
          wSum += w;
        }
      }
      vec3 irr = irrSum / wSum;
      col = alb * irr;

      // Optional irradiance cache record marker dots
      if (P_CACHE_DOTS > 0.01) {
        float dotMask = smoothstep(0.11, 0.05, minRecD);
        vec3 dotCol = useOwenSobol ? vec3(0.28, 0.92, 0.78) : vec3(0.95, 0.42, 0.28);
        col = mix(col, dotCol, dotMask * P_CACHE_DOTS * 0.85);
      }
    }
  }

  col = acesTone(col * 1.06);
  if (abs(fragCoord.x - splitX * res.x) < 1.0) 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

Owen-scrambled Sobol and low-discrepancy sampling produces well-distributed, decorrelated 2D low-discrepancy sample coordinates for every cache-point seed using bit-reversed Laine-Karras / Burley Owen hashing. The hop to Irradiance Caching is composite: map each scrambled (u, v) Sobol point onto cosine-weighted hemisphere directions at a newly inserted cache record, trace rays against the scene, accumulate both irradiance and Ward translational/rotational gradients, and store the finished record in the spatial octree or hash cache for smooth per-pixel interpolation.

How to build it

Precompute Sobol direction numbers for 2D (or 4D for two-bounce paths) in a small constant table. When an irradiance cache miss occurs at surface point P with normal N, seed a per-record Owen scramble hash from a quantized spatial hash of P so neighboring cache records never share identical correlation patterns. Map the first K (e.g., 64-128) Owen-scrambled Sobol samples via concentric disk / Malley cosine hemisphere projection, accumulate radiance and harmonic mean hit distance R0 (which defines the valid interpolation radius), and estimate rotational/translational irradiance gradients directly from the directional ray hits. Interpolate nearby valid cache records across pixels using Ward's error-bounded weighting function.

Field marks

  1. Using the exact same scramble seed across adjacent cache records introduces coherent structured banding across smooth walls.
  2. Ward's analytic translational and rotational gradient formulas originally assume regular (theta, phi) cell stratification, so unstratified Sobol samples require either Hessian/MLS regression or cell-binned gradient accumulation.
  3. Small bright emissive sources still cause outlier spikes in sparse caches unless combined with next-event estimation or firefly clamping.
  4. Cache record placement depends on ray hit distances, so subtle sample noise can shift record density from frame to frame in animated scenes.

Prior art

No prior art found on 2026-12-01.

Searches run (2)
  • arXiv: all:"Owen" AND all:"Sobol" AND all:"irradiance caching"
  • GitHub repos: "sobol" "irradiance caching"