Sand Ripples
A great dark dune of grainy, monochrome sand sweeps across the frame, combed into fine lopsided ripples that bend with the slope and twist into marbled eddies near the crest. Every ripple is real relief, catching a low raking light on one flank and falling into shadow on the other, and the mass dissolves into black at its edge. The ripples creep on their own; the light swings round to follow your cursor as the sand dips under it, a click rolls a wave across the ripples, and scrolling drifts them.
Tweak
LIVELIVEColour
Sand
Motion
Interactive
The light follows the cursor, clicks roll a wave
Usage
Follows your tweaks.
import { SandRipples } from "@/components/inreact/sand-ripples";
export function Hero() {
return (
<SandRipples
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the dune */}
</SandRipples>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/sand-ripples.jsonOr copy the source
Install the dependencies, then save this as components/inreact/sand-ripples.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);
/**
* Sand Ripples: a dark dune combed into dense ripples, lit by a low raking light.
*
* A great mass of grainy, monochrome sand (or fabric) sweeps across the frame,
* its surface combed into fine parallel ripples that bend with the slope and
* curl into marbled eddies near the crest. It is a real height field: every
* ripple catches the light on one flank and falls into shadow on the other, and
* the whole mass dissolves into black at its edge.
*
* It is always moving: the ripples creep slowly across the dune and the eddies
* turn. It reacts: the raking light swings round to come from your cursor's side
* and the sand dips under it; a click sends a wave rolling out across the
* ripples; scrolling drifts the ripples and lets the light climb. On load the
* light rises over the dune.
*
* <SandRipples className="h-screen w-full">
* <YourHero />
* </SandRipples>
*
* WebGL: one shader (height field of dune, ripples and eddies; normals from three
* samples; raking light; fine grain). GSAP drives every motion. Pauses
* off-screen; reduced motion shows a still frame; a CSS gradient without WebGL.
*/
export interface SandRipplesProps {
/** Colour of the lit sand. */
sand?: string;
/** Colour of the shadows in the ripples. */
shadow?: string;
/** Background colour beyond the dune. */
background?: string;
/** How close together the ripples are. */
ripples?: number;
/** How deep the ripples are. */
relief?: number;
/** Amount of grain. */
grain?: number;
/** Brightness of the light. */
intensity?: number;
/** Speed of the creeping ripples. */
speed?: number;
/** Cursor light and dent, click wave. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the dune. */
children?: ReactNode;
className?: string;
}
const VERT = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;
const FRAG = `
precision highp float;
uniform vec2 uRes, uMouse, uRipC, uLight;
uniform float uTime, uFlow, uIn, uFreq, uRelief, uGrain, uIntensity, uHover, uRip, uRipAmp, uDrift;
uniform vec3 uSand, uShadow, uBg;
float hash(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 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 fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 4; i++) { v += a * vnoise(p); p = p * 2.03 + vec2(7.1, 3.3); a *= 0.5; }
return v;
}
float asp;
// how much dune is here: a great mass sweeping across, its edge wandering, black beyond it
float mass(vec2 p) {
vec2 c = vec2(asp * 0.62, 0.62);
vec2 dir = normalize(vec2(1.0, 0.9));
float s = dot(p - c, dir) + 0.1 * sin(p.y * 2.6 + uFlow * 0.05) + (fbm(p * 2.2 + 4.0) - 0.5) * 0.2;
return smoothstep(0.12, -0.18, s);
}
// the surface height: the dune's swell, fine ripples combed across it, eddies near the crest
float height(vec2 p) {
float m = mass(p);
float big = m * (0.35 + 0.3 * fbm(p * 1.1 + 2.0));
// the ripples follow a slowly curling direction field, bending with the slope
vec2 q = p + (vec2(fbm(p * 1.4 + uFlow * 0.02), fbm(p * 1.4 + 5.0 - uFlow * 0.018)) - 0.5) * 0.35;
// marbled eddies: space twists round a few points near the crest
for (int i = 0; i < 2; i++) {
vec2 e = vec2(asp * (0.28 + 0.3 * float(i)), 0.78 - 0.25 * float(i)) + 0.03 * vec2(sin(uFlow * 0.05 + float(i)), cos(uFlow * 0.04));
vec2 d = q - e;
float k = exp(-dot(d, d) / 0.02) * 2.2;
float cs = cos(k), sn = sin(k);
q = e + mat2(cs, -sn, sn, cs) * d;
}
float ph = dot(q, normalize(vec2(0.35, 1.0))) * uFreq + fbm(q * 3.0) * 3.0 - uFlow * 0.25 + uDrift;
// sand ripples are lopsided: a long gentle back and a short steep face
float r = pow(0.5 + 0.5 * sin(ph + 0.6 * sin(ph)), 1.5);
float h = big + r * 0.0055 * uRelief * (0.3 + m);
// the cursor presses a soft dent; a click's wave rolls out across the sand
vec2 dm = p - uMouse;
h -= exp(-dot(dm, dm) / 0.012) * 0.025 * uHover;
float rl = length(p - uRipC);
h += sin(rl * 40.0 - uRip * 30.0) * exp(-pow((rl - uRip * 1.3) / 0.1, 2.0)) * 0.006 * uRipAmp;
return h;
}
void main() {
float H = uRes.y;
asp = uRes.x / uRes.y;
vec2 p = gl_FragCoord.xy / H;
float e = 1.0 / H;
float h0 = height(p);
float hx = height(p + vec2(e, 0.0));
float hy = height(p + vec2(0.0, e));
vec3 n = normalize(vec3(-(hx - h0) / e, -(hy - h0) / e, 1.0));
// the raking light: low over the dune, coming from the cursor's side
vec3 L = normalize(vec3(uLight, 0.42));
float dif = max(dot(n, L), 0.0);
float spec = pow(max(dot(reflect(-L, n), vec3(0.0, 0.0, 1.0)), 0.0), 18.0);
float m = mass(p);
// the sand itself: speckled, like grains catching the light
float speck = 0.9 + 0.2 * hash(floor(gl_FragCoord.xy * 0.75));
vec3 col = mix(uShadow, uSand, smoothstep(0.1, 1.0, dif) * 0.92) * speck;
col += uSand * spec * 0.25;
// the dune falls away into black at its edge
col = mix(uBg, col, m * (0.4 + 0.6 * smoothstep(0.0, 0.5, m)));
col *= uIntensity * uIn;
// living grain over everything, lightest in the deepest black
float lum = dot(col, vec3(0.33));
float g = hash(floor(gl_FragCoord.xy) + vec2(floor(uTime * 12.0) * 37.0, 0.0)) - 0.5;
col += g * uGrain * (0.02 + 0.12 * smoothstep(0.02, 0.4, lum));
gl_FragColor = vec4(clamp(col, 0.0, 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];
}
export function SandRipples({
sand = "#e8e6e2",
shadow = "#121212",
background = "#060606",
ripples = 1,
relief = 1,
grain = 1,
intensity = 1,
speed = 1,
interactive = true,
scroller,
children,
className,
}: SandRipplesProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ sand, shadow, background, ripples, relief, grain, intensity, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { sand, shadow, background, ripples, relief, grain, intensity, speed, interactive };
redraw.current?.();
}, [sand, shadow, background, ripples, relief, grain, intensity, speed, 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("webgl", { alpha: false, antialias: false });
if (!gl) {
const p = props.current;
host.style.background = `repeating-linear-gradient(160deg, ${p.shadow} 0 6px, ${p.sand}55 8px 10px), ${p.background}`;
canvas.remove();
return;
}
const prog = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, VERT],
[gl.FRAGMENT_SHADER, FRAG],
] 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(prog, sh);
}
gl.linkProgram(prog);
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(prog));
gl.useProgram(prog);
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const aPos = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
const U = Object.fromEntries(
["uRes", "uMouse", "uRipC", "uLight", "uTime", "uFlow", "uIn", "uFreq", "uRelief", "uGrain", "uIntensity", "uHover", "uRip", "uRipAmp", "uDrift", "uSand", "uShadow", "uBg"].map((n) => [n, gl.getUniformLocation(prog, n)]),
) as Record<string, WebGLUniformLocation | null>;
let w = 1, h = 1, dpr = 1;
const resize = () => {
// grain wants real pixels, so render at device resolution
dpr = Math.min(window.devicePixelRatio || 1, 2);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
gl.viewport(0, 0, canvas.width, canvas.height);
};
resize();
// ---- state: every value GSAP moves (height units, y up) ----
const s = { in: still ? 1 : 0, mx: -9, my: -9, hover: 0, rip: 0, ripAmp: 0, rx: 0, ry: 0, drift: 0, lx: -0.85, ly: 0.55, sx: 0, sy: 0 };
let time = still ? 4 : 0, flow = still ? 4 : 0;
const draw = () => {
const p = props.current;
gl.uniform2f(U.uRes, canvas.width, canvas.height);
gl.uniform2f(U.uMouse, s.mx, s.my);
gl.uniform2f(U.uRipC, s.rx, s.ry);
gl.uniform2f(U.uLight, s.lx + s.sx, s.ly + s.sy);
gl.uniform1f(U.uTime, time);
gl.uniform1f(U.uFlow, flow);
gl.uniform1f(U.uIn, s.in);
gl.uniform1f(U.uFreq, 150 * p.ripples);
gl.uniform1f(U.uRelief, p.relief);
gl.uniform1f(U.uGrain, p.grain);
gl.uniform1f(U.uIntensity, p.intensity);
gl.uniform1f(U.uHover, s.hover);
gl.uniform1f(U.uRip, s.rip);
gl.uniform1f(U.uRipAmp, s.ripAmp);
gl.uniform1f(U.uDrift, s.drift);
gl.uniform3fv(U.uSand, rgb(p.sand));
gl.uniform3fv(U.uShadow, rgb(p.shadow));
gl.uniform3fv(U.uBg, rgb(p.background));
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the light rises over the dune ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 2.2, ease: "power2.out" }, 0)
.fromTo(s, { ly: -0.4 }, { ly: 0.55, duration: 3, ease: "power3.out" }, 0);
// ---- idle: the light slowly swings, so the ripples keep catching it ----
const swing = gsap.timeline({ repeat: -1, yoyo: true, delay: 3 }).to(s, { sx: 0.3, sy: -0.15, duration: 6, ease: "sine.inOut" }).to(s, { sx: -0.2, sy: 0.1, duration: 6.5, ease: "sine.inOut" });
// ---- cursor: the light comes from the cursor's side and the sand dips under it ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.7, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.7, ease: "power3" });
const lxTo = gsap.quickTo(s, "lx", { duration: 1.2, ease: "power3" });
const lyTo = gsap.quickTo(s, "ly", { duration: 1.2, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.9, ease: "power2.inOut" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left) / r.height, y: (r.bottom - e.clientY) / r.height, nx: (e.clientX - r.left) / r.width, ny: (r.bottom - e.clientY) / r.height };
};
let first = true;
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
lxTo((p.nx - 0.5) * 2.2);
lyTo((p.ny - 0.5) * 2.0);
};
const leave = () => {
first = true;
hoverTo(0);
lxTo(-0.85);
lyTo(0.55);
};
// ---- click: a wave rolls out across the ripples ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
s.rx = p.x;
s.ry = p.y;
gsap.killTweensOf(s, "rip,ripAmp");
gsap.fromTo(s, { rip: 0 }, { rip: 1, duration: 2.4, ease: "power2.out" });
gsap.timeline().fromTo(s, { ripAmp: 0 }, { ripAmp: 1, duration: 0.3, ease: "sine.out" }).to(s, { ripAmp: 0, duration: 2.1, ease: "sine.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the ripples drift with the scroll ----
const driftTo = gsap.quickTo(s, "drift", { duration: 1.3, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => driftTo(self.progress * 8),
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt;
flow += dt * props.current.speed;
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
return () => {
gsap.ticker.remove(loop);
intro.kill();
swing.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
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
12 propssandstringColour of the lit sand.default "#e8e6e2"default "#e8e6e2"shadowstringColour of the shadows in the ripples.default "#121212"default "#121212"backgroundstringBackground colour beyond the dune.default "#060606"default "#060606"ripplesnumberHow close together the ripples are.default 1default 1reliefnumberHow deep the ripples are.default 1default 1grainnumberAmount of grain.default 1default 1intensitynumberBrightness of the light.default 1default 1speednumberSpeed of the creeping ripples.default 1default 1interactivebooleanCursor light and dent, click wave.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the dune.classNamestringSize it, e.g. h-screen w-full.