Leather Drape
A sheet of black leather lying in deep, soft folds. Diagonal drapery with rounded ridges and creased valleys is covered in a real two-scale pebble grain, domed pebbles inside a network of fine creases, that follows every fold. A semi-gloss finish catches a soft key light along the ridges and a rim from the side while the valleys fall into deep shadow, and the drape breathes slowly so it is never still. It is tactile: your cursor presses into the hide, leaving a soft dent with compression wrinkles gathering around it, and dragging pulls the folds after your hand like real fabric before they ease back, while a small lamp at the cursor rakes across the grain so every pebble glints. A click sends a ripple through the drape, scrolling makes the folds flow, and on load the leather settles into its folds. Every motion runs on soft springs.
Tweak
LIVELIVEColour
Leather
Motion
Interactive
Press and drag the leather, click for a ripple
Usage
Follows your tweaks.
import { LeatherDrape } from "@/components/inreact/leather-drape";
export function Hero() {
return (
<LeatherDrape
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the leather */}
</LeatherDrape>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/leather-drape.jsonOr copy the source
Install the dependencies, then save this as components/inreact/leather-drape.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);
/**
* Leather Drape: a sheet of black leather lying in deep, soft folds.
*
* Diagonal drapery with rounded ridges and creased valleys, covered in a real
* two-scale pebble grain (domed pebbles inside a network of fine creases) that
* follows every fold. A semi-gloss finish catches a soft key light along the
* ridges and a rim from the side; the valleys fall into deep, soft shadow.
* The drape breathes slowly so it is never still.
*
* It is tactile: your cursor presses into the hide, leaving a soft dent with
* compression wrinkles gathering around it, and dragging pulls the folds after
* your hand like real fabric before they ease back. A small lamp at the cursor
* rakes across the grain so every pebble glints. A click sends a ripple
* through the drape, scrolling makes the folds flow, and on load the leather
* settles into its folds. Every motion runs on soft springs.
*
* <LeatherDrape className="h-screen w-full">
* <YourHero />
* </LeatherDrape>
*
* WebGL2: one shader builds the fold height field (warped, folded sines), the
* grain (two Voronoi layers), lights it, then a bloom at 1/4 and 1/16 size.
* GSAP drives every motion. Pauses off-screen; reduced motion shows a still
* frame; a CSS gradient without WebGL2.
*/
export interface LeatherDrapeProps {
/** Colour of the leather (near black by default; try oxblood or cognac). */
color?: string;
/** Colour of the light on the ridges. */
light?: string;
/** Colour of the cursor lamp. */
lamp?: string;
/** Background colour (the deepest shadow). */
background?: string;
/** How deep the folds are. */
depth?: number;
/** How strong the pebble grain is, 0 to 1.5. */
grain?: number;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** Speed of the breathing drape. */
speed?: number;
/** Strength of the bloom on highlights. */
glow?: number;
/** Press, drag, lamp, click ripple, scroll flow. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the leather. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
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, uDrag; // css px, top-left origin
uniform float uDpr, uTime, uFlow, uAmp, uGrain, uFocus, uHover, uPress, uScale, uLampI, uScrollY;
uniform vec3 uColor, uLight, uLamp, uBg;
uniform vec4 uWave[${MAXW}];
in vec2 vUv;
out vec4 o;
const float TAU = 6.2831853;
// sine-free hashes (Dave Hoskins): cheaper than sin() and stable across GPUs
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); }
vec2 h22(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973)); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.xx + p3.yz) * p3.zy); }
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.68 + noise(p * 2.03 + 7.1) * 0.32; }
// the drape: a few big, sweeping folds. Smooth-abs sines give rounded ridges and soft valleys
// (no hard crease lines), layered at three scales and swept into curves by the warp.
float sabs(float x) { return sqrt(x * x + 0.06); }
float drape(vec2 q) {
float S = uScale;
vec2 d1 = normalize(vec2(1.0, -0.75)), d2 = normalize(vec2(1.0, -0.35)), d3 = normalize(vec2(0.45, -1.0));
float a = dot(q, d1) / (430.0 * S) * TAU + uFlow;
float b = dot(q, d2) / (250.0 * S) * TAU - uFlow * 0.55 + 1.7 + 0.9 * sin(a * 0.5);
float c = dot(q, d3) / (760.0 * S) * TAU + uFlow * 0.3;
return sabs(sin(a)) * 0.62 + sabs(sin(b)) * 0.24 + (sin(c) * 0.5 + 0.5) * 0.34;
}
// pebble grain: Voronoi pebbles, each a small dome; returns slope (xy) and crease mask (z)
vec3 pebbles(vec2 p, float cell, float seed) {
vec2 g = p / cell;
vec2 b = floor(g);
float d1 = 1e9, d2 = 1e9;
vec2 v1 = vec2(0.0);
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
vec2 id = b + vec2(float(i), float(j));
vec2 c = id + 0.5 + (h22(id + seed) - 0.5) * 0.85;
vec2 dv = g - c;
float d = dot(dv, dv);
if (d < d1) { d2 = d1; d1 = d; v1 = dv; }
else if (d < d2) { d2 = d; }
}
float edge = sqrt(d2) - sqrt(d1);
// domed pebble: slopes outward from its centre, flattening into the crease
vec2 slope = v1 * 2.2 * smoothstep(0.0, 0.45, edge);
// creases are at least ~1.4 px wide, so they never break into dotted, aliased lines
float wC = max(0.07, 1.4 / (cell * uDpr));
float crease = 1.0 - smoothstep(0.0, wC, edge);
return vec3(slope, crease);
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float S = uScale;
// the fabric is pulled toward where the hand drags it, and slides with scroll
vec2 dm = p - uMouse;
float r2 = dot(dm, dm);
float pull = exp(-r2 / pow(260.0 * S, 2.0)) * uHover;
vec2 warp = (vec2(fbm(p / (640.0 * S) + vec2(uTime * 0.02, 0.0)), fbm(p / (640.0 * S) + vec2(4.3, uTime * 0.017))) - 0.5) * 520.0 * S;
vec2 q = p + warp - uDrag * pull + vec2(0.0, uScrollY);
// height: the drape, the dent and wrinkles where the cursor presses, and click ripples
float R = 70.0 * S;
float r = sqrt(r2);
float dent = exp(-r2 / (R * R)) * uPress * uHover;
float ring = exp(-pow((r - R * 1.5) / (R * 0.9), 2.0)) * uPress * uHover;
float angW = atan(dm.y, dm.x);
float wave = 0.0;
vec2 waveSlope = vec2(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;
float rr = length(p - W.xy);
float front = age * 420.0 * S;
float env = exp(-pow((rr - front) / (110.0 * S), 2.0)) * exp(-age * 1.1) * W.w;
float ph = (rr - front) / (38.0 * S);
wave += sin(ph) * env;
waveSlope += (rr > 1.0 ? (p - W.xy) / rr : vec2(0.0)) * cos(ph) * env;
}
// a height function so we can take its slope; the warp is held fixed over the tiny step
vec2 e = vec2(1.5, 0.0);
float hc = drape(q);
float hx = drape(q + e.xy);
float hy = drape(q + e.yx);
float amp = 150.0 * S * uAmp;
vec2 slope = vec2(hx - hc, hy - hc) / 1.5 * amp;
// dent: a soft hollow; wrinkles: radial creases gathering around it
slope += dm / (R * R) * 2.0 * dent * 26.0 * S;
float wr = sin(angW * 9.0 + noise(vec2(angW * 2.0, r * 0.015)) * 3.0);
slope += vec2(-sin(angW), cos(angW)) * wr * ring * 0.18;
// click ripples travel through the leather
slope += waveSlope * 0.45;
// grain follows the drape (it lives in the fabric's own coordinates)
float px = 1.0 / uDpr;
// the grain is stretched a little along the folds, the way hide stretches over a drape
vec2 fd = normalize(vec2(1.0, -0.75));
vec2 qa = vec2(dot(q, fd) * 0.82, dot(q, vec2(-fd.y, fd.x)));
// a gentle wobble so creases meander like real hide instead of running dead straight
qa += (vec2(noise(qa / (16.0 * S)), noise(qa / (16.0 * S) + 5.2)) - 0.5) * 9.0 * S;
float gFade1 = smoothstep(2.0 * px, 4.5 * px, 10.5 * S);
// two layers, like real pebbled leather: plump pebbles inside a network of larger creased plates
vec3 g1 = pebbles(qa, 10.5 * S, 0.0);
vec3 g2 = pebbles(qa * vec2(1.0, 1.15), 27.0 * S, 17.0);
// the hide is patchy: grain is deeper in some areas and almost smooth in others
float patch_ = smoothstep(0.25, 0.75, noise(q / (180.0 * S) + 9.0));
vec2 gs = g1.xy * 0.2 * gFade1 * (0.6 + 0.4 * patch_) + g2.xy * 0.12;
// back to screen orientation
vec2 grainSlope = vec2(gs.x * fd.x - gs.y * fd.y, gs.x * fd.y + gs.y * fd.x) * uGrain;
float crease = max(g1.z * 0.45 * gFade1, g2.z * 0.85 * (0.55 + 0.45 * patch_)) * uGrain;
vec3 n = normalize(vec3(-(slope + grainSlope), 1.0));
// light: a soft key from the top left, a cool rim from the right, the cursor lamp
vec3 L1 = normalize(vec3(-0.55, -0.75, 0.55));
vec3 L2 = normalize(vec3(0.85, 0.1, 0.35));
vec3 V = vec3(0.0, 0.0, 1.0);
float lam1 = max(dot(n, L1), 0.0);
float lam2 = max(dot(n, L2), 0.0);
vec3 H1 = normalize(L1 + V), H2 = normalize(L2 + V);
float gloss = 1.0 - crease * 0.85;
// a sharp glint that sparkles on every lit pebble, and a broad sheen that shapes the folds
float spec1 = (pow(max(dot(n, H1), 0.0), 36.0) * 1.0 + pow(max(dot(n, H1), 0.0), 6.0) * 0.36) * gloss;
float spec2 = pow(max(dot(n, H2), 0.0), 22.0) * 0.5 * gloss;
vec3 Lp = normalize(vec3(uMouse - p, 190.0 * S));
vec3 Hp = normalize(Lp + V);
float lampFall = exp(-r2 / pow(340.0 * S, 2.0)) * uHover * uLampI;
float specP = (pow(max(dot(n, Hp), 0.0), 60.0) * 0.85 + max(dot(n, Lp), 0.0) * 0.05) * lampFall * gloss;
// valleys sink into soft shadow (by how far below the ridge they are)
float occl = mix(0.16, 1.0, smoothstep(0.2, 1.05, hc - dent * 0.6));
vec3 col = uColor * (0.08 + lam1 * 0.68 + lam2 * 0.14) * occl;
col += uLight * (spec1 + spec2) * occl;
col += uLamp * specP;
// creases read as fine dark lines where the light falls, and vanish in shadow
col *= 1.0 - crease * 0.42;
// a little sheen at grazing angles, like waxed hide
col += uLight * pow(1.0 - n.z, 3.0) * 0.08 * occl;
// click ripples catch the light as they pass
col += uLight * max(wave, 0.0) * 0.08 * occl;
vec2 cc = (p - uRes * 0.5) / (uRes * 0.5);
col *= 1.0 - uFocus * 0.7 * exp(-dot(cc * vec2(1.0, 1.3), cc * vec2(1.0, 1.3)) / 0.3);
col = max(col, uBg);
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.65, 1.2, 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];
}
export function LeatherDrape({
color = "#2a2a2c",
light = "#eef0f4",
lamp = "#fff4e2",
background = "#000000",
depth = 1,
grain = 1,
focus = 0.3,
speed = 1,
glow = 0.4,
interactive = true,
scroller,
children,
className,
}: LeatherDrapeProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, light, lamp, background, depth, grain, focus, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, light, lamp, background, depth, grain, focus, speed, glow, interactive };
redraw.current?.();
}, [color, light, lamp, background, depth, grain, 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 = `linear-gradient(150deg, ${p.color} 0%, ${p.background} 35%, ${p.color} 55%, ${p.background} 80%)`;
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", "uDrag", "uDpr", "uTime", "uFlow", "uAmp", "uGrain", "uFocus", "uHover", "uPress", "uScale", "uLampI", "uScrollY",
"uColor", "uLight", "uLamp", "uBg", "uWave",
]);
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;
};
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.3);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
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)),
};
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, press: 0, lamp: 1, scrollY: 0 };
// drag is a soft spring: the folds chase the hand and ease back with a little overshoot
const drag = { x: 0, y: 0, vx: 0, vy: 0, gx: 0, gy: 0 };
let flow = still ? 2 : 0, flowV = 0, flowSpd = 0, flowGoal = 0;
const t0 = performance.now();
const clock = () => (still ? 8 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
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.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.uDrag, drag.x, drag.y);
gl.uniform1f(US.uDpr, dpr * (X.scene.w / canvas.width));
gl.uniform1f(US.uTime, now * p.speed);
gl.uniform1f(US.uFlow, flow);
gl.uniform1f(US.uAmp, Math.max(0, p.depth) * s.intro);
gl.uniform1f(US.uGrain, Math.max(0, Math.min(1.5, p.grain)));
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uPress, s.press);
gl.uniform1f(US.uScale, Math.max(0.6, Math.min(1, Math.min(w, h * 1.3) / 1100)));
gl.uniform1f(US.uLampI, s.lamp);
gl.uniform1f(US.uScrollY, s.scrollY);
gl.uniform3fv(US.uColor, rgb(p.color));
gl.uniform3fv(US.uLight, rgb(p.light));
gl.uniform3fv(US.uLamp, rgb(p.lamp));
gl.uniform3fv(US.uBg, rgb(p.background));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t * p.speed, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
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, p.glow);
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();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the leather settles into its folds ----
const intro = gsap.to(s, { intro: 1, duration: 2.6, ease: "elastic.out(1, 0.55)", delay: 0.15 });
// ---- cursor: press, drag, lamp ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.5, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.5, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.9, ease: "sine.inOut" });
const pressTo = gsap.quickTo(s, "press", { duration: 0.7, ease: "power2.out" });
let first = true;
let last = { x: 0, y: 0, t: 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);
const t = performance.now();
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
} else {
const dt = Math.max(8, t - last.t) / 1000;
// the hand drags the fabric: the goal leans along the motion, capped so it stays fabric-like
const k = 0.09;
drag.gx = Math.max(-90, Math.min(90, drag.gx + ((p.x - last.x) / dt) * k * dt * 6));
drag.gy = Math.max(-90, Math.min(90, drag.gy + ((p.y - last.y) / dt) * k * dt * 6));
}
last = { x: p.x, y: p.y, t };
mxTo(p.x);
myTo(p.y);
hoverTo(1);
pressTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
pressTo(0);
};
// ---- click: a ripple through the drape, and the lamp swells ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: clock(), s: 1 });
if (waves.length > MAXW) waves.shift();
gsap.killTweensOf(s, "lamp");
gsap.timeline().to(s, { lamp: 1.6, duration: 0.35, ease: "sine.out" }).to(s, { lamp: 1, duration: 1.4, ease: "sine.inOut" });
flowGoal += 0.9;
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the folds flow with the page ----
const scrollYTo = gsap.quickTo(s, "scrollY", { 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) => {
scrollYTo((self.progress - 0.5) * -h * 0.3);
if (lastProgress >= 0 && props.current.interactive) flowGoal += (self.progress - lastProgress) * 14;
lastProgress = self.progress;
},
});
// ---- loop: springs for the drag and the flow ----
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;
// frame pacing: step the render scale down when frames run long, back up when there is headroom
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();
}
}
// drag goal relaxes; the drag spring chases it with a soft overshoot
drag.gx *= Math.exp(-dt * 1.6);
drag.gy *= Math.exp(-dt * 1.6);
drag.vx += ((drag.gx - drag.x) * 22 - drag.vx * 5.5) * dt;
drag.vy += ((drag.gy - drag.y) * 22 - drag.vy * 5.5) * dt;
drag.x += drag.vx * dt;
drag.y += drag.vy * dt;
// flow: idle breathing plus a spring-smoothed push from clicks and scroll
flowGoal *= Math.exp(-dt * 0.9);
flowV += ((flowGoal - flowSpd) * 10 - flowV * 4.5) * dt;
flowSpd += flowV * dt;
flow += dt * (0.05 * P.speed + flowSpd * 0.5);
const now = clock();
for (let i = waves.length - 1; i >= 0; i--) if (now - waves[i].t > 3.2) 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();
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>
);
}
export default LeatherDrape;
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
13 propscolorstringColour of the leather (near black by default; try oxblood or cognac).default "#2a2a2c"default "#2a2a2c"lightstringColour of the light on the ridges.default "#eef0f4"default "#eef0f4"lampstringColour of the cursor lamp.default "#fff4e2"default "#fff4e2"backgroundstringBackground colour (the deepest shadow).default "#000000"default "#000000"depthnumberHow deep the folds are.default 1default 1grainnumberHow strong the pebble grain is, 0 to 1.5.default 1default 1focusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.3default 0.3speednumberSpeed of the breathing drape.default 1default 1glownumberStrength of the bloom on highlights.default 0.4default 0.4interactivebooleanPress, drag, lamp, click ripple and scroll flow.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the leather.classNamestringSize it, e.g. h-screen w-full.