Flow-map water animation
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.
Also known as flowmap, flow mapping, river flow shader, two-phase flow blend
In the family Atmosphere, water & volumes, water surface shading
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | Official add-on | import { Water } from 'three/addons/objects/Water2.js' (flowMap option) docs |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in flow-map water shader; requires custom ShaderMaterial. |
| Unity | Built in | HDRP Water System > Current Map / water decals docs HDRP water currents. |
| Unreal 5.7 | Built in | Material Functions > Misc > FlowMap material functions for animated UV water flow docs |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
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.
The 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.
Adding 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 choose it
Reach for it when
- 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
Choose it for rivers, streams, pools with currents, spillways and any surface where the flow direction is authored and cheap animation matters.
Prefer Gerstner (Trochoidal) Waves or FFT Ocean (Tessendorf) for open water where waves propagate and displace geometry. Prefer Shallow Water Equations (Height-field Water) or Stable Fluids when the flow must react to obstacles and player interaction, and render the simulated velocity through the same two-phase blend. Use Real-time Water Caustics and Planar reflections with oblique near-plane clipping for the surrounding water look.
Field marks
- 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
Presets
Two-phase flow-map water with an eddy
{
"cycle_seconds": 2,
"strength": 0.35
}Show GLSL (29 lines)
// Flow-map water: a flow field advects a pattern; two phase-offset layers are cross-faded to hide the reset.
const float CYCLE = 2.0; // seconds per advection cycle
const float STRENGTH = 0.35; // how far the pattern travels per cycle
float hash(vec2 p) { p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }
float vnoise(vec2 p) {
vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
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);
}
float ripples(vec2 p) { return 0.6 * vnoise(p * 6.0) + 0.3 * vnoise(p * 13.0 + 7.0) + 0.1 * vnoise(p * 29.0); }
vec2 flowField(vec2 p) { // a river bend plus an eddy
vec2 c = p - vec2(0.62, 0.45);
vec2 swirl = vec2(-c.y, c.x) / (dot(c, c) * 40.0 + 0.5);
return normalize(vec2(1.0, 0.4 * sin(p.x * 5.0)) + swirl * 2.0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
vec2 f = flowField(uv);
float t = iTime / CYCLE;
float p0 = fract(t), p1 = fract(t + 0.5);
float w = abs(1.0 - 2.0 * p0); // weight of layer 0 (layer 1 gets 1 - w)
float a = ripples(uv - f * p0 * STRENGTH + 0.0);
float b = ripples(uv - f * p1 * STRENGTH + 0.37);
float v = mix(b, a, w);
vec3 deep = vec3(0.02, 0.18, 0.28), shallow = vec3(0.25, 0.6, 0.62);
vec3 col = mix(deep, shallow, smoothstep(0.2, 0.9, v));
col += pow(smoothstep(0.6, 0.85, v), 3.0) * vec3(0.8, 0.9, 0.95);
fragColor = vec4(pow(col, vec3(1.0 / 2.2)), 1.0);
}
Attribution: written for this index; algorithm from the cited Valve talk · basis: 0
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| flow-map-two-phase-bend | Tesla T4 1920x1080 | 8.50× baseline (moderate) · 0.280 ms / 0.476 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| flow-map-two-phase-bend | NVIDIA L4 1920x1080 | 7.83× baseline (moderate) · 0.124 ms / 0.127 ms · 2.2× faster on L4 | opengl-timer-query · Cross-architecture validation |
| flow-map-two-phase-bend | NVIDIA A100-SXM4-40GB 1920x1080 | 6.17× baseline (moderate) · 0.178 ms / 0.178 ms · 1.6× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Stable Fluids: A simulated velocity field can be baked or streamed as the flow map so water reacts to obstacles.
- Real-time Water Caustics: Normals from the blended layers drive the caustic pattern on the river bed.
- Planar reflections with oblique near-plane clipping: The perturbed normals offset the reflection texture lookup on the water plane.