{
 "id": "flow-map-water",
 "title": "Flow-map water animation",
 "aliases": [
  "flowmap",
  "flow mapping",
  "river flow shader",
  "two-phase flow blend"
 ],
 "domain": "volumes",
 "subdomain": "water surface shading",
 "stage": "volume",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2010,
 "inputs": [
  "texture"
 ],
 "outputs": [
  "normals",
  "texture"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Animate water along authored directions by scrolling a normal map through a flow texture, using two time-shifted layers cross-faded so the reset of the distortion is hidden. Gives rivers, whirlpools and fountains cheaply.",
 "how_it_works": "A flow map is a texture whose red and green channels hold a 2D flow vector per texel, painted or simulated for a river bend, eddy or waterfall. Distorting a normal map by a flow vector that grows over time stretches the pattern without bound, so the technique resets the distortion periodically.\n\nThe lookup works with two phases. Compute `phase0 = fract(t / T)` and `phase1 = fract(t / T + 0.5)`. For each phase, sample the water normals at `uv - flow * phase * strength`. Blend the two samples with weight `abs(1 - 2 * phase0)`, so each layer is fully visible at the middle of its cycle and invisible at its reset, where distortion is largest and the jump happens.\n\nAdding a per-pixel noise offset to each phase breaks the visible pulsing; a small per-layer UV offset avoids repeating bands. Flow speed can also modulate normal-map scale and foam. Results feed refraction, reflection and specular shading of the water surface.",
 "when_to_use": "Choose it for rivers, streams, pools with currents, spillways and any surface where the flow direction is authored and cheap animation matters.\n\nPrefer [gerstner-waves](gerstner-waves) or [fft-ocean](fft-ocean) for open water where waves propagate and displace geometry. Prefer [shallow-water-equations](shallow-water-equations) or [stable-fluids](stable-fluids) when the flow must react to obstacles and player interaction, and render the simulated velocity through the same two-phase blend. Use [water-caustics-realtime](water-caustics-realtime) and [planar-reflections-oblique-clipping](planar-reflections-oblique-clipping) for the surrounding water look.",
 "cost": {
  "class": "cheap",
  "notes": "Two normal-map fetches and one flow-map fetch per pixel; no simulation."
 },
 "failure_modes": [
  "Visible pulsing at the cycle period if the two phases are not offset or noise-jittered",
  "Smearing and stretching of the pattern in regions where the flow is strong relative to the cycle length",
  "Discontinuities when the flow map has seams or its resolution is too low, since bilinear filtering of vectors cancels opposing flows",
  "Flow does not interact with objects dynamically unless the map is updated at runtime",
  "Normal-map detail that is anisotropic looks wrong when rotated by a changing flow direction",
  "Foam and shoreline masks need separate authoring, or they remain static while the water moves"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:https://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf",
   "type": "web",
   "title": "Water Flow in Portal 2",
   "authors": [
    "Alex Vlachos"
   ],
   "year": null,
   "venue": "SIGGRAPH 2010",
   "url": "https://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20251212122213/https://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf",
     "timestamp": "20251212122213"
    },
    "page_title": null,
    "host": "steamcdn-a.akamaihd.net",
    "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://steamcdn-a.akamaihd.net/apps/valve/2010/siggraph2010_vlachos_waterflow.pdf → 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": "vlachoswater"
  }
 ],
 "presets": [
  {
   "id": "flow-map-two-phase-bend",
   "title": "Two-phase flow-map water with an eddy",
   "runtime": "glsl-fragment",
   "params": {
    "cycle_seconds": 2,
    "strength": 0.35
   },
   "code": "// Flow-map water: a flow field advects a pattern; two phase-offset layers are cross-faded to hide the reset.\nconst float CYCLE = 2.0;      // seconds per advection cycle\nconst float STRENGTH = 0.35;  // how far the pattern travels per cycle\nfloat hash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat vnoise(vec2 p) {\n  vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);\n}\nfloat ripples(vec2 p) { return 0.6 * vnoise(p * 6.0) + 0.3 * vnoise(p * 13.0 + 7.0) + 0.1 * vnoise(p * 29.0); }\nvec2 flowField(vec2 p) {            // a river bend plus an eddy\n  vec2 c = p - vec2(0.62, 0.45);\n  vec2 swirl = vec2(-c.y, c.x) / (dot(c, c) * 40.0 + 0.5);\n  return normalize(vec2(1.0, 0.4 * sin(p.x * 5.0)) + swirl * 2.0);\n}\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = fragCoord / iResolution.xy;\n  vec2 f = flowField(uv);\n  float t = iTime / CYCLE;\n  float p0 = fract(t), p1 = fract(t + 0.5);\n  float w = abs(1.0 - 2.0 * p0);               // weight of layer 0 (layer 1 gets 1 - w)\n  float a = ripples(uv - f * p0 * STRENGTH + 0.0);\n  float b = ripples(uv - f * p1 * STRENGTH + 0.37);\n  float v = mix(b, a, w);\n  vec3 deep = vec3(0.02, 0.18, 0.28), shallow = vec3(0.25, 0.6, 0.62);\n  vec3 col = mix(deep, shallow, smoothstep(0.2, 0.9, v));\n  col += pow(smoothstep(0.6, 0.85, v), 3.0) * vec3(0.8, 0.9, 0.95);\n  fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);\n}\n",
   "basis": "0",
   "license_note": "written for this index; algorithm from the cited Valve talk",
   "execution_fidelity": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-29",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "flow-map-water",
     "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.5757,
      "std": 0.0883,
      "unique_colors": 56
     },
     "image": "/specimens/flow-map-two-phase-bend.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "gerstner-waves",
  "fft-ocean",
  "shallow-water-equations",
  "stable-fluids",
  "water-caustics-realtime",
  "planar-reflections-oblique-clipping"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "stable-fluids",
   "why": "A simulated velocity field can be baked or streamed as the flow map so water reacts to obstacles."
  },
  {
   "id": "water-caustics-realtime",
   "why": "Normals from the blended layers drive the caustic pattern on the river bed."
  },
  {
   "id": "planar-reflections-oblique-clipping",
   "why": "The perturbed normals offset the reflection texture lookup on the water plane."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/volumes/flow-map-water.json"
 },
 "solves": [
  "river water should flow along a bend",
  "water texture stretches and smears when scrolled",
  "want cheap flowing water without a simulation",
  "pulsing visible when looping flowing normal maps"
 ],
 "authority": "Vlachos",
 "url": "https://texelatlas.vercel.app/t/flow-map-water/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 8.5,
  "tier": "moderate",
  "p50_ms": 0.2795,
  "p95_ms": 0.4756,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 40,
  "preset_id": "flow-map-two-phase-bend",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 7.83,
   "tier": "moderate",
   "p50_ms": 0.1245,
   "p95_ms": 0.1267,
   "speedup_x": 2.24,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 6.17,
   "tier": "moderate",
   "p50_ms": 0.1778,
   "p95_ms": 0.1779,
   "speedup_x": 1.57,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}