Deep Water
A dark, glossy water surface. Near-black water undulates in slow, satin-like folds, mirroring a soft light as broad emerald and deep-teal reflections; some areas glow from beneath while others fall almost black, and the whole surface flows slowly so it is never still. Your cursor leaves a soft wake in the surface that catches the light and slowly smooths out, while a small lamp's reflection glides with you. A click sends ripples rolling across the water, scrolling makes it drift, and on load the light rises out of the dark. Every motion runs on soft springs.
Tweak
LIVELIVEColour
Water
Motion
Interactive
Leave a wake with the cursor, click for ripples
Usage
Follows your tweaks.
import { DeepWater } from "@/components/inreact/deep-water";
export function Hero() {
return (
<DeepWater
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the water */}
</DeepWater>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/deep-water.jsonOr copy the source
Install the dependencies, then save this as components/inreact/deep-water.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Deep Water: a dark, glossy liquid surface with soft satin reflections.
*
* Near-black water whose surface undulates in slow, satin-like folds, mirroring
* a soft light as broad emerald and deep-teal reflections. Some areas glow from
* beneath while others fall almost black, and the whole surface flows slowly
* so it is never still.
*
* It reacts: your cursor leaves a soft wake in the surface that catches the
* light and slowly smooths out, while a small lamp's reflection glides with
* you. A click sends ripples rolling across the water, scrolling makes it
* drift, and on load the light rises out of the dark. Every motion runs on
* soft springs.
*
* <DeepWater className="h-screen w-full">
* <YourHero />
* </DeepWater>
*
* WebGL2: one shader builds the surface (warped noise slopes, the wake and
* ripples) and reflects a soft light, then a bloom at 1/4 and 1/16 size; the
* wake is a small mask simulated in JS. Adaptive resolution keeps 60fps.
* Pauses off-screen; reduced motion shows a still frame; a CSS gradient
* without WebGL2.
*/
export interface DeepWaterProps {
/** The two colours of the reflections. */
colors?: [string, string];
/** Colour of the water itself (the darkest areas). */
liquid?: string;
/** Size of the surface undulations. */
scale?: number;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** Speed of the drift. */
speed?: number;
/** Strength of the reflections and the bloom. */
glow?: number;
/** Cursor wake and lamp, click ripples, scroll drift. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the water. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const MASK = 8;
const QUAD = `#version 300 es
in vec2 aQ; out vec2 vUv;
void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `#version 300 es
precision highp float;
uniform vec2 uRes, uMouse, uDrift; // css px, top-left origin
uniform float uDpr, uTime, uScale, uFocus, uHover, uGlow, uIntro, uFlash;
uniform vec3 uA, uB, uLiquid;
uniform vec4 uWave[${MAXW}];
uniform sampler2D uPart;
in vec2 vUv;
out vec4 o;
float h21(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(h21(i), h21(i + vec2(1, 0)), f.x), mix(h21(i + vec2(0, 1)), h21(i + vec2(1, 1)), f.x), f.y);
}
float fbm(vec2 p) { return noise(p) * 0.6 + noise(p * 2.07 + 5.1) * 0.28 + noise(p * 4.3 + 1.7) * 0.12; }
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float S = uScale;
float t = uTime;
vec2 q = p + uDrift;
// a slow swirl keeps the surface flowing
q += (vec2(fbm(q / (380.0 * S) + t * 0.02), fbm(q / (380.0 * S) + 7.3 - t * 0.017)) - 0.5) * 150.0 * S;
// the surface: soft satin-like undulations
vec2 lq = q / (170.0 * S) + vec2(t * 0.03, -t * 0.02);
float e = 0.06;
vec2 gr = vec2(fbm(lq + vec2(e, 0.0)) - fbm(lq - vec2(e, 0.0)), fbm(lq + vec2(0.0, e)) - fbm(lq - vec2(0.0, e))) / (2.0 * e) * 0.55;
// the cursor's wake: a soft trough that tilts the surface and catches the light
vec2 uv = p / uRes;
vec2 dx = vec2(${MASK}.0 / uRes.x, 0.0), dy = vec2(0.0, ${MASK}.0 / uRes.y);
vec2 wake = vec2(texture(uPart, uv + dx).r - texture(uPart, uv - dx).r, texture(uPart, uv + dy).r - texture(uPart, uv - dy).r);
gr += wake * 1.4;
// click ripples: rings that tilt the surface as they pass
float rip = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 3.0) continue;
vec2 dv = p - W.xy;
float rr = length(dv);
float front = age * 330.0 * S;
float env = exp(-pow((rr - front) / (60.0 * S), 2.0)) * exp(-age * 1.1) * W.w;
gr += (rr > 1.0 ? dv / rr : vec2(0.0)) * cos((rr - front) / (16.0 * S)) * env * 0.5;
rip += env;
}
vec3 nl = normalize(vec3(-gr, 1.0));
vec2 rl = 2.0 * nl.z * nl.xy;
// a broad softbox mirrored in the surface, and the cursor's lamp gliding across it
float near = exp(-dot(p - uMouse, p - uMouse) / pow(260.0 * S, 2.0)) * uHover;
float sheen = exp(-dot(rl - vec2(-0.25, -0.35), rl - vec2(-0.25, -0.35)) / 0.05);
vec2 lampDir = (uMouse - p) / (420.0 * S);
float lampR = exp(-dot(rl - lampDir, rl - lampDir) / 0.02) * near;
// some areas are lit from beneath, others fall almost black
float area = smoothstep(0.3, 0.75, fbm(q / (420.0 * S) + vec2(2.0, t * 0.02)));
vec3 tint = mix(uB, uA, smoothstep(0.2, 0.8, sheen + area * 0.5));
vec3 col = uLiquid + tint * (sheen * 0.75 + area * 0.16 + lampR * 0.9 + rip * 0.12) * uGlow * (1.0 + uFlash * 0.8);
// on load the light rises out of the dark
col = uLiquid + (col - uLiquid) * uIntro;
vec2 cc = (p - uRes * 0.5) / (uRes * 0.5);
col *= 1.0 - uFocus * 0.65 * exp(-dot(cc * vec2(1.0, 1.3), cc * vec2(1.0, 1.3)) / 0.3);
col = max(col, uLiquid * 0.9);
col += (h21(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
o = vec4(col, 1.0);
}`;
const BLUR = `#version 300 es
precision mediump float;
uniform sampler2D uTex; uniform vec2 uStep; in vec2 vUv; out vec4 o;
void main() {
vec4 c = texture(uTex, vUv) * 0.2270;
c += (texture(uTex, vUv + uStep * 1.3846) + texture(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture(uTex, vUv + uStep * 3.2308) + texture(uTex, vUv - uStep * 3.2308)) * 0.0703;
o = c;
}`;
const BRIGHT = `#version 300 es
precision mediump float;
uniform sampler2D uTex; in vec2 vUv; out vec4 o;
void main() {
vec3 c = texture(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
o = vec4(c * smoothstep(0.62, 1.15, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision mediump float;
uniform sampler2D uScene, uBloom, uWide; uniform float uGlow, uTime; in vec2 vUv; out vec4 o;
float h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.6 + texture(uWide, vUv).rgb * 0.4;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.8, 0.0) * 1.1);
col += (h(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
o = vec4(min(col, vec3(1.0)), 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
const DEFAULT_COLORS: [string, string] = ["#2fb79a", "#0d4f55"];
export function DeepWater({
colors = DEFAULT_COLORS,
liquid = "#020505",
scale = 1,
focus = 0.25,
speed = 1,
glow = 1,
interactive = true,
scroller,
children,
className,
}: DeepWaterProps) {
const hostRef = useRef<HTMLDivElement>(null);
const [c1, c2] = colors;
const props = useRef({ c1, c2, liquid, scale, focus, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { c1, c2, liquid, scale, focus, speed, glow, interactive };
redraw.current?.();
}, [c1, c2, liquid, scale, focus, speed, glow, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(50% 40% at 40% 40%, ${p.c1}33, transparent 70%), radial-gradient(40% 40% at 70% 70%, ${p.c2}22, transparent 70%), ${p.liquid}`;
canvas.remove();
return;
}
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.bindAttribLocation(pr, 0, "aQ");
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, [
"uRes", "uMouse", "uDrift", "uDpr", "uTime", "uScale", "uFocus", "uHover", "uGlow", "uIntro", "uFlash",
"uA", "uB", "uLiquid", "uWave", "uPart",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const drawQuad = () => gl.drawArrays(gl.TRIANGLES, 0, 3);
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const t of Object.values(T)) {
gl.deleteFramebuffer(t.fb);
gl.deleteTexture(t.tex);
}
T = null;
};
// ---- the wake: where the cursor has pressed into the surface ----
const partTex = gl.createTexture()!;
let mw = 1, mh = 1;
let part = new Float32Array(1), partGoal = new Float32Array(1), bytes = new Uint8Array(1);
const layoutMask = () => {
mw = Math.max(2, Math.ceil(w / MASK));
mh = Math.max(2, Math.ceil(h / MASK));
part = new Float32Array(mw * mh);
partGoal = new Float32Array(mw * mh);
bytes = new Uint8Array(mw * mh);
gl.bindTexture(gl.TEXTURE_2D, partTex);
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R8, mw, mh, 0, gl.RED, gl.UNSIGNED_BYTE, bytes);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
};
let w = 1, h = 1, dpr = 1;
// adaptive resolution: the scene renders a little smaller when the GPU cannot hold 60fps
let rs = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 1.5);
const nw = Math.max(1, host.clientWidth), nh = Math.max(1, host.clientHeight);
const changed = nw !== w || nh !== h;
w = nw;
h = nh;
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = Math.max(1, Math.round(canvas.width * rs)), sh = Math.max(1, Math.round(canvas.height * rs));
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
if (changed) layoutMask();
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, flash: 0, dx: 0, dy: 0 };
let driftV = 0, driftGoal = 0, driftSpd = 0;
const t0 = performance.now();
let flow = still ? 6 : 0;
const clock = () => (still ? 10 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
// press a wake along a stroke
const partAlong = (x0: number, y0: number, x1: number, y1: number) => {
const R = 64 * Math.max(0.7, Math.min(1, w / 1100));
const steps = Math.max(1, Math.ceil(Math.hypot(x1 - x0, y1 - y0) / (R * 0.35)));
for (let k = 1; k <= steps; k++) {
const x = x0 + ((x1 - x0) * k) / steps, y = y0 + ((y1 - y0) * k) / steps;
const cx = x / MASK, cy = y / MASK, rr = R / MASK;
const minx = Math.max(0, Math.floor(cx - rr)), maxx = Math.min(mw - 1, Math.ceil(cx + rr));
const miny = Math.max(0, Math.floor(cy - rr)), maxy = Math.min(mh - 1, Math.ceil(cy + rr));
for (let j = miny; j <= maxy; j++)
for (let i = minx; i <= maxx; i++) {
const d = Math.hypot(i + 0.5 - cx, j + 0.5 - cy) / rr;
if (d >= 1) continue;
const v = (1 - d * d) * (1 - d * d);
const idx = j * mw + i;
if (v > partGoal[idx]) partGoal[idx] = v;
}
}
};
const blurPass = (src: Target, dst: Target, dx: number, dy: number) => {
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb);
gl.viewport(0, 0, dst.w, dst.h);
gl.useProgram(blurProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, src.tex);
gl.uniform1i(UB.uTex, 0);
gl.uniform2f(UB.uStep, dx / src.w, dy / src.h);
drawQuad();
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const now = clock();
gl.bindTexture(gl.TEXTURE_2D, partTex);
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, mw, mh, gl.RED, gl.UNSIGNED_BYTE, bytes);
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform2f(US.uDrift, s.dx, s.dy);
gl.uniform1f(US.uDpr, dpr * (X.scene.w / canvas.width));
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uScale, Math.max(0.3, p.scale) * Math.max(0.6, Math.min(1, Math.min(w, h * 1.3) / 1100)));
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uGlow, Math.max(0, p.glow));
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uFlash, s.flash);
gl.uniform3fv(US.uA, rgb(p.c1));
gl.uniform3fv(US.uB, rgb(p.c2));
gl.uniform3fv(US.uLiquid, rgb(p.liquid));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, partTex);
gl.uniform1i(US.uPart, 0);
drawQuad();
gl.bindFramebuffer(gl.FRAMEBUFFER, X.a.fb);
gl.viewport(0, 0, X.a.w, X.a.h);
gl.useProgram(brightProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, X.scene.tex);
gl.uniform1i(UR.uTex, 0);
drawQuad();
blurPass(X.a, X.b, 1, 0);
blurPass(X.b, X.a, 0, 1);
blurPass(X.a, X.c, 1, 0);
blurPass(X.c, X.d, 0, 1);
blurPass(X.d, X.c, 1.8, 0);
blurPass(X.c, X.d, 0, 1.8);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.useProgram(compProg);
[X.scene.tex, X.a.tex, X.d.tex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(UC.uScene, 0);
gl.uniform1i(UC.uBloom, 1);
gl.uniform1i(UC.uWide, 2);
gl.uniform1f(UC.uGlow, Math.max(0, p.glow) * 0.45);
gl.uniform1f(UC.uTime, now);
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
gl.deleteTexture(partTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the light rises out of the dark ----
const intro = gsap.to(s, { intro: 1, duration: 2.8, ease: "power2.out", delay: 0.1 });
// ---- cursor: a wake in the surface and a lamp gliding with it ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.45, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.45, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.9, ease: "sine.inOut" });
let first = true;
let last = { x: 0, y: 0 };
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
last = p;
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
partAlong(last.x, last.y, p.x, p.y);
last = p;
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: ripples rolling across the water ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: flow, s: 1 });
if (waves.length > MAXW) waves.shift();
gsap.killTweensOf(s, "flash");
gsap.timeline().to(s, { flash: 1, duration: 0.25, ease: "sine.out" }).to(s, { flash: 0, duration: 1.4, ease: "sine.inOut" });
driftGoal += 0.8;
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the water drifts with the page ----
const dyTo = gsap.quickTo(s, "dy", { duration: 1.2, ease: "power3" });
let lastProgress = -1;
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
dyTo((self.progress - 0.5) * h * 0.5);
if (lastProgress >= 0 && props.current.interactive) driftGoal += Math.abs(self.progress - lastProgress) * 20;
lastProgress = self.progress;
},
});
// ---- loop: springs for the drift and the wake ----
let visible = true;
let prev = performance.now();
let slow = 0, lastScale = performance.now();
const loop = () => {
const t = performance.now();
const dt = Math.min(0.05, (t - prev) / 1000);
prev = t;
if (!visible) return;
const P = props.current;
slow = slow * 0.95 + (dt > 0.0175 ? 0.05 : 0);
if (t - lastScale > 1200) {
if (slow > 0.35 && rs > 0.76) {
rs = Math.max(0.75, rs - 0.08);
lastScale = t;
resize();
} else if (slow < 0.04 && rs < 1 && t - lastScale > 5000) {
rs = Math.min(1, rs + 0.08);
lastScale = t;
resize();
}
}
driftGoal = Math.min(4, driftGoal) * Math.exp(-dt * 0.9);
driftV += ((driftGoal - driftSpd) * 10 - driftV * 4.5) * dt;
driftSpd += driftV * dt;
flow += dt * P.speed * (1 + Math.max(0, driftSpd) * 1.4);
s.dx += dt * 6 * P.speed * (1 + Math.max(0, driftSpd));
// the wake forms quickly and smooths out over a few seconds
const into = 1 - Math.exp(-dt * 7), out = 1 - Math.exp(-dt * 0.35);
for (let i = 0; i < part.length; i++) {
const g = partGoal[i];
part[i] += (g - part[i]) * (g > part[i] ? into : out);
partGoal[i] = g * (1 - out);
bytes[i] = Math.round(Math.min(1, part[i]) * 255);
}
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 3.1) waves.splice(i, 1);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
redraw.current = null;
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(partTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background: liquid }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
export default DeepWater;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
10 propscolors[string, string]The two colours of the reflections.default ["#2fb79a", "#0d4f55"]default ["#2fb79a", "#0d4f55"]liquidstringColour of the water itself (the darkest areas).default "#020505"default "#020505"scalenumberSize of the surface undulations.default 1default 1focusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.25default 0.25speednumberSpeed of the drift.default 1default 1glownumberStrength of the reflections and the bloom.default 1default 1interactivebooleanCursor wake and lamp, click ripples, scroll drift.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the water.classNamestringSize it, e.g. h-screen w-full.