Prism Slick
Black liquid chrome, its highlights split into prism colours like oil on water. A real photograph brought to life with a detailed depth map of its relief: every swell, ridge and contour ring of the liquid. The surface breathes and flows, its highlights sliding along the real tubes of liquid, while a soft light travels across it and breaks into cyan and gold with red and violet fringes, traced separately for each colour. Your cursor pushes the liquid itself: it smears along your stroke, fanning into a prism spectrum, blooms with an oil-slick rainbow where it is disturbed, and wobbles back like thick mercury. A click drops a droplet that craters the surface and sends rings out; press and hold to open a swirling gravity well that sucks the liquid in, then let go and it splashes back. The depth map gives true 2.5D parallax, the cursor is a lamp raking the relief in prism colours, scrolling stretches the liquid and speeds the flow, and on load the surface rises out of the dark as the light sweeps across it. Bring your own photo, depth map and normal map to make it yours.
Tweak
LIVELIVELight
Motion
Interactive
Parallax, liquid lens and prism lamp at the cursor, click for ripples
Lens
Usage
Follows your tweaks.
import { PrismSlick } from "@/components/inreact/prism-slick";
export function Hero() {
return (
<PrismSlick
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the liquid */}
</PrismSlick>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/prism-slick.jsonOr copy the source
Install the dependencies, then save this as components/inreact/prism-slick.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);
/**
* Prism Slick: black liquid chrome, its highlights split into prism colours
* like oil on water.
*
* A real photograph brought to life, with a detailed depth map of its relief:
* every swell, ridge and contour ring of the liquid. The surface breathes and
* flows, its highlights sliding along the real tubes of liquid, while a soft
* light travels across it and breaks into cyan and gold with red and violet
* fringes (real dispersion: the light is traced separately for each colour).
*
* It reacts: the depth map gives true 2.5D parallax as the cursor moves, the
* liquid bulges toward the cursor like a lens, and the cursor is a lamp that
* rakes across the relief in prism colours. A click sends ripples through the
* liquid, scrolling speeds the flow, and on load the surface rises out of the
* dark as the light sweeps across it.
*
* <PrismSlick className="h-screen w-full">
* <YourHero />
* </PrismSlick>
*
* Bring your own photo with `image`, `depthImage` (white = near) and
* `normalImage`. Past the photo's edges the liquid continues as its own mirror
* image. WebGL2, mipmapped, real bloom (1/4 and 1/16 size). Pauses off-screen;
* reduced motion shows a still frame; the plain photo without WebGL2.
*/
export interface PrismSlickProps {
/** The photo. */
image?: string;
/** Its depth map, white = near. */
depthImage?: string;
/** Its normal map (tangent space, +Y up). */
normalImage?: string;
/** The cool light colour. */
cyan?: string;
/** The warm light colour. */
gold?: string;
/** How much the liquid breathes and flows. */
flow?: number;
/** Speed of all the motion. */
speed?: number;
/** Strength of the light raking the relief. */
gloss?: number;
/** Strength of the prism fringes on that light. */
dispersion?: number;
/** Depth parallax strength. */
parallax?: number;
/** Strength of the bloom on the highlights. */
glow?: number;
/** How much of the screen width the photo spans (1 = cover). */
fit?: number;
/** Background shown while the photo loads. */
background?: string;
/** Parallax, lens and lamp at the cursor, click ripples, scroll flow. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the liquid. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const CELL = 16; // css px per cell of the push field
const MAXD = 90; // largest push, css px
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 sampler2D uImg, uDepth, uNrm, uField;
uniform vec2 uRes, uImgSize, uMouse, uPar, uSweep; // css px
uniform float uDpr, uScale, uTime, uFlow, uHover, uGloss, uDisp, uIntro, uLod0, uFlash, uSurge, uMaxD, uSv;
uniform vec3 uCyan, uGold;
uniform vec4 uWave[${MAXW}];
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);
}
// image px (from the photo's centre) -> uv; the textures mirror past the photo's edges
vec2 toUv(vec2 ip) { return ip / uImgSize + 0.5; }
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float minD = min(uRes.x, uRes.y);
vec2 c = uRes * 0.5;
vec2 ip = (p - c) / uScale;
// depth and relief at this point
float dep = texture(uDepth, toUv(ip)).r;
vec3 n0 = texture(uNrm, toUv(ip)).rgb * 2.0 - 1.0;
n0 = vec3(n0.x, -n0.y, n0.z); // to screen space (y down)
// depth parallax: the near swells swing further than the deep troughs
ip -= uPar * (dep - 0.5) / uScale;
// the liquid breathes: each swell rises and falls in turn, so the highlights slide along the real tubes
float t = uTime;
float breathe = sin(t * 0.55 + dep * 6.2831 * 1.5) * 0.6 + sin(t * 0.31 - dep * 6.2831 * 0.8 + 1.7) * 0.4;
ip += n0.xy * breathe * uFlow * 7.0;
// and drifts in a slow, smooth current
vec2 cp = ip / uImgSize.y * 2.2;
vec2 cur = vec2(noise(cp + vec2(t * 0.05, 0.0)), noise(cp + vec2(3.7, t * 0.04))) - 0.5;
ip += cur * uFlow * uImgSize.y * 0.012;
// the liquid bulges toward the cursor like a lens
vec2 dm = p - uMouse;
float near = exp(-dot(dm, dm) / (0.04 * minD * minD)) * uHover;
ip -= dm / uScale * near * 0.12;
// click ripples roll out through the liquid
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 dw = p - W.xy;
float rr = length(dw) / minD;
float fr = rr - age * 0.45;
float k = exp(-fr * fr / 0.006) * exp(-age * 1.1) * W.w;
ip += normalize(dw + 1e-4) * k * sin(fr * 55.0) * 7.0 / uScale;
rip += k;
}
// the liquid your hand has pushed: where each bit of it has been dragged to (springing back like mercury)
vec4 fl = texture(uField, p / uRes);
vec2 disp = (fl.rg * 2.0 - 1.0) * uMaxD;
float mag = fl.b;
// scrolling stretches the liquid along the page
ip.y -= uSv * (p.y - c.y) / uScale * 0.05;
vec2 dsp = disp / uScale;
// prism split: each colour is smeared a different amount, so moving liquid fans into a spectrum
vec2 split = (dsp + vec2(0.0, uSv * 9.0 / uScale)) * 0.22 * uDisp;
ip -= dsp;
vec3 col;
col.r = textureLod(uImg, toUv(ip - split), uLod0).r;
col.g = textureLod(uImg, toUv(ip), uLod0).g;
col.b = textureLod(uImg, toUv(ip + split), uLod0).b;
vec3 n = texture(uNrm, toUv(ip)).rgb * 2.0 - 1.0;
n = normalize(vec3(n.x, -n.y, n.z * 1.2));
// the travelling light and the cursor lamp rake the relief, traced per colour for prism fringes
vec3 V = vec3(0.0, 0.0, 1.0);
vec3 add = vec3(0.0);
for (int k = 0; k < 2; k++) {
vec2 lp = k == 0 ? uSweep : uMouse;
float wk = k == 0 ? 0.4 : uHover * 1.2;
if (wk <= 0.001) continue;
vec2 dl = (lp - p) / minD;
float fall = exp(-dot(dl, dl) / (k == 0 ? 0.25 : 0.08));
vec3 tint = k == 0 ? uCyan : mix(uCyan, uGold, 0.5);
for (int ch = 0; ch < 3; ch++) {
float spread = (float(ch) - 1.0) * 0.09 * uDisp;
vec3 L = normalize(vec3(dl * (1.0 + spread), 0.35));
float sp = pow(max(dot(n, normalize(L + V)), 0.0), 90.0);
add[ch] += sp * fall * wk * tint[ch];
}
}
// the warm light from the other side gilds the opposite flanks
vec3 Lg = normalize(vec3(-(uSweep - c) / minD, 0.4));
add += uGold * pow(max(dot(n, normalize(Lg + V)), 0.0), 70.0) * 0.25;
// the light only blooms where the liquid already catches some light: the blacks stay black
float lit = smoothstep(0.03, 0.2, max(col.r, max(col.g, col.b)));
col += add * uGloss * lit;
// disturbed liquid blooms with an oil-slick rainbow, strongest on the lit rims
float stir = smoothstep(0.03, 0.6, mag);
vec3 slick = 0.5 + 0.5 * cos(6.2831 * (mag * 1.6 + dot(n.xy, normalize(disp + 1e-4)) * 0.6 + uTime * 0.08 + vec3(0.0, 0.33, 0.67)));
col *= 1.0 + stir * 0.7 * lit;
col += slick * stir * (0.04 + 0.22 * lit) * uGloss;
// a ripple catches the light as it passes
col *= 1.0 + rip * 0.6;
col += uCyan * rip * 0.03 + mix(uCyan, uGold, 0.5) * uFlash * 0.02 * near;
// on load the surface rises out of the dark as the light sweeps across it
float sweep = p.x / uRes.x * 0.7 + (1.0 - p.y / uRes.y) * 0.3;
col *= (1.0 - smoothstep(uIntro * 1.6 - 0.45, uIntro * 1.6 - 0.05, sweep)) * smoothstep(0.0, 0.25, uIntro);
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.5, 0.95, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision highp float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow;
in vec2 vUv; out vec4 o;
float h(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); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.85 + texture(uWide, vUv).rgb * 0.15;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.82, 0.0) * 0.9);
col += (h(gl_FragCoord.xy) + h(gl_FragCoord.yx + 17.0) - 1.0) / 255.0;
o = 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];
}
type Spring = { x: number; v: number; goal: number };
const spring = (x: number): Spring => ({ x, v: 0, goal: x });
// a soft, slightly underdamped spring: glides and settles with a gentle overshoot
const step = (s: Spring, k: number, c: number, dt: number) => {
const n = Math.max(1, Math.ceil(dt / (1 / 120)));
const h = dt / n;
for (let i = 0; i < n; i++) {
s.v += ((s.goal - s.x) * k - s.v * c) * h;
s.x += s.v * h;
}
};
export function PrismSlick({
image = "/backgrounds/prism-slick/slick.jpg",
depthImage = "/backgrounds/prism-slick/depth.png",
normalImage = "/backgrounds/prism-slick/normal.jpg",
cyan = "#7ff0ff",
gold = "#ffd45a",
flow = 1,
speed = 1,
gloss = 1,
dispersion = 1,
parallax = 1,
glow = 0.45,
fit = 1,
background = "#000204",
interactive = true,
scroller,
children,
className,
}: PrismSlickProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ cyan, gold, flow, speed, gloss, dispersion, parallax, glow, fit, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { cyan, gold, flow, speed, gloss, dispersion, parallax, glow, fit, interactive };
redraw.current?.();
}, [cyan, gold, flow, speed, gloss, dispersion, parallax, glow, fit, 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;opacity:0;transition:opacity .6s ease;";
host.prepend(canvas);
const gl = canvas.getContext("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
host.style.backgroundImage = `url(${image})`;
host.style.backgroundSize = "cover";
host.style.backgroundPosition = "center";
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, [
"uImg", "uDepth", "uNrm", "uRes", "uImgSize", "uMouse", "uPar", "uSweep", "uDpr", "uScale", "uTime", "uFlow", "uHover",
"uGloss", "uDisp", "uIntro", "uLod0", "uFlash", "uSurge", "uCyan", "uGold", "uWave", "uField", "uMaxD", "uSv",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
const vbo = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
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 push field: how far each bit of liquid has been dragged, on gooey springs ----
const fieldTex = gl.createTexture()!;
let fw = 2, fh = 2;
let fdx = new Float32Array(4), fdy = new Float32Array(4), fvx = new Float32Array(4), fvy = new Float32Array(4);
let tmpx = new Float32Array(4), tmpy = new Float32Array(4);
let fbytes = new Uint8Array(16);
let fieldW = 0, fieldH = 0;
let fieldAwake = false;
const layoutField = () => {
fw = Math.max(2, Math.ceil(w / CELL));
fh = Math.max(2, Math.ceil(h / CELL));
const n = fw * fh;
fdx = new Float32Array(n);
fdy = new Float32Array(n);
fvx = new Float32Array(n);
fvy = new Float32Array(n);
tmpx = new Float32Array(n);
tmpy = new Float32Array(n);
fbytes = new Uint8Array(n * 4).fill(128);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, fw, fh, 0, gl.RGBA, gl.UNSIGNED_BYTE, fbytes);
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);
};
const uploadField = () => {
for (let i = 0, n = fw * fh; i < n; i++) {
const x = Math.max(-1, Math.min(1, fdx[i] / MAXD)), y = Math.max(-1, Math.min(1, fdy[i] / MAXD));
fbytes[i * 4] = Math.round((x * 0.5 + 0.5) * 255);
fbytes[i * 4 + 1] = Math.round((y * 0.5 + 0.5) * 255);
fbytes[i * 4 + 2] = Math.round(Math.min(1, Math.hypot(x, y) * 1.6 + Math.hypot(fvx[i], fvy[i]) / 900) * 255);
fbytes[i * 4 + 3] = 255;
}
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, fw, fh, gl.RGBA, gl.UNSIGNED_BYTE, fbytes);
};
// push the liquid around a point: along a direction, or outward (amount < 0 pulls inward), with a twist
const push = (x: number, y: number, R: number, amount: number, dirX: number, dirY: number, radial = false, twist = 0) => {
const cx = x / CELL, cy = y / CELL, rr = R / CELL;
const x0 = Math.max(0, Math.floor(cx - rr)), x1 = Math.min(fw - 1, Math.ceil(cx + rr));
const y0 = Math.max(0, Math.floor(cy - rr)), y1 = Math.min(fh - 1, Math.ceil(cy + rr));
for (let j = y0; j <= y1; j++)
for (let i = x0; i <= x1; i++) {
const ox = i + 0.5 - cx, oy = j + 0.5 - cy;
const d = Math.hypot(ox, oy) / rr;
if (d >= 1) continue;
const wgt = (1 - d * d) * (1 - d * d);
let ux = dirX, uy = dirY;
if (radial) {
const l = Math.hypot(ox, oy) || 1;
ux = ox / l;
uy = oy / l;
}
const k = j * fw + i;
fvx[k] += (ux * amount - uy * twist) * wgt;
fvy[k] += (uy * amount + ux * twist) * wgt;
}
fieldAwake = true;
};
const stepField = (dt: number) => {
if (!fieldAwake) return;
const sub = Math.max(1, Math.ceil(dt / (1 / 120)));
const hs = dt / sub;
let energy = 0;
const n = fw * fh;
for (let it = 0; it < sub; it++) {
// gooey springs: thick liquid metal wobbles back into place
for (let i = 0; i < n; i++) {
fvx[i] += (-34 * fdx[i] - 4.2 * fvx[i]) * hs;
fvy[i] += (-34 * fdy[i] - 4.2 * fvy[i]) * hs;
fdx[i] += fvx[i] * hs;
fdy[i] += fvy[i] * hs;
}
}
// and spreads a little into its neighbours, like a liquid
for (let j = 0; j < fh; j++)
for (let i = 0; i < fw; i++) {
const k = j * fw + i;
const l = i > 0 ? k - 1 : k, r = i < fw - 1 ? k + 1 : k, u = j > 0 ? k - fw : k, d = j < fh - 1 ? k + fw : k;
tmpx[k] = fdx[k] * 0.84 + (fdx[l] + fdx[r] + fdx[u] + fdx[d]) * 0.04;
tmpy[k] = fdy[k] * 0.84 + (fdy[l] + fdy[r] + fdy[u] + fdy[d]) * 0.04;
}
for (let i = 0; i < n; i++) {
fdx[i] = tmpx[i];
fdy[i] = tmpy[i];
energy += Math.abs(fdx[i]) + Math.abs(fdy[i]) + Math.abs(fvx[i]) * 0.02 + Math.abs(fvy[i]) * 0.02;
}
if (energy < 0.05 * n * 0.01) {
fdx.fill(0);
fdy.fill(0);
fvx.fill(0);
fvy.fill(0);
fieldAwake = false;
}
};
let w = 1, h = 1, dpr = 1, rs = 1;
const resize = () => {
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);
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 (w !== fieldW || h !== fieldH) {
fieldW = w;
fieldH = h;
layoutField();
}
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, flash: 0, surge: 0, sv: 0 };
const px = spring(0), py = spring(0);
let flow = 0;
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
const imgTex = gl.createTexture()!;
const depTex = gl.createTexture()!;
const nrmTex = gl.createTexture()!;
let imgW = 1, imgH = 1, ready = 0;
let disposed = false;
// cover the stage (with a little overscan for the flow and parallax)
const scaleOf = () => Math.max(h / imgH, (w * Math.max(0.3, props.current.fit)) / imgW) * 1.06;
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 || ready < 3) return;
const p = props.current;
const X = T;
const minD = Math.min(w, h);
const sc = scaleOf();
const sceneScale = X.scene.w / canvas.width;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
[imgTex, depTex, nrmTex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(US.uImg, 0);
gl.uniform1i(US.uDepth, 1);
gl.uniform1i(US.uNrm, 2);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uImgSize, imgW, imgH);
gl.uniform2f(US.uMouse, s.mx, s.my);
const par = minD * 0.03 * Math.max(0, p.parallax);
gl.uniform2f(US.uPar, px.x * par, py.x * par);
// a soft light travels slowly across the liquid
gl.uniform2f(US.uSweep, w * (0.5 + 0.55 * Math.sin(flow * 0.17)), h * (0.5 + 0.45 * Math.sin(flow * 0.23 + 1.1)));
gl.uniform1f(US.uDpr, dpr * sceneScale);
gl.uniform1f(US.uScale, sc);
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uFlow, still ? 0 : Math.max(0, p.flow) * (1 + s.surge * 1.5 + Math.min(1.5, Math.abs(s.sv))));
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uGloss, Math.max(0, p.gloss));
gl.uniform1f(US.uDisp, Math.max(0, p.dispersion));
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uLod0, Math.max(0, Math.log2(1 / (sc * dpr * sceneScale))));
gl.uniform1f(US.uFlash, s.flash);
gl.uniform1f(US.uSurge, s.surge);
gl.uniform3fv(US.uCyan, rgb(p.cyan));
gl.uniform3fv(US.uGold, rgb(p.gold));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
uploadField();
gl.activeTexture(gl.TEXTURE3);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.uniform1i(US.uField, 3);
gl.uniform1f(US.uMaxD, MAXD);
gl.uniform1f(US.uSv, still ? 0 : s.sv);
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));
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
// ---- cursor: parallax by depth, a liquid lens, a lamp in prism colours ----
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.8, ease: "sine.inOut" });
let first = true;
let last = { x: 0, y: 0, t: 0 };
// press and hold: a gravity well
let holding = false;
let holdAt = { 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 (still || !props.current.interactive) return;
const p = local(e);
const now = performance.now();
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
last = { x: p.x, y: p.y, t: now };
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
px.goal = (p.x / w) * 2 - 1;
py.goal = (p.y / h) * 2 - 1;
if (holding) holdAt = p;
// drag the liquid along your stroke: the faster you move, the further it smears
const dx = p.x - last.x, dy = p.y - last.y;
const len = Math.hypot(dx, dy);
if (len > 0.5) {
const v = Math.min(4, len / Math.max(8, now - last.t)); // px per ms
const steps = Math.max(1, Math.ceil(len / 20));
for (let k = 1; k <= steps; k++)
push(last.x + (dx * k) / steps, last.y + (dy * k) / steps, 95, ((140 + v * 380) / steps) * props.current.flow, dx / len, dy / len);
}
last = { x: p.x, y: p.y, t: now };
};
const leave = () => {
first = true;
hoverTo(0);
px.goal = 0;
py.goal = 0;
};
// ---- click: ripples roll out through the liquid ----
const down = (e: PointerEvent) => {
if (still || !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();
// a droplet hits: the liquid craters outward and wobbles back
push(p.x, p.y, 180, 650, 0, 0, true);
holding = true;
holdAt = p;
gsap.killTweensOf(s, "flash,surge");
gsap.timeline().to(s, { flash: 1, duration: 0.2, ease: "sine.out" }).to(s, { flash: 0, duration: 1.2, ease: "sine.inOut" });
gsap.timeline().to(s, { surge: 1, duration: 0.3, ease: "power2.out" }).to(s, { surge: 0, duration: 1.8, ease: "power2.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// let go: the well collapses and the liquid splashes back
const up = () => {
if (!holding) return;
holding = false;
waves.push({ x: holdAt.x, y: holdAt.y, t: flow, s: 0.8 });
if (waves.length > MAXW) waves.shift();
push(holdAt.x, holdAt.y, 200, 500, 0, 0, true);
};
window.addEventListener("pointerup", up);
window.addEventListener("pointercancel", up);
// ---- scroll: the liquid flows faster with scroll speed ----
const svTo = gsap.quickTo(s, "sv", { duration: 0.5, ease: "power2.out" });
let svIdle: gsap.core.Tween | null = null;
const st = still
? null
: ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
if (!props.current.interactive) return;
svTo(Math.max(-2, Math.min(2, self.getVelocity() / 1500)));
svIdle?.kill();
svIdle = gsap.delayedCall(0.15, () => svTo(0));
},
});
// ---- loop ----
let visible = true;
let prev = performance.now();
let slow = 0;
let intro: gsap.core.Tween | null = null;
const tick = () => {
const t = performance.now();
const rawDt = (t - prev) / 1000;
const dt = Math.min(0.05, rawDt);
prev = t;
if (!visible || ready < 3) return;
const p = props.current;
flow += dt * Math.max(0, p.speed) * (1 + s.surge * 1.2 + Math.abs(s.sv) * 0.8);
step(px, 12, 5.5, dt);
step(py, 12, 5.5, dt);
// holding: the liquid is drawn into a swirling well under your hand
if (holding && props.current.interactive) push(holdAt.x, holdAt.y, 230, -1500 * dt * props.current.flow, 0, 0, true, 900 * dt);
stepField(dt);
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 3.1) waves.splice(i, 1);
slow = slow * 0.97 + (rawDt > 1 / 45 ? 0.03 : 0);
if (slow > 0.5 && rs === 1) {
rs = 0.8;
resize();
}
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
const start = () => {
canvas.style.opacity = "1";
if (still) {
draw();
redraw.current = draw;
return;
}
intro = gsap.to(s, { intro: 1, duration: 2.4, ease: "power2.inOut", delay: 0.05 });
prev = performance.now();
io.observe(host);
gsap.ticker.add(tick);
};
const load = (src: string, tex: WebGLTexture, onSize?: (iw: number, ih: number) => void) => {
const im = new Image();
im.crossOrigin = "anonymous";
im.decoding = "async";
im.onload = () => {
if (disposed) return;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, im);
// past the photo's edges the liquid continues as its own mirror image
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
onSize?.(im.naturalWidth, im.naturalHeight);
ready++;
if (ready === 3) start();
};
im.src = src;
};
load(image, imgTex, (iw, ih) => {
imgW = iw;
imgH = ih;
});
load(depthImage, depTex);
load(normalImage, nrmTex);
return () => {
disposed = true;
redraw.current = null;
gsap.ticker.remove(tick);
intro?.kill();
st?.kill();
svIdle?.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
window.removeEventListener("pointerup", up);
window.removeEventListener("pointercancel", up);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(imgTex);
gl.deleteTexture(depTex);
gl.deleteTexture(nrmTex);
gl.deleteTexture(fieldTex);
gl.deleteProgram(sceneProg);
gl.deleteProgram(blurProg);
gl.deleteProgram(brightProg);
gl.deleteProgram(compProg);
gl.deleteBuffer(vbo);
gl.deleteVertexArray(vao);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [image, depthImage, normalImage, 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 PrismSlick;
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
17 propsimagestringThe photo.default "/backgrounds/prism-slick/slick.jpg"default "/backgrounds/prism-slick/slick.jpg"depthImagestringIts depth map, white = near (parallax and the breathing).default "/backgrounds/prism-slick/depth.png"default "/backgrounds/prism-slick/depth.png"normalImagestringIts normal map (tangent space, +Y up), for the light.default "/backgrounds/prism-slick/normal.jpg"default "/backgrounds/prism-slick/normal.jpg"cyanstringThe cool light colour.default "#7ff0ff"default "#7ff0ff"goldstringThe warm light colour.default "#ffd45a"default "#ffd45a"flownumberHow much the liquid breathes and flows.default 1default 1speednumberSpeed of all the motion.default 1default 1glossnumberStrength of the light raking the relief.default 1default 1dispersionnumberStrength of the prism fringes on that light.default 1default 1parallaxnumberDepth parallax strength.default 1default 1glownumberStrength of the bloom on the highlights.default 0.45default 0.45fitnumberHow much of the screen width the photo spans (1 = cover); below 1 the liquid continues as a mirror image.default 1default 1backgroundstringShown while the photo loads.default "#000204"default "#000204"interactivebooleanParallax, lens and lamp at the cursor, click ripples, scroll flow.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the liquid.classNamestringSize it, e.g. h-screen w-full.