{
 "id": "owen-scrambled-sobol-sampling",
 "title": "Owen-scrambled Sobol and low-discrepancy sampling",
 "aliases": [
  "Owen scrambling",
  "scrambled Sobol sequence",
  "QMC sampling",
  "hash-based Owen scrambling"
 ],
 "domain": "gi",
 "subdomain": "Monte Carlo sampling",
 "stage": "lighting",
 "realtime": "interactive",
 "platforms": [
  "cuda",
  "desktop-gpu",
  "cpu",
  "webgpu",
  "blender",
  "python"
 ],
 "year_introduced": 2020,
 "inputs": [],
 "outputs": [
  "radiance"
 ],
 "style": "photoreal",
 "dynamic": "both",
 "summary": "Generate sample points from the Sobol sequence and randomise them per pixel with a cheap hash-based Owen scramble, so each pixel gets well-stratified, decorrelated samples at any sample count with no stored tables.",
 "how_it_works": "Low-discrepancy sequences such as Sobol fill the unit hypercube more evenly than random numbers, which cuts error in smooth integrands. Using the same sequence at every pixel produces visible structured artifacts, so each pixel needs its own randomisation that keeps the stratification.\n\nOwen scrambling does this by flipping bits of the binary digits in a nested way: whether a bit is flipped depends on all higher bits. That keeps the point set a valid net, so stratification survives. A hash-based version computes the nested flips with a few integer operations: reverse the bits, apply a hash-like mixing step that only lets higher bits influence lower ones, reverse again. No random permutation tables are needed.\n\nA renderer draws the Sobol index from the sample number and the dimension, applies a per-pixel and per-dimension seed to the scramble, and converts the 32-bit result to a float. Dimensions can be padded so that decorrelated dimensions do not alias. Because the construction is a pure function of (index, seed), it runs on GPUs and supports progressive rendering without state.",
 "when_to_use": "Choose it as the default sampler for a path tracer, or for any renderer integrating smooth functions such as direct lighting and ambient occlusion with a few dozen samples per pixel.\n\nPrefer [blue-noise-screen-space-sampler](blue-noise-screen-space-sampler) at one to eight samples per pixel for real-time work, where distributing error as blue noise matters more than convergence rate. Prefer plain pseudo-random or PCG hashes when the integrand is discontinuous and QMC gives little benefit. Prefer [poisson-disk-sampling](poisson-disk-sampling) for placement of objects rather than integration samples. Used with [next-event-estimation](next-event-estimation) it improves light and BSDF sampling.",
 "cost": {
  "class": "cheap",
  "notes": "A few integer operations per generated dimension; no memory beyond Sobol direction numbers."
 },
 "failure_modes": [
  "Correlated dimensions: reusing the same scramble seed across dimensions gives visible patterns",
  "Ordering of dimensions matters; assigning low dimensions to low-impact decisions wastes the best stratification",
  "Convergence gain vanishes for high-dimensional paths because stratification degrades past a few dimensions",
  "Sample counts that are not powers of two lose the net property and some stratification",
  "Float conversion of 32-bit integers loses the lowest bits and can create bias if not done carefully",
  "Progressive rendering must use consistent indexes across frames or scrambles restart and reintroduce noise"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://jcgt.org/published/0009/04/01",
   "type": "web",
   "title": "Practical Hash-based Owen Scrambling",
   "authors": [
    "Brent Burley"
   ],
   "year": null,
   "venue": "JCGT 2020",
   "url": "https://jcgt.org/published/0009/04/01",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261103122324/https://jcgt.org/published/0009/04/01/",
     "timestamp": "20261103122324"
    },
    "page_title": null,
    "host": "jcgt.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://jcgt.org/published/0009/04/01 → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "burleypractical"
  },
  {
   "role": "tutorial",
   "key": "url:https://pbr-book.org/4ed/Sampling_and_Reconstruction/Sobol_Samplers",
   "type": "tutorial",
   "title": "Sobol Samplers",
   "authors": [
    "Matt Pharr",
    "Wenzel Jakob",
    "Greg Humphreys"
   ],
   "year": null,
   "venue": "Physically Based Rendering 4th ed.",
   "url": "https://pbr-book.org/4ed/Sampling_and_Reconstruction/Sobol_Samplers",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20260923045044/https://pbr-book.org/4ed/Sampling_and_Reconstruction/Sobol_Samplers",
     "timestamp": "20260923045044"
    },
    "page_title": "Sobol&rsquo; Samplers",
    "host": "pbr-book.org",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/4ed/Sampling_and_Reconstruction/Sobol_Samplers → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://pbr-book.org/4ed/Sampling_and_Reconstruction/Sobol_Samplers → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.8,
   "__bib": "pharrsobol"
  },
  {
   "role": "implementation",
   "key": "gh:mmp/pbrt-v4",
   "type": "code",
   "title": "mmp/pbrt-v4",
   "description": "Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the \"Physically Based Rendering: From Theory to Implementation\" book.",
   "authors": [
    "mmp"
   ],
   "year": 2017,
   "venue": "GitHub",
   "url": "https://github.com/mmp/pbrt-v4",
   "ids": {
    "repo": "mmp/pbrt-v4"
   },
   "license": "Apache-2.0",
   "extra": {
    "stars": 3761,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-15T22:47:49Z",
    "language": "C++",
    "homepage": "https://pbrt.org",
    "license_name": "Apache License 2.0"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/mmp/pbrt-v4",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "mmp2017pbrt"
  }
 ],
 "presets": [
  {
   "id": "owen-scrambled-sobol-sampling-live",
   "title": "Owen-Scrambled Sobol QMC — clumpy white-noise RNG (left) vs stratified Owen-Sobol sequence (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_SAMPLES": 32,
    "P_SCRAMBLE_SEED": 3,
    "P_PLOT_RATIO": 0.44,
    "P_SPLIT": 0.5
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_SAMPLES = 32.0; // P Sample Count [8.0, 64.0, 4.0]\nconst float P_SCRAMBLE_SEED = 3.0; // P Owen Scramble [1.0, 12.0, 1.0]\nconst float P_PLOT_RATIO = 0.44; // P Scatter Height [0.25, 0.65, 0.02]\nconst float P_SPLIT = 0.50; // P White / Sobol Split [0.0, 1.0, 0.02]\n\n// 32-bit bit reversal + Laine-Karras hash for authentic Owen scrambling in WebGL2 & GL 3.30\nuint bitRev32(uint x) {\n  x = ((x & 0x55555555u) << 1u) | ((x & 0xAAAAAAAAu) >> 1u);\n  x = ((x & 0x33333333u) << 2u) | ((x & 0xCCCCCCCCu) >> 2u);\n  x = ((x & 0x0F0F0F0Fu) << 4u) | ((x & 0xF0F0F0F0u) >> 4u);\n  x = ((x & 0x00FF00FFu) << 8u) | ((x & 0xFF00FF00u) >> 8u);\n  return (x << 16u) | (x >> 16u);\n}\n\nuint lkHash(uint x, uint seed) {\n  x += seed;\n  x ^= x * 0x6c50b47cu;\n  x ^= x * 0xb82f1e52u;\n  x ^= x * 0xc7afe638u;\n  x ^= x * 0x8d22f6e6u;\n  return x;\n}\n\nuint owenScramble(uint x, uint seed) {\n  return bitRev32(lkHash(bitRev32(x), seed));\n}\n\n// 2D Sobol sequence (dim 0: van der Corput, dim 1: Sobol direction numbers via bit ops)\nvec2 owenSobol2D(uint idx, uint seed) {\n  uint x = bitRev32(idx);\n  uint y = 0u;\n  uint n = idx;\n  uint dir = 0x80000000u;\n  for (int b = 0; b < 16; b++) {\n    if ((n & 1u) != 0u) y ^= dir;\n    n >>= 1u;\n    dir ^= (dir >> 1u);\n  }\n  uint sx = owenScramble(x, seed * 0x9e3779b9u + 0x243f6a88u);\n  uint sy = owenScramble(y, seed * 0x85ebca6bu + 0xb7e15162u);\n  return vec2(float(sx >> 8u), float(sy >> 8u)) * (1.0 / 16777216.0);\n}\n\nvec2 whiteNoise2D(uint idx, uint seed) {\n  uint h1 = lkHash(idx * 374761393u + seed * 668265263u, 0x1b873593u);\n  uint h2 = lkHash(idx * 1274126177u + seed * 2246822519u, 0x85ebca77u);\n  return vec2(float(h1 >> 8u), float(h2 >> 8u)) * (1.0 / 16777216.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 uv01 = fragCoord / max(iResolution.xy, vec2(1.0));\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  float plotH = clamp(P_PLOT_RATIO, 0.22, 0.68);\n  int nSamp = int(clamp(floor(P_SAMPLES + 0.5), 8.0, 64.0));\n  uint baseSeed = uint(clamp(floor(P_SCRAMBLE_SEED + 0.5), 1.0, 20.0)) + uint(floor(iTime * 0.6));\n  bool isSobol = uv01.x >= split;\n\n  vec3 col = vec3(0.03, 0.045, 0.072);\n\n  if (uv01.y > plotH) {\n    // Top viewport: real-time Monte Carlo soft-shadow integration on a lit sphere & floor\n    vec2 pUV = vec2((uv01.x - 0.5) * (iResolution.x / max(iResolution.y, 1.0)), (uv01.y - (plotH + 1.0) * 0.5) / max(1.0 - plotH, 0.15) * 0.62);\n    vec3 ro = vec3(0.0, 0.42, 2.35);\n    vec3 rd = normalize(vec3(pUV, -1.65));\n\n    // Analytic sphere (center (0, 0.12, 0), R = 0.44) + floor plane (y = -0.32)\n    vec3 sphC = vec3(0.0, 0.12, 0.0);\n    float sphR = 0.44;\n    vec3 oc = ro - sphC;\n    float b = dot(oc, rd);\n    float c = dot(oc, oc) - sphR * sphR;\n    float disc = b * b - c;\n    float tSph = (disc > 0.0) ? (-b - sqrt(disc)) : 1e5;\n    float tFlr = (rd.y < -0.001) ? ((-0.32 - ro.y) / rd.y) : 1e5;\n    float tHit = min(tSph, tFlr);\n\n    col = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.19, 0.28), smoothstep(-0.2, 0.45, pUV.y));\n\n    if (tHit < 12.0) {\n      vec3 p = ro + rd * tHit;\n      bool hitSph = (tSph < tFlr);\n      vec3 n = hitSph ? normalize(p - sphC) : vec3(0.0, 1.0, 0.0);\n      vec3 alb = hitSph ? vec3(0.84, 0.78, 0.70) : mix(vec3(0.24, 0.28, 0.36), vec3(0.38, 0.42, 0.50), mod(floor(p.x * 2.5) + floor(p.z * 2.5), 2.0));\n\n      // Per-pixel Owen seed so noise decorrelates cleanly into blue-like screen-space error\n      uvec2 pix = uvec2(fragCoord);\n      uint pixSeed = lkHash(pix.x + pix.y * 4099u, baseSeed);\n\n      // Integrate 16-sample disk area light shadow using White Noise (left) vs Owen-Sobol (right)\n      vec3 lCenter = vec3(0.75 * cos(iTime * 0.45), 1.65, 0.65);\n      float lRad = 0.58;\n      float litSum = 0.0;\n      int mcN = min(nSamp, 16);\n      for (int i = 0; i < 16; i++) {\n        if (i >= mcN) break;\n        vec2 u = isSobol ? owenSobol2D(uint(i), pixSeed) : whiteNoise2D(uint(i), pixSeed);\n        float rD = sqrt(max(u.x, 0.0)) * lRad;\n        float phi = u.y * 6.2831853;\n        vec3 lPt = lCenter + vec3(cos(phi) * rD, 0.0, sin(phi) * rD);\n        vec3 lDir = normalize(lPt - p);\n        float ndl = max(dot(n, lDir), 0.0);\n        // Check analytic shadow ray against sphere\n        float vis = 1.0;\n        if (!hitSph) {\n          vec3 sOc = p + n * 0.002 - sphC;\n          float sb = dot(sOc, lDir);\n          float sc = dot(sOc, sOc) - sphR * sphR;\n          if (sb < 0.0 && (sb * sb - sc) > 0.0) vis = 0.0;\n        }\n        litSum += ndl * vis;\n      }\n      float direct = litSum / float(mcN);\n      col = alb * (0.18 + 1.35 * direct);\n    }\n  } else {\n    // Bottom panel: 2D unit-square point distribution comparison (8x8 strata grid)\n    float margin = 0.04;\n    float panelX = isSobol ? ((uv01.x - split) / max(1.0 - split, 0.1)) : (uv01.x / max(split, 0.1));\n    float panelY = uv01.y / max(plotH, 0.1);\n    vec2 boxUV = (vec2(panelX, panelY) - 0.5) * vec2(1.45, 1.20) + 0.5;\n\n    col = vec3(0.025, 0.036, 0.058);\n    if (boxUV.x >= 0.0 && boxUV.x <= 1.0 && boxUV.y >= 0.0 && boxUV.y <= 1.0) {\n      col = vec3(0.042, 0.060, 0.095);\n      // 4x4 elementary strata grid showing Owen-Sobol hits every stratum cleanly\n      vec2 g = abs(fract(boxUV * 4.0 - 0.5) - 0.5);\n      col += vec3(0.05, 0.08, 0.14) * smoothstep(0.03, 0.008, min(g.x, g.y));\n\n      float minD = 1e5;\n      float secondD = 1e5;\n      for (int i = 0; i < 64; i++) {\n        if (i >= nSamp) break;\n        vec2 pt = isSobol ? owenSobol2D(uint(i), baseSeed) : whiteNoise2D(uint(i), baseSeed);\n        float d = length(boxUV - pt);\n        if (d < minD) { secondD = minD; minD = d; }\n        else if (d < secondD) { secondD = d; }\n      }\n      // Voronoi distance tint highlights empty voids & clumping in white noise vs uniform Sobol\n      float voidWarn = smoothstep(0.11, 0.24, minD);\n      if (!isSobol) col = mix(col, vec3(0.45, 0.12, 0.10), voidWarn * 0.55);\n      else col = mix(col, vec3(0.06, 0.24, 0.30), (1.0 - voidWarn) * 0.35);\n\n      float dotCore = smoothstep(0.026, 0.012, minD);\n      vec3 dotCol = isSobol ? vec3(0.18, 0.94, 0.96) : vec3(1.0, 0.62, 0.24);\n      col = mix(col, dotCol, dotCore);\n      // Frame border\n      float bdr = min(min(boxUV.x, 1.0 - boxUV.x), min(boxUV.y, 1.0 - boxUV.y));\n      col = mix(col, vec3(0.45, 0.62, 0.82), smoothstep(0.012, 0.003, bdr));\n    }\n  }\n\n  // Horizontal panel divider & vertical split line\n  col = mix(col, vec3(0.42, 0.56, 0.74), smoothstep(0.005, 0.001, abs(uv01.y - plotH)));\n  col = mix(col, vec3(0.95, 0.97, 1.0), smoothstep(0.0035, 0.0008, abs(uv01.x - split)));\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "owen-scrambled-sobol-sampling",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:32.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.4646,
      "std": 0.2131,
      "min": 0.1886,
      "max": 0.9216
     },
     "image": "/specimens/owen-scrambled-sobol-sampling-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "blue-noise-screen-space-sampler",
  "next-event-estimation",
  "path-tracing",
  "poisson-disk-sampling",
  "blue-noise-dithering"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "next-event-estimation",
   "why": "The sampler supplies the 2D points that select a light and a point on it at every path vertex."
  },
  {
   "id": "blue-noise-screen-space-sampler",
   "why": "An Owen-scrambled Sobol point set can be re-ranked per pixel to land error in blue noise, trading convergence for screen-space quality."
  },
  {
   "id": "multiple-importance-sampling",
   "why": "Both strategies in an MIS estimator draw their points from the same scrambled sequence dimensions."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/owen-scrambled-sobol-sampling.json"
 },
 "solves": [
  "want faster convergence with few samples per pixel",
  "sampling pattern shows structured artifacts across pixels",
  "need a random sampler that works well on gpu without tables",
  "noise in path tracer is clumpy at low sample counts"
 ],
 "authority": "Burley",
 "url": "https://texelatlas.vercel.app/t/owen-scrambled-sobol-sampling/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 22.89,
  "tier": "heavy",
  "p50_ms": 0.7096,
  "p95_ms": 0.7297,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "owen-scrambled-sobol-sampling-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 20.65,
   "tier": "heavy",
   "p50_ms": 0.3284,
   "p95_ms": 0.3339,
   "speedup_x": 2.16,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 14.7,
   "tier": "moderate",
   "p50_ms": 0.4234,
   "p95_ms": 0.434,
   "speedup_x": 1.68,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}