Backgrounds06 / 118
Liquid Satin
A landscape of glossy satin folds receding into black, their ridges catching a thin-film sheen that slides from cyan through azure and violet to pink as the cloth moves. It lifts under your cursor and twists into a swirl as you sweep across it, a click sends a ripple running through the fabric, and scrolling tilts your view as the folds flow past.
WebGLWebGLIridescent sheenIridescent sheenCursor swirlCursor swirlGSAP ScrollTriggerGSAP ScrollTriggerReduced-motion safeReduced-motion safe
Sweep to twist the clothClick to ripple
Tweak
LIVELIVESheen
#6ad6ff
#4c7dff
#9a6bff
#ff6fcf
#2c3448
1.00
Folds
1.00
1.00
1.00
Motion
1.00
Interactive
Cursor swirl, lift and click ripples
Usage
Follows your tweaks.
usage.tsx
import { LiquidSatin } from "@/components/inreact/liquid-satin";
export function Hero() {
return (
<LiquidSatin
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the fabric */}
</LiquidSatin>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/liquid-satin.jsonOr copy the source
Install the dependencies, then save this as components/inreact/liquid-satin.tsx.
terminal
npm install gsapcomponents/inreact/liquid-satin.tsx
"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Liquid Satin: a landscape of iridescent satin folds on black.
*
* Deep folds of glossy fabric recede into darkness, their ridges catching a
* thin-film sheen that shifts from cyan through azure and violet to pink as
* the cloth moves. The fabric reacts to you: it lifts under your cursor and
* twists into a swirl as you sweep across it, a click sends a ripple running
* through the cloth, and scrolling tilts your view and makes the folds flow.
*
* <LiquidSatin className="h-screen w-full">
* <YourHero />
* </LiquidSatin>
*
* One WebGL fragment shader. GSAP drives the cursor (swirl, lift), the
* ripples, the settle on load and the scroll. Pauses off-screen, renders one
* still frame for reduced motion, falls back to a gradient without WebGL.
*/
export interface LiquidSatinProps {
/** Four colours the iridescent sheen moves through. */
colors?: [string, string, string, string];
/** Colour of the fabric itself, in the half-light. */
base?: string;
/** Depth of the folds. */
relief?: number;
/** Size of the folds: higher means more, smaller folds. */
scale?: number;
/** Strength of the gloss and iridescence. */
sheen?: number;
/** Speed of the fabric's motion. */
speed?: number;
/** How far the folds recede into the distance. */
perspective?: number;
/** Cursor swirl and lift, click ripples. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the fabric. */
children?: ReactNode;
className?: string;
}
const RIPPLES = 3;
const VERT = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;
const FRAG = `
precision highp float;
uniform vec2 uRes, uMouse;
uniform float uTime, uRelief, uScale, uSheen, uPersp, uLift, uSwirl, uSettle, uLight, uFlow;
uniform vec3 uC0, uC1, uC2, uC3, uBase;
uniform vec4 uRip[${RIPPLES}];
vec3 pal(float t) {
t = fract(t) * 4.0;
if (t < 1.0) return mix(uC0, uC1, smoothstep(0.0, 1.0, t));
if (t < 2.0) return mix(uC1, uC2, smoothstep(1.0, 2.0, t));
if (t < 3.0) return mix(uC2, uC3, smoothstep(2.0, 3.0, t));
return mix(uC3, uC0, smoothstep(3.0, 4.0, t));
}
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
// the cloth gathers into a slow vortex at its heart, and the cursor twists it further as you sweep
vec2 twist(vec2 uv, float t) {
vec2 c = vec2(0.08 + 0.05 * sin(t * 0.13), -0.06 + 0.04 * cos(t * 0.11));
vec2 d0 = uv - c;
uv = c + rot(1.5 * exp(-dot(d0, d0) / 0.07) + 0.15 * sin(t * 0.2)) * d0;
vec2 d = uv - uMouse;
float k = exp(-dot(d, d) / 0.045);
return uMouse + rot(uSwirl * k) * d;
}
// screen -> fabric: the cloth recedes, folds compressing toward the top
vec2 fabric(vec2 uv) {
float y01 = uv.y + 0.5;
float persp = 1.0 + y01 * y01 * 2.2 * uPersp;
return vec2(uv.x * persp, y01 * persp * 1.25 + uFlow) * uScale * 2.1;
}
// the folds: domain-warped waves with soft creases where the cloth turns under
float cloth(vec2 p, float t) {
vec2 q = p + 0.55 * vec2(sin(p.y * 1.25 + t * 0.31), cos(p.x * 1.05 - t * 0.27));
q += 0.28 * vec2(sin(q.y * 2.5 - t * 0.43 + 1.0), cos(q.x * 2.2 + t * 0.37));
float a = sin(q.x * 2.1 + q.y * 0.75 + t * 0.42);
float b = sin(-q.x * 1.25 + q.y * 2.6 - t * 0.33 + 2.0);
float c = sin(q.x * 3.9 + q.y * 3.1 + t * 0.52);
float d = sin(q.x * -5.3 + q.y * 4.6 - t * 0.6 + 4.0);
// smooth |a| and |b| fold the cloth into sharp creases, the rest rolls it
return sqrt(a * a + 0.006) * 0.9 + sqrt(b * b + 0.02) * 0.45 + c * 0.16 + d * 0.06;
}
// what you do to it: a lift under the cursor and ripples from clicks
float touch(vec2 uv) {
vec2 d = uv - uMouse;
float h = uLift * 0.55 * exp(-dot(d, d) / 0.03);
for (int i = 0; i < ${RIPPLES}; i++) {
vec4 r = uRip[i];
float k = length(uv - r.xy) - r.z;
h += r.w * sin(k * 38.0) * exp(-k * k * 55.0);
}
return h;
}
float height(vec2 uv, float t) {
return cloth(fabric(twist(uv, t)), t) * uRelief * uSettle + touch(uv);
}
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
float t = uTime;
float e = 1.2 / uRes.y;
float h = height(uv, t);
float hx = height(uv + vec2(e, 0.0), t);
float hy = height(uv + vec2(0.0, e), t);
vec3 n = normalize(vec3(-(hx - h) / e * 0.085, -(hy - h) / e * 0.085, 1.0));
vec3 V = normalize(vec3(0.0, -0.35, 1.0));
vec3 L1 = normalize(vec3(-0.55, 0.65, 0.55));
vec3 L2 = normalize(vec3(0.75, -0.15, 0.45));
float diff = max(dot(n, L1), 0.0);
float nh1 = max(dot(n, normalize(L1 + V)), 0.0);
float nh2 = max(dot(n, normalize(L2 + V)), 0.0);
float sharp = pow(nh1, 70.0) + pow(nh2, 90.0) * 0.6;
float broad = pow(nh1, 9.0) + pow(nh2, 12.0) * 0.5;
float nv = max(dot(n, V), 0.0);
float fres = pow(1.0 - nv, 3.0);
// thin-film sheen: the colour slides with the angle of the cloth and its height
vec3 film = pal(nv * 1.6 + h * 0.22 + n.x * 0.35 + t * 0.025);
vec3 col = uBase * (0.07 + diff * 0.42);
col += film * (broad * 0.85 + fres * 0.55) * uSheen;
col += mix(film, vec3(1.0), 0.35) * sharp * 1.4 * uSheen;
// the folds turn under into deep shadow
float crease = smoothstep(0.0, 0.75, h / max(uRelief, 0.2));
col *= mix(0.06, 1.0, crease * crease);
// the cloth fades into black toward the far distance
float y01 = gl_FragCoord.y / uRes.y;
col *= 1.0 - smoothstep(0.42, 0.95, y01) * 0.97;
col *= 1.0 - 0.3 * dot(uv * vec2(0.7, 1.0), uv * vec2(0.7, 1.0));
col *= uLight;
col = 1.0 - exp(-col * 1.35);
col += (hash(gl_FragCoord.xy + fract(t * 7.0) * 91.0) - 0.5) / 160.0;
gl_FragColor = vec4(max(col, 0.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 LiquidSatin({
colors = ["#6ad6ff", "#4c7dff", "#9a6bff", "#ff6fcf"],
base = "#2c3448",
relief = 1,
scale = 1,
sheen = 1,
speed = 1,
perspective = 1,
interactive = true,
scroller,
children,
className,
}: LiquidSatinProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ colors, base, relief, scale, sheen, speed, perspective, interactive });
const redraw = useRef<(() => void) | null>(null);
const [c0, c1, c2, c3] = colors;
useEffect(() => {
props.current = { colors: [c0, c1, c2, c3], base, relief, scale, sheen, speed, perspective, interactive };
redraw.current?.();
}, [c0, c1, c2, c3, base, relief, scale, sheen, speed, perspective, 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;";
host.prepend(canvas);
const gl = canvas.getContext("webgl", { antialias: false, alpha: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(90% 70% at 50% 90%, ${p.colors[2]}55, transparent 70%), radial-gradient(60% 50% at 30% 80%, ${p.colors[0]}33, transparent 70%), #000`;
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);
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", "uTime", "uRelief", "uScale", "uSheen", "uPersp", "uLift", "uSwirl", "uSettle", "uLight", "uFlow", "uC0", "uC1", "uC2", "uC3", "uBase", "uRip"].map(
(n) => [n, gl.getUniformLocation(prog, n)],
),
) as Record<string, WebGLUniformLocation | null>;
// ---- state: every value here is moved by GSAP ----
const s = { mx: 0.2, my: -0.1, lift: 0, swirl: 0, settle: still ? 1 : 0.35, light: still ? 1 : 0, flow: 0, tilt: 0, boost: 0 };
const ripples = Array.from({ length: RIPPLES }, () => ({ x: 0, y: 0, r: 0, a: 0 }));
const ripBuf = new Float32Array(RIPPLES * 4);
let rip = 0;
let time = 4.2;
let w = 1, h = 1;
const resize = () => {
const dpr = Math.min(window.devicePixelRatio || 1, 1.5);
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();
const draw = () => {
const p = props.current;
ripples.forEach((r, i) => ripBuf.set([r.x, r.y, r.r, r.a], i * 4));
gl.uniform2f(U.uRes, canvas.width, canvas.height);
gl.uniform2f(U.uMouse, s.mx, s.my);
gl.uniform1f(U.uTime, time);
gl.uniform1f(U.uRelief, p.relief);
gl.uniform1f(U.uScale, p.scale);
gl.uniform1f(U.uSheen, p.sheen);
gl.uniform1f(U.uPersp, p.perspective * (1 + s.tilt));
gl.uniform1f(U.uLift, s.lift);
gl.uniform1f(U.uSwirl, s.swirl);
gl.uniform1f(U.uSettle, s.settle);
gl.uniform1f(U.uLight, s.light);
gl.uniform1f(U.uFlow, s.flow);
gl.uniform3fv(U.uC0, rgb(p.colors[0]));
gl.uniform3fv(U.uC1, rgb(p.colors[1]));
gl.uniform3fv(U.uC2, rgb(p.colors[2]));
gl.uniform3fv(U.uC3, rgb(p.colors[3]));
gl.uniform3fv(U.uBase, rgb(p.base));
gl.uniform4fv(U.uRip, ripBuf);
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
const ro = new ResizeObserver(() => {
resize();
if (still) 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 comes up and the cloth settles into its folds ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { light: 1, duration: 2.2, ease: "power2.out" }, 0)
.to(s, { settle: 1, duration: 3.2, ease: "expo.out" }, 0);
// ---- cursor: the cloth lifts under you and twists as you sweep ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.9, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.9, ease: "power3" });
const swirlTo = gsap.quickTo(s, "swirl", { duration: 1.1, ease: "power2.out" });
const unwind = gsap.delayedCall(0.12, () => swirlTo(0)).pause();
let lp: { x: number; y: number; t: number } | null = null;
const toUv = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left - r.width / 2) / r.height, y: -(e.clientY - r.top - r.height / 2) / r.height };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = toUv(e);
mxTo(p.x);
myTo(p.y);
const now = performance.now();
if (lp) {
const dt = Math.max(8, now - lp.t);
// sweeping right twists one way, left the other; faster sweeps twist harder
const vx = (p.x - lp.x) / dt;
const vy = (p.y - lp.y) / dt;
swirlTo(gsap.utils.clamp(-2.4, 2.4, (vx - vy * 0.5) * 900));
unwind.restart(true);
}
lp = { ...p, t: now };
};
const enter = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = toUv(e);
gsap.set(s, { mx: p.x, my: p.y });
gsap.to(s, { lift: 1, duration: 1.1, ease: "power3.out", overwrite: "auto" });
};
const leave = () => {
lp = null;
swirlTo(0);
gsap.to(s, { lift: 0, duration: 1.4, ease: "power3.out", overwrite: "auto" });
};
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = toUv(e);
const r = ripples[rip++ % RIPPLES];
gsap.killTweensOf(r);
Object.assign(r, { x: p.x, y: p.y, r: 0, a: 0.22 });
gsap.to(r, { r: 1.8, duration: 3, ease: "power1.out" });
gsap.to(r, { a: 0, duration: 3, ease: "power2.in" });
// the cloth jumps a little at the touch, then settles
gsap.fromTo(s, { lift: 1.6 }, { lift: 1, duration: 1.4, ease: "elastic.out(1, 0.4)", overwrite: "auto" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerenter", enter);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: your view tilts over the cloth and the folds flow past ----
const flowTo = gsap.quickTo(s, "flow", { duration: 1.4, ease: "power3" });
const tiltTo = gsap.quickTo(s, "tilt", { duration: 1.4, ease: "power3" });
const boostTo = gsap.quickTo(s, "boost", { duration: 0.8, ease: "power2.out" });
const calm = gsap.delayedCall(0.2, () => boostTo(0)).pause();
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
flowTo(self.progress * 2.2);
tiltTo((self.progress - 0.5) * 0.6);
boostTo(gsap.utils.clamp(0, 1, Math.abs(self.getVelocity()) / 2400));
calm.restart(true);
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const tick = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt * props.current.speed * (1 + s.boost * 2.5);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
intro.kill();
unwind.kill();
calm.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerenter", enter);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
ripples.forEach((r) => gsap.killTweensOf(r));
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden bg-black", className].filter(Boolean).join(" ")}>
{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
11 propscolors[string, string, string, string]Four colours the iridescent sheen moves through.default ["#6ad6ff", "#4c7dff", "#9a6bff", "#ff6fcf"]default ["#6ad6ff", "#4c7dff", "#9a6bff", "#ff6fcf"]basestringColour of the fabric itself, in the half-light.default "#2c3448"default "#2c3448"reliefnumberDepth of the folds.default 1default 1scalenumberSize of the folds: higher means more, smaller folds.default 1default 1sheennumberStrength of the gloss and iridescence.default 1default 1speednumberSpeed of the fabric's motion.default 1default 1perspectivenumberHow far the folds recede into the distance.default 1default 1interactivebooleanCursor swirl and lift, click ripples.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the fabric.classNamestringSize it, e.g. h-screen w-full.