Lacquer Tiles
Rounded slabs of glossy black lacquer lie tilted in layers in the dark, each with a fine bevelled rim catching a razor line of light, a groove just inside it, and a gently domed face reflecting a soft studio light as a pale square gliding across it. Every tile casts a soft shadow onto those beneath. The light swings with your cursor so the reflections slide across every face and the layers part in parallax, a click lifts the nearest tiles and sweeps light across the stack, and scrolling drifts the layers.
Tweak
LIVELIVEColour
Tiles
Motion
Interactive
The light follows the cursor, clicks lift the tiles
Usage
Follows your tweaks.
import { LacquerTiles } from "@/components/inreact/lacquer-tiles";
export function Hero() {
return (
<LacquerTiles
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the tiles */}
</LacquerTiles>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/lacquer-tiles.jsonOr copy the source
Install the dependencies, then save this as components/inreact/lacquer-tiles.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);
/**
* Lacquer Tiles: glossy black tiles stacked in the dark, each rimmed with light.
*
* Rounded slabs of black lacquer lie tilted across the frame in layers, one over
* another. Each has a fine bevelled rim that catches a razor line of light, a
* second groove just inside it, and a glossy face that reflects a soft studio
* light as a broad pale square gliding across it. Every tile casts a soft
* shadow onto the ones beneath, so the stack has real depth. A real bloom pass
* lets the brightest rims glow; the blacks stay black.
*
* It is always alive: the tiles drift gently and the studio light glides. It
* reacts: the light swings with your cursor so the reflections slide across
* every face, and the layers part in parallax; a click lifts the tiles nearest
* it and sweeps a band of light across the stack; scrolling drifts the layers
* at their own speeds. On load the rims light up one by one.
*
* <LacquerTiles className="h-screen w-full">
* <YourHero />
* </LacquerTiles>
*
* WebGL: one shader (rounded-box distance fields, bevel and groove profile,
* domed faces reflecting soft boxes, layered soft shadows), then 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 WebGL.
*/
export interface LacquerTilesProps {
/** Colour of the light on the rims and faces. */
light?: string;
/** Tint of the lacquer. */
lacquer?: string;
/** Background colour. */
background?: string;
/** Size of the tiles. */
size?: number;
/** Strength of the reflections on the faces. */
gloss?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the drift. */
speed?: number;
/** Cursor light and parallax, click lift. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the tiles. */
children?: ReactNode;
className?: string;
}
const N = 7;
/** the stack, back to front: x, y (from the centre, height units), half width, half height, angle, depth */
const TILES: [number, number, number, number, number, number][] = [
[-0.55, 0.42, 0.34, 0.26, 0.72, 0.0],
[0.62, 0.38, 0.3, 0.24, 0.8, 0.15],
[0.05, -0.62, 0.36, 0.25, 0.76, 0.3],
[-0.38, -0.12, 0.32, 0.3, 0.78, 0.5],
[0.42, -0.08, 0.3, 0.27, 0.74, 0.65],
[-0.05, 0.55, 0.28, 0.2, 0.82, 0.8],
[0.55, -0.6, 0.26, 0.22, 0.77, 0.95],
];
const QUAD = `attribute vec2 aQ; varying vec2 vUv; void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `
precision highp float;
uniform vec2 uRes, uEnv, uPar, uSweepC;
uniform float uTime, uIn, uSize, uGloss, uSweep, uSweepAmp;
uniform vec3 uLight, uLacquer, uBg;
uniform vec4 uA[${N}];
uniform vec4 uB[${N}];
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float sdRBox(vec2 p, vec2 b, float r) {
vec2 q = abs(p) - b + r;
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
}
// the studio: dark, with one broad soft box (whose reflection is the pale square on each face) and two strip lights
float env(vec3 r) {
vec2 c = r.xy - uEnv;
vec2 q = abs(c) - vec2(0.2, 0.16);
float box = 1.0 - smoothstep(0.0, 0.12, length(max(q, 0.0)) + min(max(q.x, q.y), 0.0));
float strip = exp(-pow((dot(r.xy, normalize(vec2(1.0, 1.0))) - 0.35 - uEnv.x * 0.5) / 0.05, 2.0));
float strip2 = exp(-pow((dot(r.xy, normalize(vec2(-1.0, 1.0))) + 0.45 + uEnv.y * 0.5) / 0.07, 2.0)) * 0.5;
// a click's sweep: a band of light running across the studio
float sweep = exp(-pow((r.x + r.y - (uSweep * 3.0 - 1.5)) / 0.15, 2.0)) * uSweepAmp;
return box * 0.9 + strip + strip2 + sweep * 1.4;
}
void main() {
float H = uRes.y;
vec2 p = gl_FragCoord.xy / H;
vec2 c = vec2(uRes.x / H * 0.5, 0.5);
vec3 col = uBg;
float bw = 0.012;
for (int i = 0; i < ${N}; i++) {
vec4 A = uA[i];
vec4 B = uB[i];
// A: centre x, y, angle, depth; B: half w, half h, lift, reveal
vec2 ctr = c + A.xy * uSize + uPar * (0.02 + 0.06 * A.w);
float ca = cos(A.z), sa = sin(A.z);
mat2 R = mat2(ca, sa, -sa, ca);
vec2 hb = B.xy * uSize;
float rad = min(hb.x, hb.y) * 0.32;
// the soft shadow this tile casts onto everything beneath; lifted tiles cast further
vec2 so = vec2(0.018, -0.03) * (1.0 + B.z * 2.0);
float ds = sdRBox(R * (p - ctr - so), hb, rad);
col *= 1.0 - 0.75 * exp(-max(ds, 0.0) / (0.03 + 0.04 * B.z)) * step(-0.002, -ds + 0.06);
vec2 q = R * (p - ctr);
float d = sdRBox(q, hb, rad);
if (d > 0.003) continue;
// the slope of the box surface, from the distance field
float e = 0.0015;
vec2 g = vec2(sdRBox(q + vec2(e, 0.0), hb, rad) - sdRBox(q - vec2(e, 0.0), hb, rad),
sdRBox(q + vec2(0.0, e), hb, rad) - sdRBox(q - vec2(0.0, e), hb, rad));
g = normalize(g + 1e-6);
g = vec2(ca * g.x - sa * g.y, sa * g.x + ca * g.y);
float x = -d / bw;
// profile: a rounded bevel at the edge, a fine groove just inside, then a gently domed face
float slope = 0.0;
if (x < 1.0) slope = (1.0 - x) / sqrt(max(1.0 - (1.0 - x) * (1.0 - x), 0.02));
else slope = 0.9 * exp(-pow((x - 1.9) / 0.25, 2.0)) * sign(x - 1.9) * -1.0;
slope = clamp(slope, -3.0, 3.0);
vec2 qf = q / hb;
vec2 dome = vec2(ca * qf.x - sa * qf.y, sa * qf.x + ca * qf.y) * 0.12;
vec3 n = normalize(vec3(g * slope + dome * smoothstep(1.0, 2.5, x), 1.0));
vec3 r = reflect(vec3(0.0, 0.0, -1.0), n);
float fr = pow(1.0 - n.z, 2.0);
float refl = env(r);
// the rim: a razor line of light where the bevel faces the studio
// the rim is lit by how much that edge faces the light: the edges turned toward it blaze white
vec2 ld = normalize(vec2(-0.55, 0.75) - uEnv * 0.9);
float facing = max(dot(g, ld), 0.0);
float rimLight = 0.18 + 1.6 * pow(facing, 2.0) + 0.5 * refl;
float rim = (1.0 - smoothstep(0.0, 0.22, abs(x - 0.3))) * rimLight;
float groove = exp(-pow((x - 1.9) / 0.12, 2.0)) * (0.12 + 0.8 * pow(facing, 2.0) + 0.4 * refl);
vec3 face = uLacquer * 0.025 + uLight * refl * mix(0.3, 0.9, fr) * uGloss * (0.6 + 0.4 * smoothstep(1.0, 3.0, x));
vec3 tcol = face + uLight * (rim * 1.35 + groove * 0.4);
// tiles further back are a touch dimmer
tcol *= 0.65 + 0.35 * A.w;
tcol *= B.w;
float cover = 1.0 - smoothstep(-1.2 / H, 1.2 / H, d);
col = mix(col, tcol, cover);
}
col *= uIn;
col += (hash(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 1.0);
}`;
const BLUR = `
precision mediump float;
uniform sampler2D uTex;
uniform vec2 uStep;
varying vec2 vUv;
void main() {
vec4 c = texture2D(uTex, vUv) * 0.2270;
c += (texture2D(uTex, vUv + uStep * 1.3846) + texture2D(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture2D(uTex, vUv + uStep * 3.2308) + texture2D(uTex, vUv - uStep * 3.2308)) * 0.0703;
gl_FragColor = c;
}`;
const BRIGHT = `
precision mediump float;
uniform sampler2D uTex;
varying vec2 vUv;
void main() {
vec3 c = texture2D(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
gl_FragColor = vec4(c * smoothstep(0.6, 1.0, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture2D(uScene, vUv).rgb;
vec3 bl = texture2D(uBloom, vUv).rgb * 0.6 + texture2D(uWide, vUv).rgb * 0.5;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.85, 0.0) * 1.3);
col = min(col, vec3(1.0));
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 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 LacquerTiles({
light = "#f4f4f2",
lacquer = "#8a8f99",
background = "#000000",
size = 1,
gloss = 1,
glow = 0.6,
speed = 1,
interactive = true,
scroller,
children,
className,
}: LacquerTilesProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ light, lacquer, background, size, gloss, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { light, lacquer, background, size, gloss, glow, speed, interactive };
redraw.current?.();
}, [light, lacquer, background, size, gloss, glow, 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, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `linear-gradient(135deg, ${p.background} 30%, ${p.lacquer}33 45%, ${p.background} 60%), ${p.background}`;
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.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", "uEnv", "uPar", "uSweepC", "uTime", "uIn", "uSize", "uGloss", "uSweep", "uSweepAmp", "uLight", "uLacquer", "uBg", "uA", "uB"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const drawQuad = (pr: WebGLProgram) => {
const a = gl.getAttribLocation(pr, "aQ");
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.enableVertexAttribArray(a);
gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.disableVertexAttribArray(a);
};
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 x of Object.values(T)) {
gl.deleteFramebuffer(x.fb);
gl.deleteTexture(x.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
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);
const sw = canvas.width, sh = canvas.height;
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();
// ---- state: every value GSAP moves ----
const s = { in: still ? 1 : 0, ex: 0.2, ey: 0.25, dx: 0, dy: 0, px: 0, py: 0, scroll: 0, sweep: 0, sweepAmp: 0 };
const tiles = TILES.map(() => ({ lift: 0, reveal: still ? 1 : 0 }));
const Abuf = new Float32Array(N * 4), Bbuf = new Float32Array(N * 4);
let time = still ? 10 : 0;
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(blurProg);
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const aspect = w / h;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, X.scene.w, X.scene.h);
// the void sits a little right of centre on wide screens, centred on narrow ones, leaving room for content
const off = Math.min(0.18, Math.max(0, (aspect - 1) * 0.12));
TILES.forEach(([x, y, hw, hh, ang, depth], i) => {
const t = time * 0.12 + i * 1.7;
const lift = tiles[i].lift;
// each tile drifts gently on its own; scrolling drifts the near ones further
Abuf.set([x + Math.sin(t) * 0.012, y + Math.cos(t * 0.8) * 0.012 + s.scroll * (0.2 + depth * 0.5), ang + Math.sin(t * 0.6) * 0.015, depth], i * 4);
Bbuf.set([hw * (1 + lift * 0.04), hh * (1 + lift * 0.04), lift, tiles[i].reveal], i * 4);
});
gl.uniform2f(US.uEnv, s.ex + s.dx, s.ey + s.dy);
gl.uniform2f(US.uPar, s.px, s.py);
gl.uniform2f(US.uSweepC, 0, 0);
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uIn, s.in);
gl.uniform1f(US.uSize, p.size * 0.78 * Math.max(1, Math.pow(aspect, 0.35)));
gl.uniform1f(US.uGloss, p.gloss);
gl.uniform1f(US.uSweep, s.sweep);
gl.uniform1f(US.uSweepAmp, s.sweepAmp);
gl.uniform3fv(US.uLight, rgb(p.light));
gl.uniform3fv(US.uLacquer, rgb(p.lacquer));
gl.uniform3fv(US.uBg, rgb(p.background));
gl.uniform4fv(US.uA, Abuf);
gl.uniform4fv(US.uB, Bbuf);
drawQuad(sceneProg);
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(brightProg);
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, time);
drawQuad(compProg);
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 room lights up and the rims come on one by one, back to front ----
const intro = gsap.timeline({ delay: 0.1 }).to(s, { in: 1, duration: 1.6, ease: "power2.out" }, 0);
tiles.forEach((t, i) => intro.to(t, { reveal: 1, duration: 1.1, ease: "power2.out" }, 0.2 + i * 0.16));
// ---- idle: the studio light glides, so the reflections never sit still ----
const drift = gsap
.timeline({ repeat: -1, yoyo: true })
.to(s, { dx: 0.22, dy: -0.12, duration: 5.5, ease: "sine.inOut" })
.to(s, { dx: -0.18, dy: 0.1, duration: 6, ease: "sine.inOut" });
// ---- cursor: the light swings with it and the layers part in parallax ----
const exTo = gsap.quickTo(s, "ex", { duration: 1, ease: "power3" });
const eyTo = gsap.quickTo(s, "ey", { duration: 1, ease: "power3" });
const pxTo = gsap.quickTo(s, "px", { duration: 1.4, ease: "power3" });
const pyTo = gsap.quickTo(s, "py", { duration: 1.4, ease: "power3" });
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 - 0.5, ny: (r.bottom - e.clientY) / r.height - 0.5 };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
exTo(p.nx * -1.2);
eyTo(p.ny * -1.2);
pxTo(p.nx * 0.6);
pyTo(p.ny * 0.6);
};
const leave = () => {
exTo(0.2);
eyTo(0.25);
pxTo(0);
pyTo(0);
};
// ---- click: the nearest tiles lift, and a band of light sweeps across the stack ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const scale = props.current.size * 0.78 * Math.max(1, Math.pow(w / h, 0.35));
TILES.forEach(([x, y], i) => {
const dist = Math.hypot(w / h * 0.5 + x * scale - p.x, 0.5 + y * scale - p.y);
const k = Math.max(0, 1 - dist / 0.5);
if (k <= 0) return;
gsap.killTweensOf(tiles[i], "lift");
gsap.timeline().to(tiles[i], { lift: k, duration: 0.35, ease: "power2.out" }).to(tiles[i], { lift: 0, duration: 1.4, ease: "elastic.out(1, 0.5)" });
});
gsap.killTweensOf(s, "sweep,sweepAmp");
gsap.fromTo(s, { sweep: 0 }, { sweep: 1, duration: 1.4, ease: "power2.inOut" });
gsap.timeline().fromTo(s, { sweepAmp: 0 }, { sweepAmp: 1, duration: 0.2, ease: "sine.out" }).to(s, { sweepAmp: 0, duration: 1.2, ease: "sine.in" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the layers drift, the near ones further ----
const scrollTo = gsap.quickTo(s, "scroll", { duration: 1.2, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => scrollTo((self.progress - 0.5) * 0.3),
});
// ---- 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 * 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();
drift.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
tiles.forEach((t) => gsap.killTweensOf(t));
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>
);
}
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 propslightstringColour of the light on the rims and faces.default "#f4f4f2"default "#f4f4f2"lacquerstringTint of the lacquer.default "#8a8f99"default "#8a8f99"backgroundstringBackground colour.default "#000000"default "#000000"sizenumberSize of the tiles.default 1default 1glossnumberStrength of the reflections on the faces.default 1default 1glownumberStrength of the bloom.default 0.6default 0.6speednumberSpeed of the drift.default 1default 1interactivebooleanCursor light and parallax, click lift.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the tiles.classNamestringSize it, e.g. h-screen w-full.