Serpent Skin
Dark emerald python scales that glide past, catch the light and bristle under your hand. A real photograph of the skin, made seamless so it slides on forever, with a normal map of every scale so the light is real: each scale is a small glossy dome that catches a sheen as light passes over it, with a faint iridescence like the real thing. Idle, the skin glides slowly past with a sinuous slither while a soft light orbits across it. The cursor is a lamp raking across the scales, which lift gently toward it; a click sends a ripple through the skin that makes the scales bristle and flash, scrolling slides the skin with you, and on load a sheen sweeps across and reveals it. Rotate the hue to make it any colour.
Tweak
LIVELIVEColour
Skin
Motion
Interactive
Light the scales with the cursor, click to make them bristle
Usage
Follows your tweaks.
import { SerpentSkin } from "@/components/inreact/serpent-skin";
export function Hero() {
return (
<SerpentSkin
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the skin */}
</SerpentSkin>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/serpent-skin.jsonOr copy the source
Install the dependencies, then save this as components/inreact/serpent-skin.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);
/**
* Serpent Skin: dark emerald python scales that glide past, catch the light
* and bristle under your hand.
*
* A real photograph of the skin, made seamless so it can slide forever, with
* a normal map of every scale so the light is real: each scale is a small
* glossy dome that catches a sheen as the light passes over it, with a faint
* iridescence like the real thing. Idle, the skin glides slowly past with a
* sinuous slither, and a soft light orbits across it so glints travel over
* the scales.
*
* It reacts: the cursor is a light raking across the scales, which lift
* gently toward it. A click sends a ripple through the skin that makes the
* scales bristle and flash, scrolling slides the skin with you, and on load a
* sheen sweeps across and reveals it.
*
* <SerpentSkin className="h-screen w-full">
* <YourHero />
* </SerpentSkin>
*
* Bring your own texture with `image` (seamless vertically) and `normalImage`.
* 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 SerpentSkinProps {
/** The skin photo, seamless top to bottom. */
image?: string;
/** Its normal map (tangent space, +Y up). */
normalImage?: string;
/** Rotates the skin's hue, in degrees (0 = emerald). */
hue?: number;
/** Sheen colours: the highlight, and its iridescent shift. */
sheen?: string;
iridescence?: string;
/** Size of the scales (1 = as photographed at full height). */
scale?: number;
/** Strength of the light on the scales. */
gloss?: number;
/** Speed of the glide and slither. */
speed?: number;
/** Strength of the sinuous slither. */
slither?: number;
/** Strength of the bloom on the glints. */
glow?: number;
/** Background shown while the photo loads. */
background?: string;
/** Cursor light and lift, click ripple, scroll glide. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the skin. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const MASK = 14; // css px per cell of the brushed-scales field
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, uNrm, uField;
uniform vec2 uRes, uImgSize, uMouse, uOrbit; // css px
uniform float uDpr, uScale, uTime, uGlide, uSlither, uHover, uGloss, uHue, uIntro, uFlash, uLod0, uScrollLift, uSpineY;
uniform vec3 uSheen, uIri;
uniform vec4 uWave[${MAXW}];
in vec2 vUv;
out vec4 o;
// rotate hue around the grey axis, keeping brightness
vec3 hueRotate(vec3 c, float a) {
const vec3 k = vec3(0.57735);
float ca = cos(a);
return c * ca + cross(k, c) * sin(a) + k * dot(k, c) * (1.0 - ca);
}
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;
// screen -> skin px: the spine runs down the middle; the skin glides down forever
vec2 sp = (p - c) / uScale;
// the slither: a slow S-wave travels down the body
float ph = sp.y / uImgSize.y * 6.2831 * 1.2 - uTime * 0.9;
sp.x += sin(ph) * uSlither * uImgSize.x * 0.012;
// the scales lift gently toward the cursor
vec2 dm = p - uMouse;
float near = exp(-dot(dm, dm) / (0.05 * minD * minD)) * uHover;
sp -= dm / uScale * near * 0.05;
// the scales your hand has brushed: how far each is flipped up (springing back), and which way
vec4 fld = texture(uField, p / uRes);
float lift = fld.r * 2.0 - 1.0;
vec2 fdir = fld.gb * 2.0 - 1.0;
float flen = length(fdir);
fdir = flen > 1e-3 ? fdir / flen : vec2(0.0, 1.0);
lift += uScrollLift;
float al = min(abs(lift), 1.0);
sp -= fdir * lift * 5.0 / uScale;
// click: a ripple runs through the skin and the scales bristle
float rip = 0.0;
vec2 ripDir = 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.6) continue;
vec2 dw = p - W.xy;
float rr = length(dw) / minD;
float fr = rr - age * 0.6;
float k = exp(-fr * fr / 0.008) * exp(-age * 1.4) * W.w;
vec2 nd = normalize(dw + 1e-4);
sp += nd * k * sin(fr * 50.0) * 6.0 / uScale;
rip += k;
ripDir += nd * k;
}
vec2 uv = vec2(sp.x / uImgSize.x + 0.5, (sp.y - uGlide) / uImgSize.y + 0.5);
vec3 col = textureLod(uImg, uv, uLod0).rgb;
col = hueRotate(col, uHue);
vec3 n = textureLod(uNrm, uv, uLod0).rgb * 2.0 - 1.0;
n = normalize(vec3(n.x, -n.y, n.z * 1.4)); // to screen space (y down)
// the bristling scales tilt toward the ripple
n = normalize(n + vec3(ripDir * 0.6, 0.0));
// brushed scales flip up along the stroke
n = normalize(n + vec3(fdir * lift * 1.5, 0.0));
// light: a soft key orbiting slowly, and the cursor as a raking lamp
vec3 V = vec3(0.0, 0.0, 1.0);
vec3 Lo = normalize(vec3((uOrbit - p) / minD, 0.55));
vec3 Lm = normalize(vec3((uMouse - p) / minD, 0.3));
float orbitFall = exp(-dot((p - uOrbit) / minD, (p - uOrbit) / minD) / 0.35);
float lamp = exp(-dot(dm, dm) / (0.09 * minD * minD)) * uHover;
float so = pow(max(dot(n, normalize(Lo + V)), 0.0), 36.0) * orbitFall;
float sm = pow(max(dot(n, normalize(Lm + V)), 0.0), 48.0) * lamp;
float dm2 = max(dot(n, Lm), 0.0) * lamp;
// a glint of light runs down the spine like a pulse
vec3 Ls = normalize(vec3((vec2(c.x, uSpineY) - p) / minD, 0.4));
float spineFall = exp(-pow((p.y - uSpineY) / (0.14 * minD), 2.0)) * exp(-pow((p.x - c.x) / (0.3 * minD), 2.0));
float ss = pow(max(dot(n, normalize(Ls + V)), 0.0), 60.0) * spineFall;
// thin-film iridescence: the sheen shifts colour with the angle of each scale
float film = 0.5 + 0.5 * sin(atan(n.y, n.x) * 2.0 + dot(n.xy, n.xy) * 9.0 + uTime * 0.3);
vec3 sheen = mix(uSheen, uIri, film * 0.7);
// the body flexes with the slither: the bulge catches a little more light
float flex = 0.9 + 0.12 * cos(ph);
float bright = dot(col, vec3(0.33));
float gate = 0.4 + 0.6 * smoothstep(0.02, 0.12, bright);
float top = smoothstep(0.03, 0.14, bright); // the crown of each scale, not the gaps
col *= flex * (1.0 + dm2 * 1.6 + rip * 0.6 + al * 0.45 * top);
col += sheen * (so * 0.22 + sm * 0.75 + rip * 0.05 + ss * 0.22) * uGloss * gate;
// a flipped scale shows its iridescent underside: emerald, teal, violet, gold
float fp = film * 0.6 + dot(n.xy, fdir) * 1.2 + lift * 0.7 + uTime * 0.12;
vec3 rainbow = 0.55 + 0.45 * cos(6.2831 * (fp + vec3(0.0, 0.3, 0.62)));
vec3 under = mix(sheen, rainbow, 0.8);
float hl = pow(max(dot(n, normalize(Lm * 0.6 + Lo * 0.4 + V)), 0.0), 28.0);
col += under * al * (0.015 + hl * 0.5) * uGloss * top;
col += sheen * uFlash * 0.015 * top;
// on load: a sheen sweeps across and reveals the skin
float sweep = (p.x / uRes.x * 0.6 + p.y / uRes.y * 0.4);
float reveal = smoothstep(uIntro * 1.4 - 0.4, uIntro * 1.4 - 0.05, sweep);
float band = exp(-pow((sweep - (uIntro * 1.4 - 0.2)) / 0.08, 2.0)) * (1.0 - uIntro);
col = col * (1.0 - reveal) + sheen * band * 0.12;
o = vec4(max(col, 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.45, 0.9, 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.1;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.8, 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 SerpentSkin({
image = "/backgrounds/serpent-skin/skin.jpg",
normalImage = "/backgrounds/serpent-skin/normal.jpg",
hue = 0,
sheen = "#9dffd8",
iridescence = "#c9a8ff",
scale = 1,
gloss = 1,
speed = 1,
slither = 1,
glow = 0.5,
background = "#020503",
interactive = true,
scroller,
children,
className,
}: SerpentSkinProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ hue, sheen, iridescence, scale, gloss, speed, slither, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { hue, sheen, iridescence, scale, gloss, speed, slither, glow, interactive };
redraw.current?.();
}, [hue, sheen, iridescence, scale, gloss, speed, slither, 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;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 = "auto 120%";
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", "uNrm", "uRes", "uImgSize", "uMouse", "uOrbit", "uDpr", "uScale", "uTime", "uGlide", "uSlither", "uHover",
"uGloss", "uHue", "uIntro", "uFlash", "uLod0", "uSheen", "uIri", "uWave", "uField", "uScrollLift", "uSpineY",
]);
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 brushed scales: a coarse field of springs, one per cell ----
const fieldTex = gl.createTexture()!;
let fw = 1, fh = 1;
let lift = new Float32Array(1), lv = new Float32Array(1), fdx = new Float32Array(1), fdy = new Float32Array(1);
let fbytes = new Uint8Array(4);
const layoutField = () => {
fw = Math.max(2, Math.ceil(w / MASK));
fh = Math.max(2, Math.ceil(h / MASK));
lift = new Float32Array(fw * fh);
lv = new Float32Array(fw * fh);
fdx = new Float32Array(fw * fh);
fdy = new Float32Array(fw * fh).fill(1);
fbytes = new Uint8Array(fw * fh * 4);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, fw, fh, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
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 l = Math.max(-1, Math.min(1, lift[i]));
fbytes[i * 4] = Math.round((l * 0.5 + 0.5) * 255);
fbytes[i * 4 + 1] = Math.round((fdx[i] * 0.5 + 0.5) * 255);
fbytes[i * 4 + 2] = Math.round((fdy[i] * 0.5 + 0.5) * 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);
};
// kick the scales near a point up, pointing them along a direction (or outward)
const kick = (x: number, y: number, R: number, amount: number, dirX: number, dirY: number, radial = false) => {
const cx = x / MASK, cy = y / MASK, rr = R / MASK;
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);
const k = j * fw + i;
lv[k] += amount * wgt;
let ux = dirX, uy = dirY;
if (radial) {
const l = Math.hypot(ox, oy) || 1;
ux = ox / l;
uy = oy / l;
}
const m = Math.min(1, wgt * 1.5);
fdx[k] += (ux - fdx[k]) * m;
fdy[k] += (uy - fdy[k]) * m;
const l2 = Math.hypot(fdx[k], fdy[k]) || 1;
fdx[k] /= l2;
fdy[k] /= l2;
}
};
let w = 1, h = 1, dpr = 1, rs = 1;
let fieldW = 0, fieldH = 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),
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, sv: 0, scrollY: 0 };
let flow = 0, glide = 0;
const glideSpring = spring(0);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
const imgTex = gl.createTexture()!;
const nrmTex = gl.createTexture()!;
let imgW = 1, imgH = 1, ready = 0;
let disposed = false;
// the skin spans the height (scale 1) and at least 60% of the width; past its sides it continues mirrored
const skinScale = () => Math.max((h * 0.9) / imgH, (w * 0.5) / imgW) * Math.max(0.3, props.current.scale);
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 < 2) return;
const p = props.current;
const X = T;
const minD = Math.min(w, h);
const sc = skinScale();
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);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, imgTex);
gl.uniform1i(US.uImg, 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, nrmTex);
gl.uniform1i(US.uNrm, 1);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uImgSize, imgW, imgH);
gl.uniform2f(US.uMouse, s.mx, s.my);
// a soft key light orbiting slowly across the skin
gl.uniform2f(US.uOrbit, w * (0.5 + 0.42 * Math.sin(flow * 0.23)), h * (0.5 + 0.38 * Math.sin(flow * 0.31 + 1.2)));
gl.uniform1f(US.uDpr, dpr * sceneScale);
gl.uniform1f(US.uScale, sc);
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uGlide, glide + glideSpring.x);
gl.uniform1f(US.uSlither, still ? 0 : Math.max(0, p.slither));
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uGloss, Math.max(0, p.gloss));
gl.uniform1f(US.uHue, (p.hue * Math.PI) / 180);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uFlash, s.flash);
gl.uniform1f(US.uLod0, Math.max(0, Math.log2(1 / (sc * dpr * sceneScale))));
gl.uniform3fv(US.uSheen, rgb(p.sheen));
gl.uniform3fv(US.uIri, rgb(p.iridescence));
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.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, fieldTex);
gl.uniform1i(US.uField, 2);
gl.uniform1f(US.uScrollLift, Math.max(-0.6, Math.min(0.6, s.sv * 0.3)));
// the spine glint travels down the body every few seconds
gl.uniform1f(US.uSpineY, h * (((flow * 0.07) % 1) * 1.6 - 0.3));
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: a raking light, the scales lift toward it ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.45, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.45, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.7, ease: "sine.inOut" });
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 (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);
// brush the scales: they flip up along the stroke, harder the faster you move
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(3, len / Math.max(8, now - last.t)); // px per ms
const ux = dx / len, uy = dy / len;
const steps = Math.max(1, Math.ceil(len / 18));
for (let k = 1; k <= steps; k++)
kick(last.x + (dx * k) / steps, last.y + (dy * k) / steps, 60, (1.6 + v * 2.6) / steps, ux, uy);
}
last = { x: p.x, y: p.y, t: now };
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: a ripple, the scales bristle and flash ----
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 shockwave flips a ring of scales outward
kick(p.x, p.y, 130, 5.5, 0, 0, true);
gsap.killTweensOf(s, "flash");
gsap.timeline().to(s, { flash: 1, duration: 0.2, ease: "sine.out" }).to(s, { flash: 0, duration: 1.2, ease: "sine.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the skin slides with you, gliding on 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;
glideSpring.goal = self.progress * imgH * 0.6;
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 < 2) return;
const p = props.current;
const sp = Math.max(0, p.speed);
flow += dt * sp;
// the skin glides on forever (the photo repeats seamlessly top to bottom)
glide = (glide + dt * (imgH * 0.012 * sp + Math.abs(s.sv) * imgH * 0.05)) % imgH;
step(glideSpring, 9, 5.2, dt);
// each brushed scale springs back down with a little flutter
const sub = Math.max(1, Math.ceil(dt / (1 / 120)));
const hs = dt / sub;
for (let n = 0; n < sub; n++)
for (let i = 0, m = fw * fh; i < m; i++) {
const x = lift[i], v = lv[i];
if (x === 0 && v === 0) continue;
const nv = v + (-70 * x - 7.5 * v) * hs;
const nx = x + nv * hs;
if (Math.abs(nx) < 1e-4 && Math.abs(nv) < 1e-3) {
lift[i] = 0;
lv[i] = 0;
} else {
lift[i] = Math.max(-1, Math.min(1, nx));
lv[i] = nv;
}
}
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 2.7) 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.2, 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);
// mirrored across the sides, repeating down the length
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.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);
const an = gl.getExtension("EXT_texture_filter_anisotropic");
if (an) gl.texParameterf(gl.TEXTURE_2D, an.TEXTURE_MAX_ANISOTROPY_EXT, 4);
onSize?.(im.naturalWidth, im.naturalHeight);
ready++;
if (ready === 2) start();
};
im.src = src;
};
load(image, imgTex, (iw, ih) => {
imgW = iw;
imgH = ih;
});
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);
gsap.killTweensOf(s);
freeTargets();
gl.deleteTexture(imgTex);
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, 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 SerpentSkin;
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
15 propsimagestringThe skin photo, seamless top to bottom.default "/backgrounds/serpent-skin/skin.jpg"default "/backgrounds/serpent-skin/skin.jpg"normalImagestringIts normal map (tangent space, +Y up).default "/backgrounds/serpent-skin/normal.jpg"default "/backgrounds/serpent-skin/normal.jpg"huenumberRotates the skin's hue in degrees (0 = emerald).default 0default 0sheenstringColour of the highlights on the scales.default "#9dffd8"default "#9dffd8"iridescencestringThe colour the sheen shifts toward with the angle of each scale.default "#c9a8ff"default "#c9a8ff"scalenumberSize of the scales.default 1default 1glossnumberStrength of the light on the scales.default 1default 1speednumberSpeed of the glide and slither.default 1default 1slithernumberStrength of the sinuous slither.default 1default 1glownumberStrength of the bloom on the glints.default 0.5default 0.5backgroundstringShown while the photo loads.default "#020503"default "#020503"interactivebooleanCursor light and lift, click ripple, scroll glide.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the skin.classNamestringSize it, e.g. h-screen w-full.