{
 "id": "domain-warping",
 "title": "Domain Warping",
 "aliases": [
  "noise warping",
  "warped fBm",
  "flow-distorted noise"
 ],
 "domain": "procgen",
 "subdomain": "noise composition",
 "stage": "procedural",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "cpu",
  "blender",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2002,
 "inputs": [],
 "outputs": [
  "texture",
  "heightfield",
  "volume-density"
 ],
 "style": "both",
 "dynamic": "both",
 "summary": "Feed the output of one noise function back into the coordinates of another, f(p + w(p)), so the pattern is bent into swirls, folds and marble-like flows that plain fBm cannot make.",
 "how_it_works": "Instead of evaluating a field f at p, you first displace p by a vector field w, built from independent noise samples (typically two offset fBm calls for x and y). Nesting the idea, f(p + a*g(p + b*h(p))) gives progressively more organic structure; each level multiplies cost by the complexity of the inner evaluation. The displacement amplitude controls how far features travel, and animating one of the offset constants or adding time to the inner noise yields convincing liquid motion. Intermediate values (the warp vectors, the magnitude of the displacement) are free by-products that can be used to colour the pattern, so the result is often both a height and a palette index. The technique is general: any coordinate-based function (noise, Voronoi, SDF) can be warped.",
 "when_to_use": "Choose it when you need organic swirls, marble, smoke, lava, strata, or want to break the regularity of `fractal-brownian-motion` terrain cheaply (for example to fake flow-aligned ridges). Prefer `hydraulic-erosion-stava` or `stream-power-erosion` for physically plausible drainage, and `reaction-diffusion-textures` for self-organising stripes and spots.",
 "cost": {
  "class": "cheap",
  "notes": "Multiplicative in nesting depth: two levels of warp with 5 fBm calls each is about 15 noise stacks per pixel."
 },
 "failure_modes": [
  "Large warp amplitude folds the domain over itself, causing discontinuous seams or smeared detail",
  "Differentiation is hard: finite-difference normals through nested warps are noisy and expensive",
  "Each nesting level multiplies the cost, so mobile or per-vertex use needs a baked texture",
  "Using the same noise for warp and base creates visible diagonal correlation instead of independent swirls"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://iquilezles.org/articles/warp",
   "type": "web",
   "title": "Domain Warping",
   "authors": [
    "Inigo Quilez"
   ],
   "year": null,
   "venue": "iquilezles.org",
   "url": "https://iquilezles.org/articles/warp",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261115193016/https://iquilezles.org/articles/warp/",
     "timestamp": "20261115193016"
    },
    "page_title": "Inigo Quilez :: computer graphics, maths, shaders, fractals, demoscene",
    "host": "iquilezles.org",
    "title_confirmed_by_page": false,
    "title_unconfirmed": true
   },
   "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://iquilezles.org/articles/warp → 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": "http",
     "endpoint": "GET https://iquilezles.org/articles/warp → 200",
     "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,
   "__bib": "quilezdomain"
  },
  {
   "role": "tutorial",
   "key": "url:https://thebookofshaders.com/13",
   "type": "tutorial",
   "title": "The Book of Shaders: Fractal Brownian Motion",
   "authors": [
    "Patricio Gonzalez Vivo"
   ],
   "year": null,
   "venue": "thebookofshaders.com",
   "url": "https://thebookofshaders.com/13",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261114134911/https://thebookofshaders.com/13/",
     "timestamp": "20261114134911"
    },
    "page_title": "The Book of Shaders",
    "host": "thebookofshaders.com",
    "title_confirmed_by_page": true,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "http",
     "endpoint": "GET https://thebookofshaders.com/13 → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://thebookofshaders.com/13 → 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": "http",
     "endpoint": "GET https://thebookofshaders.com/13 → 200",
     "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.95,
   "__bib": "vivobookb"
  },
  {
   "role": "implementation",
   "key": "gh:gokayfem/glsl-studies",
   "ids": {
    "repo": "gokayfem/glsl-studies"
   },
   "type": "code",
   "title": "gokayfem/glsl-studies",
   "authors": [
    "Gökay Aydoğan"
   ],
   "year": 2026,
   "venue": "GitHub",
   "url": "https://github.com/gokayfem/glsl-studies",
   "license": "MIT",
   "description": "454 procedural graphics studies in GLSL ES 3.00 for WebGL2, from woven cloth and animal fur to glacial terrain and atmospheric optics. Each study includes shader source and a rendered preview.",
   "extra": {
    "stars": 924,
    "stars_checked": "2026-11-30",
    "language": "GLSL",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-30T13:13:54Z",
    "homepage": null,
    "license_name": "MIT License"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/gokayfem/glsl-studies",
     "checked_at": "2026-11-30T21:49:39.376Z"
    }
   },
   "status": "verified",
   "title_sim": null,
   "checked_at": "2026-11-30T21:49:39.376Z",
   "__bib": "aydoan2026gokayfem"
  }
 ],
 "presets": [
  {
   "id": "domain-warp-fbm",
   "title": "Two-level domain-warped fBm",
   "runtime": "glsl-fragment",
   "params": {
    "warp_strength": 4,
    "octaves": 5
   },
   "basis": "original",
   "license_note": "written for this index. Technique described by Inigo Quilez; code is original.",
   "code": "// GLSL ES 3.0, Shadertoy-style. f(p + 4*q + 4*r) with animated warp fields.\nconst int   OCTAVES = 5;\nconst float WARP = 4.0;\n\nfloat hash21(vec2 p){\n  p = fract(p * vec2(123.34, 456.21));\n  p += dot(p, p + 45.32);\n  return fract(p.x * p.y);\n}\nfloat vnoise(vec2 p){\n  vec2 i = floor(p), f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash21(i), hash21(i + vec2(1.0, 0.0)), u.x),\n             mix(hash21(i + vec2(0.0, 1.0)), hash21(i + vec2(1.0, 1.0)), u.x), u.y);\n}\nfloat fbm(vec2 p){\n  float s = 0.0, a = 0.5;\n  for (int i = 0; i < OCTAVES; i++) {\n    s += a * vnoise(p);\n    p = mat2(1.6, 1.2, -1.2, 1.6) * p;\n    a *= 0.5;\n  }\n  return s;\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord){\n  vec2 p = (fragCoord - 0.5 * iResolution.xy) / iResolution.y * 3.0;\n  float t = iTime * 0.15;\n  vec2 q = vec2(fbm(p + vec2(0.0, 0.0)), fbm(p + vec2(5.2, 1.3)));\n  vec2 r = vec2(fbm(p + WARP * q + vec2(1.7, 9.2) + t),\n                fbm(p + WARP * q + vec2(8.3, 2.8) - t));\n  float f = fbm(p + WARP * r);\n  vec3 col = mix(vec3(0.10, 0.12, 0.30), vec3(0.85, 0.35, 0.15), smoothstep(0.2, 0.8, f));\n  col = mix(col, vec3(0.95, 0.90, 0.75), clamp(length(r) * 0.8, 0.0, 1.0) * f);\n  col = mix(col, vec3(0.02, 0.05, 0.12), clamp(q.x * q.x * 2.0, 0.0, 1.0) * 0.5);\n  fragColor = vec4(col * (0.3 + 1.1 * f), 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "domain-warping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-29T15:51:50.471Z",
     "renderer": "Chromium 145.0.7632.6 headless, WebGL2 via ANGLE/SwiftShader, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.276,
      "std": 0.1347,
      "unique_colors": 168
     },
     "image": "/specimens/domain-warp-fbm.webp",
     "reason": null
    }
   }
  },
  {
   "id": "domain-warping-wgsl",
   "title": "Multi-octave FBM domain warping (WGSL)",
   "runtime": "webgpu-wgsl",
   "basis": "original",
   "license_note": "written for this index",
   "params": {
    "WARP": 3.2,
    "OCTAVES": 5
   },
   "code": "// WebGPU WGSL fragment specimen: iterated f(p + WARP * q + WARP * r) domain warping\nconst WARP: f32 = 3.2000; // P\nconst OCTAVES: i32 = 5; // P\n\nfn hash21(p_in: vec2f) -> f32 {\n  var p = fract(p_in * vec2f(123.34, 456.21));\n  p = p + dot(p, p + 45.32);\n  return fract(p.x * p.y);\n}\n\nfn vnoise(p: vec2f) -> f32 {\n  let i = floor(p);\n  let f = fract(p);\n  let u = f * f * (3.0 - 2.0 * f);\n  let a = hash21(i);\n  let b = hash21(i + vec2f(1.0, 0.0));\n  let c = hash21(i + vec2f(0.0, 1.0));\n  let d = hash21(i + vec2f(1.0, 1.0));\n  return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\nfn fbm(p_in: vec2f) -> f32 {\n  var p = p_in;\n  var acc: f32 = 0.0;\n  var amp: f32 = 0.5;\n  let rot = mat2x2f(vec2f(0.8, 0.6), vec2f(-0.6, 0.8));\n  for (var i: i32 = 0; i < OCTAVES; i = i + 1) {\n    acc = acc + amp * vnoise(p);\n    p = rot * p * 2.02;\n    amp = amp * 0.5;\n  }\n  return acc;\n}\n\n@fragment\nfn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {\n  let uv = (pos.xy / u.resolution.y) * 2.6;\n  let t = u.time * 0.14;\n  let q = vec2f(fbm(uv + vec2f(0.0, t)), fbm(uv + vec2f(5.2, 1.3 - t)));\n  let r = vec2f(fbm(uv + WARP * q + vec2f(1.7, 9.2)), fbm(uv + WARP * q + vec2f(8.3, 2.8)));\n  let f = fbm(uv + WARP * r);\n  var col = mix(vec3f(0.09, 0.18, 0.24), vec3f(0.68, 0.48, 0.30), clamp(f * 1.4, 0.0, 1.0));\n  col = mix(col, vec3f(0.94, 0.92, 0.86), smoothstep(0.55, 0.92, length(q) * 0.75 + f * 0.4));\n  return vec4f(col, 1.0);\n}",
   "execution_fidelity": "faithful-pass",
   "proof": {
    "kind": "wgsl",
    "label": "WebGPU WGSL runtime",
    "ok": true,
    "proof": null
   }
  }
 ],
 "related": [
  "fractal-brownian-motion",
  "perlin-noise",
  "reaction-diffusion-textures"
 ],
 "extends": [
  "fractal-brownian-motion"
 ],
 "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/procgen/domain-warping.json"
 },
 "solves": [
  "noise looks too uniform and blobby",
  "want swirling marble or smoke patterns",
  "fractal terrain lacks flowing or folded structure",
  "need lava or strata looking organic swirls cheaply"
 ],
 "authority": "Quilez",
 "url": "https://texelatlas.vercel.app/t/domain-warping/",
 "execution_fidelity": "faithful-pass",
 "fidelity_label": "Faithful Pass",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 34.16,
  "tier": "heavy",
  "p50_ms": 1.1237,
  "p95_ms": 1.151,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "domain-warp-fbm",
  "execution_fidelity": "faithful-pass",
  "fidelity_label": "Faithful Pass",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 29.82,
   "tier": "heavy",
   "p50_ms": 0.4741,
   "p95_ms": 0.4876,
   "speedup_x": 2.37,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 23.94,
   "tier": "heavy",
   "p50_ms": 0.6895,
   "p95_ms": 0.6897,
   "speedup_x": 1.63,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}