Plush Fur
A deep pelt of real 3D fur that moves only under your hand. A soft, lumpy body, like the back of a bear, seen at an angle and covered in a dense pile of slim strands that grow up out of the skin in true depth, each tapering to a fine point and lying with the coat, gathering softly into locks. The roots sit in shadow under the pile, the tips glow, and a smooth, silky sheen slides along the strands. It is perfectly still until a hand moves through it, then it moves like real fur: the strands you pass are pushed along with your stroke and part around your hand, then spring back with a soft wobble and settle, while the light follows your hand. A click sends a ruffle through the pelt.
Tweak
LIVELIVEColour
Fur
Motion
Interactive
Stroke the fur with the cursor, click to puff it up
Usage
Follows your tweaks.
import { PlushFur } from "@/components/inreact/plush-fur";
export function Hero() {
return (
<PlushFur
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the fur */}
</PlushFur>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/plush-fur.jsonOr copy the source
Install the dependencies, then save this as components/inreact/plush-fur.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { useEffect, useRef, type ReactNode } from "react";
/**
* Plush Fur: a deep pelt of real 3D fur you can run your hand through.
*
* A soft, lumpy body (like a bear's back) seen at an angle, covered in a deep,
* dense pile of slim strands. The fur is real geometry in depth: dozens of
* stacked shells grow every strand up out of the skin, each tapering to a fine
* point and lying with the coat, gathering softly into locks. The roots sit in
* shadow under the pile, the tips glow, and a smooth, silky sheen slides along
* the strands.
*
* It is perfectly still until a hand moves through it, then it moves like real
* fur: the strands you pass are pushed along with your stroke and part around
* your hand, then spring back with a soft wobble and settle. The light follows
* your hand, and a click sends a ruffle through the pelt.
*
* <PlushFur className="h-screen w-full">
* <YourHero />
* </PlushFur>
*
* WebGL2: shell-rendered fur (one instanced draw of 52 displaced shells over a
* tessellated skin, strands alpha-tested per shell), a perspective camera, hair
* (Kajiya-Kay) lighting, then a bloom at 1/4 and 1/16 size. The hand's wake is
* a grid of springs simulated in JS. Adaptive resolution keeps 60fps. Pauses
* off-screen; reduced motion shows a still frame; a CSS gradient without
* WebGL2.
*/
export interface PlushFurProps {
/** Colour of the tips (the brightest strands). */
tip?: string;
/** Colour of the body of the fur. */
color?: string;
/** Colour deep at the roots. */
root?: string;
/** Colour of the sheen and the cursor's light. */
sheen?: string;
/** Length of the fur. */
length?: number;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** How quickly the fur springs back after the hand passes. */
speed?: number;
/** Strength of the bloom on the tips. */
glow?: number;
/** The fur reacts to a hand moving through it. */
interactive?: boolean;
/** Foreground content, drawn above the fur. */
children?: ReactNode;
className?: string;
}
const SHELLS = 52;
const GRID = 120; // skin tessellation
const MASK = 64; // combed-field resolution over the skin
const MAXW = 4;
const FUR_VS = `#version 300 es
precision highp float;
layout(location = 0) in vec2 aP; // 0..1 across the skin
uniform mat4 uVP;
uniform vec4 uExtent; // skin world rect: x0, y0, w, h
uniform float uShells, uLen, uTime, uPress, uHandR, uRuffle;
uniform vec2 uHand; // world xy under the cursor
uniform vec4 uWave[${MAXW}];
uniform sampler2D uComb; // rg: the hand's wake, a spring displacement (encoded -1..1)
out vec2 vW;
out float vH;
out vec3 vT;
out vec3 vPos;
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);
}
// the body under the fur: soft lumps, like muscle under a pelt
float bump(vec2 w) { return (noise(w * 0.8 + 3.0) * 0.65 + noise(w * 1.9 + 9.0) * 0.35) * 0.36; }
void main() {
float h = float(gl_InstanceID) / uShells; // 0 = skin, 1 = longest tips
vec2 w = uExtent.xy + aP * uExtent.zw;
float z = bump(w);
float e = 0.02;
vec3 n = normalize(vec3(-(bump(w + vec2(e, 0.0)) - z) / e, -(bump(w + vec2(0.0, e)) - z) / e, 1.0));
// the lie of the coat: a slow swirl down the body (perfectly still until a hand moves through it)
float a = (noise(w * 0.55 + 1.7) - 0.5) * 2.4 - 1.25 + (noise(w * 5.5 + 7.0) - 0.5) * 1.3;
vec2 lie = vec2(cos(a), sin(a));
// the hand's wake: strands pushed along the stroke, springing back with a soft wobble
vec2 wake = texture(uComb, aP).rg * 2.0 - 1.0;
// the hand: presses into the pile and parts the strands around it
vec2 dh = w - uHand;
float fh = exp(-dot(dh, dh) / (uHandR * uHandR)) * uPress;
vec2 part = (length(dh) > 1e-4 ? normalize(dh) : vec2(0.0)) * fh;
// click ruffle: a ring that lifts and fans the fur as it passes
float lift = 0.0;
vec2 fan = 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 > 2.4) continue;
vec2 dv = w - W.xy;
float rr = length(dv);
float band = exp(-pow((rr - age * 1.6) / 0.22, 2.0)) * exp(-age * 1.2) * W.w;
lift = max(lift, band);
fan += (rr > 1e-4 ? dv / rr : vec2(0.0)) * band;
}
// how far the strands lean over: a lot, like a long pelt; less when lifted, more when combed or pressed
float lean = 0.9 + fh * 0.4 - lift * 0.8 - uRuffle * 0.3;
vec2 bend = lie * lean + wake * 1.7 + part * 0.6 + fan * 1.0;
// the shell height: flattened under the hand
float up = 1.0 - fh * 0.15 + lift * 0.25;
float hb = pow(h, 1.5);
vec3 pos = vec3(w, z) + n * h * uLen * up + vec3(bend, 0.0) * hb * uLen * 0.9;
// strand tangent, for the hair sheen
vT = normalize(n * up + vec3(bend, 0.0) * 1.35 * pow(max(h, 0.05), 0.5));
vW = w;
vH = h;
vPos = pos;
gl_Position = uVP * vec4(pos, 1.0);
}`;
const FUR_FS = `#version 300 es
precision highp float;
in vec2 vW;
in float vH;
in vec3 vT;
in vec3 vPos;
uniform float uDensity, uClump, uTime, uFlash, uFocus;
uniform vec3 uTip, uBody, uRoot, uSheen, uCam, uLamp;
uniform vec2 uRes;
uniform float uDpr, uLampOn;
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); }
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 vnoise(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);
}
void main() {
float h = vH;
vec2 w = vW;
// which way this strand leans
vec2 lean2 = vT.xy;
float ll = length(lean2);
vec2 ld = ll > 1e-4 ? lean2 / ll : vec2(1.0, 0.0);
vec2 lp = vec2(-ld.y, ld.x);
// locks: toward the tips, strands draw together sideways (staying parallel along their length),
// so each tuft becomes a pointed lock with dark gaps beside it
// lock cells: long and narrow, laid out in one fixed frame along the coat's general lie
// (a fixed frame keeps them stable; a frame that turned with the fur would swirl into marbling)
const vec2 FD = vec2(0.315, -0.949);
const vec2 FP = vec2(0.949, 0.315);
vec2 lf = vec2(dot(w, FD), dot(w, FP)) * vec2(uClump * 0.5, uClump);
vec2 cc = floor(lf);
vec2 jit = (h22(cc + 4.0) - 0.5) * vec2(0.5, 0.7);
vec2 cl = cc + 0.5 + jit;
vec2 cw = FD * (cl.x / (uClump * 0.5)) + FP * (cl.y / uClump);
vec2 dl = cw - w;
float pull = smoothstep(0.0, 0.8, h);
// strands draw in sideways to their lock's centre, staying parallel along their own lean
vec2 ws = w + lp * dot(dl, lp) * pull * 0.68 + ld * dot(dl, ld) * pull * 0.06;
// roots far from their lock's centre line sit in the parting between locks, in shadow
float parting = smoothstep(0.25, 0.55, abs(dot(dl, lp)) * uClump);
// strands: one per cell, each with its own length and thickness
vec2 g = ws * uDensity;
vec2 id = floor(g);
vec2 f = fract(g);
vec2 r = h22(id);
// length and brightness vary smoothly across the pelt, never in squares
float len = mix(0.55, 1.0, r.x) * mix(0.65, 1.0, vnoise(lf * 0.6 + 3.0));
float tuftLit = mix(0.7, 1.12, smoothstep(0.15, 0.85, vnoise(lf * 0.5 + 7.0)));
float alive = 1.0 - step(len, h);
vec2 cen = vec2(0.5) + (r - 0.5) * 0.5;
// slim strands that taper to a fine point
float rad = 0.5 * pow(1.0 - h / len, 0.8);
// each strand is stretched along its lean, so consecutive shells overlap into one continuous hair
float stretch = 1.0 + 1.6 * ll / max(vT.z, 0.25);
vec2 df = f - cen;
vec2 q = vec2(dot(df, ld) / stretch, dot(df, vec2(-ld.y, ld.x)));
float inside = step(length(q), rad);
if (h > 0.0 && (alive * inside) < 0.5) discard;
float t = h / max(len, 1e-3);
// colour along the strand: dark root, rich body, glowing tip
vec3 col = mix(uRoot, uBody, smoothstep(0.08, 0.55, t));
col = mix(col, uTip, smoothstep(0.45, 0.95, t) * mix(0.6, 1.0, r.y));
col += uTip * smoothstep(0.75, 1.0, t) * 0.55 * r.y;
col *= tuftLit;
// self-shadowing: deep in the pile very little light reaches
float ao = mix(0.03, 1.0, pow(h, 1.3)) * mix(1.0, 0.5, parting * (1.0 - smoothstep(0.3, 0.9, h)));
// hair sheen (Kajiya-Kay) from a key light and the cursor's lamp
vec3 V = normalize(uCam - vPos);
vec3 Lk = normalize(vec3(-0.5, 0.65, 0.9));
vec3 Ll = normalize(uLamp - vPos);
vec3 T = normalize(vT);
float tl = dot(T, Lk);
float diff = sqrt(max(1.0 - tl * tl, 0.0));
vec3 Hk = normalize(Lk + V);
float th = dot(T, Hk);
float sinTH = sqrt(max(1.0 - th * th, 0.0));
// a bright, smooth primary highlight and a softer, tinted secondary one: a silky coat
float spec = pow(sinTH, 30.0);
vec3 T2 = normalize(T + vec3(0.0, 0.0, 0.35));
float th2 = dot(T2, Hk);
float spec2 = pow(sqrt(max(1.0 - th2 * th2, 0.0)), 14.0);
vec3 Hl = normalize(Ll + V);
float thl = dot(T, Hl);
float specL = pow(sqrt(max(1.0 - thl * thl, 0.0)), 90.0) * uLampOn / (1.0 + dot(uLamp - vPos, uLamp - vPos) * 1.5);
col *= ao * (0.16 + 0.82 * diff * diff);
col += uSheen * (spec * 1.5 + specL * 0.8) * t * ao + uTip * spec2 * 0.35 * t * ao;
col += uTip * uFlash * 0.2 * t;
// a calm centre for headlines
vec2 sp = gl_FragCoord.xy / uDpr / uRes - 0.5;
col *= 1.0 - uFocus * 0.65 * exp(-dot(sp * vec2(2.0, 2.6), sp * vec2(2.0, 2.6)) / 0.3);
o = vec4(col, 1.0);
}`;
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 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.55, 1.05, 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];
}
// ---- tiny matrix helpers (column-major, like WebGL expects) ----
type V3 = [number, number, number];
const sub = (a: V3, b: V3): V3 => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
const cross = (a: V3, b: V3): V3 => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
const norm = (a: V3): V3 => {
const l = Math.hypot(a[0], a[1], a[2]) || 1;
return [a[0] / l, a[1] / l, a[2] / l];
};
const dot3 = (a: V3, b: V3) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
function perspective(fovy: number, aspect: number, near: number, far: number) {
const f = 1 / Math.tan(fovy / 2), nf = 1 / (near - far);
return new Float32Array([f / aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, (far + near) * nf, -1, 0, 0, 2 * far * near * nf, 0]);
}
function lookAt(eye: V3, at: V3, up: V3) {
const z = norm(sub(eye, at)), x = norm(cross(up, z)), y = cross(z, x);
return new Float32Array([x[0], y[0], z[0], 0, x[1], y[1], z[1], 0, x[2], y[2], z[2], 0, -dot3(x, eye), -dot3(y, eye), -dot3(z, eye), 1]);
}
function mul(a: Float32Array, b: Float32Array) {
const o = new Float32Array(16);
for (let i = 0; i < 4; i++)
for (let j = 0; j < 4; j++) {
let s = 0;
for (let k = 0; k < 4; k++) s += a[k * 4 + j] * b[i * 4 + k];
o[i * 4 + j] = s;
}
return o;
}
function invert(a: Float32Array) {
const o = new Float32Array(16);
const b00 = a[0] * a[5] - a[1] * a[4], b01 = a[0] * a[6] - a[2] * a[4], b02 = a[0] * a[7] - a[3] * a[4];
const b03 = a[1] * a[6] - a[2] * a[5], b04 = a[1] * a[7] - a[3] * a[5], b05 = a[2] * a[7] - a[3] * a[6];
const b06 = a[8] * a[13] - a[9] * a[12], b07 = a[8] * a[14] - a[10] * a[12], b08 = a[8] * a[15] - a[11] * a[12];
const b09 = a[9] * a[14] - a[10] * a[13], b10 = a[9] * a[15] - a[11] * a[13], b11 = a[10] * a[15] - a[11] * a[14];
const det = 1 / (b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06);
o[0] = (a[5] * b11 - a[6] * b10 + a[7] * b09) * det;
o[1] = (a[2] * b10 - a[1] * b11 - a[3] * b09) * det;
o[2] = (a[13] * b05 - a[14] * b04 + a[15] * b03) * det;
o[3] = (a[10] * b04 - a[9] * b05 - a[11] * b03) * det;
o[4] = (a[6] * b08 - a[4] * b11 - a[7] * b07) * det;
o[5] = (a[0] * b11 - a[2] * b08 + a[3] * b07) * det;
o[6] = (a[14] * b02 - a[12] * b05 - a[15] * b01) * det;
o[7] = (a[8] * b05 - a[10] * b02 + a[11] * b01) * det;
o[8] = (a[4] * b10 - a[5] * b08 + a[7] * b06) * det;
o[9] = (a[1] * b08 - a[0] * b10 - a[3] * b06) * det;
o[10] = (a[12] * b04 - a[13] * b02 + a[15] * b00) * det;
o[11] = (a[9] * b02 - a[8] * b04 - a[11] * b00) * det;
o[12] = (a[5] * b07 - a[4] * b09 - a[6] * b06) * det;
o[13] = (a[0] * b09 - a[1] * b07 + a[2] * b06) * det;
o[14] = (a[13] * b01 - a[12] * b03 - a[14] * b00) * det;
o[15] = (a[8] * b03 - a[9] * b01 + a[10] * b00) * det;
return o;
}
export function PlushFur({
tip = "#f08cf0",
color = "#8a2a8c",
root = "#140314",
sheen = "#ff8cf2",
length = 1,
focus = 0.15,
speed = 1,
glow = 0.5,
interactive = true,
children,
className,
}: PlushFurProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ tip, color, root, sheen, length, focus, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { tip, color, root, sheen, length, focus, speed, glow, interactive };
redraw.current?.();
}, [tip, color, root, sheen, length, 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 = `radial-gradient(60% 50% at 30% 30%, ${p.color}aa, transparent 70%), radial-gradient(60% 50% at 75% 70%, ${p.color}66, transparent 70%), ${p.root}`;
canvas.remove();
return;
}
const build = (vs: string, fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, vs],
[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 furProg = build(FUR_VS, FUR_FS);
const blurProg = build(QUAD, BLUR);
const brightProg = build(QUAD, BRIGHT);
const compProg = build(QUAD, COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const UF = uni(furProg, [
"uVP", "uExtent", "uShells", "uLen", "uTime", "uPress", "uHandR", "uRuffle", "uHand", "uWave", "uComb",
"uDensity", "uClump", "uFlash", "uFocus", "uTip", "uBody", "uRoot", "uSheen", "uCam", "uLamp", "uRes", "uDpr", "uLampOn",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
// fullscreen triangle for the post passes
const fsVao = gl.createVertexArray();
gl.bindVertexArray(fsVao);
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.bindVertexArray(fsVao);
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
// the skin: a tessellated grid, drawn once per shell (instanced)
const skinVao = gl.createVertexArray();
gl.bindVertexArray(skinVao);
{
const verts = new Float32Array((GRID + 1) * (GRID + 1) * 2);
for (let j = 0; j <= GRID; j++) for (let i = 0; i <= GRID; i++) verts.set([i / GRID, j / GRID], (j * (GRID + 1) + i) * 2);
const idx = new Uint32Array(GRID * GRID * 6);
let k = 0;
for (let j = 0; j < GRID; j++)
for (let i = 0; i < GRID; i++) {
const a = j * (GRID + 1) + i, b = a + 1, c = a + GRID + 1, d = c + 1;
idx.set([a, c, b, b, c, d], k);
k += 6;
}
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, idx, gl.STATIC_DRAW);
}
gl.bindVertexArray(null);
const INDEX_COUNT = GRID * GRID * 6;
// ---- the hand's wake over the skin: a displacement per cell, each an underdamped spring ----
const combTex = gl.createTexture()!;
const wx = new Float32Array(MASK * MASK), wy = new Float32Array(MASK * MASK), vx = new Float32Array(MASK * MASK), vy = new Float32Array(MASK * MASK);
const combBytes = new Uint8Array(MASK * MASK * 4).fill(128);
gl.bindTexture(gl.TEXTURE_2D, combTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, MASK, MASK, 0, gl.RGBA, gl.UNSIGNED_BYTE, combBytes);
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);
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number; depth?: WebGLRenderbuffer };
const target = (tw: number, th: number, withDepth = false): 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);
let depth: WebGLRenderbuffer | undefined;
if (withDepth) {
depth = gl.createRenderbuffer()!;
gl.bindRenderbuffer(gl.RENDERBUFFER, depth);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, tw, th);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depth);
}
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th, depth };
};
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);
if (t.depth) gl.deleteRenderbuffer(t.depth);
}
T = null;
};
let w = 1, h = 1, dpr = 1, rs = 1;
// camera and the patch of skin it sees
const eye: V3 = [0, -1.05, 2.45];
const at: V3 = [0, 0.2, 0];
let camPos: V3 = eye;
let vp = new Float32Array(16), inv = new Float32Array(16);
const extent = [-2, -2, 4, 4];
let pxPerUnit = 400;
// where a screen point (css px) lands on the skin plane z = 0.1
const toSkin = (x: number, y: number): [number, number] | null => {
const nx = (x / w) * 2 - 1, ny = 1 - (y / h) * 2;
const pt = (z: number) => {
const v = [nx, ny, z, 1];
const r = [0, 0, 0, 0];
for (let i = 0; i < 4; i++) r[i] = inv[i] * v[0] + inv[4 + i] * v[1] + inv[8 + i] * v[2] + inv[12 + i] * v[3];
return [r[0] / r[3], r[1] / r[3], r[2] / r[3]];
};
const a = pt(-1), b = pt(1);
const dz = b[2] - a[2];
if (Math.abs(dz) < 1e-6) return null;
const tt = (0.1 - a[2]) / dz;
return [a[0] + (b[0] - a[0]) * tt, a[1] + (b[1] - a[1]) * tt];
};
const setCamera = (tilt: number) => {
const aspect = w / h;
const e: V3 = [eye[0], eye[1] - tilt * 0.25, eye[2] + tilt * 0.1];
const proj = perspective((38 * Math.PI) / 180, aspect, 0.05, 20);
const view = lookAt(e, at, [0, 0, 1]);
vp = mul(proj, view);
inv = invert(vp);
camPos = e;
// the skin patch covers everything the camera sees, with a margin
const corners = [[0, 0], [w, 0], [0, h], [w, h]].map(([x, y]) => toSkin(x, y)).filter(Boolean) as [number, number][];
if (corners.length === 4) {
const xs = corners.map((c) => c[0]), ys = corners.map((c) => c[1]);
const x0 = Math.min(...xs) - 0.4, x1 = Math.max(...xs) + 0.4, y0 = Math.min(...ys) - 0.4, y1 = Math.max(...ys) + 0.4;
extent[0] = x0;
extent[1] = y0;
extent[2] = x1 - x0;
extent[3] = y1 - y0;
}
// pixels per world unit at the centre of the view, so strands stay ~3px wide on any screen
const c0 = toSkin(w / 2, h / 2), c1 = toSkin(w / 2 + 100, h / 2);
if (c0 && c1) pxPerUnit = 100 / Math.hypot(c1[0] - c0[0], c1[1] - c0[1]);
};
const s = { grow: 1, hx: 0, hy: 0, press: 0, hover: 0, flash: 0, ruffle: 0, tilt: 0, lampX: 0, lampY: 0 };
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, true),
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)),
};
setCamera(s.tilt);
};
resize();
let flow = still ? 4 : 0;
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
// a hand moving through the fur pushes the strands it passes along with it
const comb = (x0: number, y0: number, x1: number, y1: number) => {
const len = Math.hypot(x1 - x0, y1 - y0);
if (len < 1e-5) return;
// how hard the stroke pushes, from how far the hand moved this event
const push = Math.min(1.2, len * 9);
const ux = (x1 - x0) / len, uy = (y1 - y0) / len;
const R = 0.24;
const steps = Math.max(1, Math.ceil(len / (R * 0.3)));
for (let k = 1; k <= steps; k++) {
const x = x0 + ((x1 - x0) * k) / steps, y = y0 + ((y1 - y0) * k) / steps;
const mx = ((x - extent[0]) / extent[2]) * MASK, my = ((y - extent[1]) / extent[3]) * MASK;
const rr = (R / extent[2]) * MASK;
const minx = Math.max(0, Math.floor(mx - rr)), maxx = Math.min(MASK - 1, Math.ceil(mx + rr));
const miny = Math.max(0, Math.floor(my - rr)), maxy = Math.min(MASK - 1, Math.ceil(my + rr));
for (let j = miny; j <= maxy; j++)
for (let i = minx; i <= maxx; i++) {
const d = Math.hypot(i + 0.5 - mx, j + 0.5 - my) / rr;
if (d >= 1) continue;
const wgt = (1 - d * d) * (1 - d * d) / steps;
const idx = j * MASK + i;
// pushed along the stroke, and a little out to the side of the hand
const ox = (i + 0.5 - mx) / Math.max(rr, 1e-3), oy = (j + 0.5 - my) / Math.max(rr, 1e-3);
vx[idx] += (ux * 9 + ox * 2.5) * push * wgt;
vy[idx] += (uy * 9 + oy * 2.5) * push * wgt;
}
}
};
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;
for (let i = 0; i < MASK * MASK; i++) {
combBytes[i * 4] = Math.round(Math.max(0, Math.min(1, wx[i] * 0.5 + 0.5)) * 255);
combBytes[i * 4 + 1] = Math.round(Math.max(0, Math.min(1, wy[i] * 0.5 + 0.5)) * 255);
combBytes[i * 4 + 2] = 0;
combBytes[i * 4 + 3] = 255;
}
gl.bindTexture(gl.TEXTURE_2D, combTex);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, MASK, MASK, gl.RGBA, gl.UNSIGNED_BYTE, combBytes);
const rootC = rgb(p.root);
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.clearColor(rootC[0] * 0.5, rootC[1] * 0.5, rootC[2] * 0.5, 1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.useProgram(furProg);
gl.uniformMatrix4fv(UF.uVP, false, vp);
gl.uniform4f(UF.uExtent, extent[0], extent[1], extent[2], extent[3]);
gl.uniform1f(UF.uShells, SHELLS);
// slim strands: one per ~1.7px at the centre of the view, so the coat is dense; locks ~30 strands across
const density = pxPerUnit / 2.0;
gl.uniform1f(UF.uDensity, density);
gl.uniform1f(UF.uClump, density / 30);
gl.uniform1f(UF.uLen, 0.22 * Math.max(0.2, p.length) * s.grow);
gl.uniform1f(UF.uTime, flow);
gl.uniform1f(UF.uPress, s.press);
gl.uniform1f(UF.uHandR, 0.22);
gl.uniform1f(UF.uRuffle, s.ruffle);
gl.uniform2f(UF.uHand, s.hx, s.hy);
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(UF.uWave, waveBuf);
gl.uniform1f(UF.uFlash, s.flash);
gl.uniform1f(UF.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform3fv(UF.uTip, rgb(p.tip));
gl.uniform3fv(UF.uBody, rgb(p.color));
gl.uniform3fv(UF.uRoot, rootC);
gl.uniform3fv(UF.uSheen, rgb(p.sheen));
gl.uniform3f(UF.uCam, camPos[0], camPos[1], camPos[2]);
gl.uniform3f(UF.uLamp, s.lampX, s.lampY, 0.55);
gl.uniform1f(UF.uLampOn, s.hover);
gl.uniform2f(UF.uRes, w, h);
gl.uniform1f(UF.uDpr, dpr * (X.scene.w / canvas.width));
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, combTex);
gl.uniform1i(UF.uComb, 0);
gl.bindVertexArray(skinVao);
gl.drawElementsInstanced(gl.TRIANGLES, INDEX_COUNT, gl.UNSIGNED_INT, 0, SHELLS + 1);
gl.bindVertexArray(null);
gl.disable(gl.DEPTH_TEST);
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));
gl.uniform1f(UC.uTime, flow);
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();
gl.deleteTexture(combTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- the hand: press, part and comb; the light follows ----
const hxTo = gsap.quickTo(s, "hx", { duration: 0.35, ease: "power3" });
const hyTo = gsap.quickTo(s, "hy", { duration: 0.35, ease: "power3" });
const lxTo = gsap.quickTo(s, "lampX", { duration: 0.8, ease: "power3" });
const lyTo = gsap.quickTo(s, "lampY", { duration: 0.8, ease: "power3" });
const pressTo = gsap.quickTo(s, "press", { duration: 0.6, ease: "power2.out" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.9, ease: "sine.inOut" });
let last: [number, number] | null = null;
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 wp = toSkin(p.x, p.y);
if (!wp) return;
if (!last) gsap.set(s, { hx: wp[0], hy: wp[1], lampX: wp[0], lampY: wp[1] });
hxTo(wp[0]);
hyTo(wp[1]);
lxTo(wp[0]);
lyTo(wp[1]);
pressTo(1);
hoverTo(1);
if (last) comb(last[0], last[1], wp[0], wp[1]);
last = wp;
};
const leave = () => {
last = null;
pressTo(0);
hoverTo(0);
};
// ---- click: a ruffle through the pelt ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const wp = toSkin(p.x, p.y);
if (!wp) return;
waves.push({ x: wp[0], y: wp[1], t: flow, s: 1 });
if (waves.length > MAXW) waves.shift();
gsap.killTweensOf(s, "flash,ruffle");
gsap.timeline().to(s, { flash: 1, ruffle: 1, duration: 0.3, ease: "sine.out" }).to(s, { flash: 0, ruffle: 0, duration: 1.4, ease: "sine.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- loop ----
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;
slow = slow * 0.95 + (dt > 0.0175 ? 0.05 : 0);
if (t - lastScale > 1200) {
if (slow > 0.35 && rs > 0.7) {
rs = Math.max(0.68, 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();
}
}
flow += dt;
// the wake springs back like real fur: an underdamped spring per cell, so it settles with a soft wobble
const K = 38 / Math.max(0.3, P.speed), C = 4.2;
for (let i = 0; i < wx.length; i++) {
if (wx[i] === 0 && wy[i] === 0 && vx[i] === 0 && vy[i] === 0) continue;
vx[i] += (-K * wx[i] - C * vx[i]) * dt;
vy[i] += (-K * wy[i] - C * vy[i]) * dt;
wx[i] += vx[i] * dt;
wy[i] += vy[i] * dt;
if (Math.abs(wx[i]) + Math.abs(wy[i]) + Math.abs(vx[i]) + Math.abs(vy[i]) < 1e-4) wx[i] = wy[i] = vx[i] = vy[i] = 0;
}
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 2.5) 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);
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(combTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, []);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background: root }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
export default PlushFur;
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 propstipstringColour of the tips (the brightest strands).default "#f08cf0"default "#f08cf0"colorstringColour of the body of the fur.default "#8a2a8c"default "#8a2a8c"rootstringColour deep at the roots.default "#140314"default "#140314"sheenstringColour of the sheen and the cursor's light.default "#ff8cf2"default "#ff8cf2"lengthnumberLength of the fur.default 1default 1focusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.15default 0.15speednumberHow quickly the fur springs back after the hand passes.default 1default 1glownumberStrength of the bloom on the tips.default 0.5default 0.5interactivebooleanThe fur reacts to a hand moving through it.default truedefault truechildrenReactNodeForeground content, drawn above the fur.classNamestringSize it, e.g. h-screen w-full.