Silk Web
A tangled cobweb hangs in the dark, caught in a cold beam of light: three sheets of fine silver strands knotted into irregular cells, torn into wide oval holes whose rims gather into bundles of thread, long loose strands across them, dust turning in the beam and a real bloom on the brightest silk. The strands stretch toward your cursor and catch its light, then shiver back when you let go; a click plucks the web and a vibration ripples through every strand; scrolling flies you into it.
Tweak
LIVELIVEColour
Web
Motion
Interactive
The silk stretches toward the cursor, clicks pluck it
Usage
Follows your tweaks.
import { SilkWeb } from "@/components/inreact/silk-web";
export function Hero() {
return (
<SilkWeb
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the web */}
</SilkWeb>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/silk-web.jsonOr copy the source
Install the dependencies, then save this as components/inreact/silk-web.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);
/**
* Silk Web: a tangled cobweb hanging in the dark, caught in a cold beam of light.
*
* Sheets of fine silver strands knot into irregular cells, three layers deep,
* torn open into wide oval holes whose rims gather into bundles of thread;
* long loose strands run across it all. A soft beam falls from above, lighting
* the near strands and leaving the far ones in haze, with dust turning slowly
* in the light. A real bloom pass lets the brightest silk glow.
*
* It reacts like silk: the strands near your cursor stretch toward it and catch
* its light, and spring back with a shiver when you let go; a click plucks the
* web, sending a vibration rippling out through every strand; scrolling flies
* you into the web, the near layers sliding past the far ones. On load the
* beam opens and the strands glint into being. An air current keeps it swaying.
*
* <SilkWeb className="h-screen w-full">
* <YourHero />
* </SilkWeb>
*
* WebGL: one shader (cell networks for the web, a light field, dust), then
* bloom at 1/4 and 1/16 size. GSAP drives every motion. Pauses off-screen;
* reduced motion shows a still frame; a CSS gradient without WebGL.
*/
export interface SilkWebProps {
/** Colour of the silk. */
silk?: string;
/** Colour of the light beam and the cursor's light. */
light?: string;
/** Background colour in the dark. */
background?: string;
/** How dense the web is. */
density?: number;
/** Strength of the light. */
intensity?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the air current. */
speed?: number;
/** Cursor pull and light, click pluck. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the web. */
children?: ReactNode;
className?: string;
}
const QUAD = `attribute vec2 aQ; varying vec2 vUv; void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `
#extension GL_OES_standard_derivatives : enable
precision highp float;
uniform vec2 uRes, uMouse, uPluckC;
uniform float uTime, uIn, uPull, uHover, uPluck, uPluckAmp, uZoom, uScrollY, uDensity, uIntensity, uShiver;
uniform vec2 uPar;
uniform vec3 uSilk, uLight, uBg;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(vec2 p) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }
float vnoise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 4; i++) {
v += a * vnoise(p);
p = p * 2.02 + vec2(11.3, 7.7);
a *= 0.5;
}
return v;
}
// distance to the nearest cell border: the strands of one sheet of web
vec2 strands(vec2 x, float seed) {
vec2 n = floor(x), f = fract(x);
vec2 mg = vec2(0.0), mr = vec2(0.0);
float md = 8.0;
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 h = hash2(n + g + seed);
vec2 o = h + 0.07 * sin(uTime * 0.5 + 6.2831 * h);
vec2 r = g + o - f;
float d = dot(r, r);
if (d < md) { md = d; mr = r; mg = g; }
}
md = 8.0;
for (int j = -2; j <= 2; j++)
for (int i = -2; i <= 2; i++) {
vec2 g = mg + vec2(float(i), float(j));
vec2 h = hash2(n + g + seed);
vec2 o = h + 0.07 * sin(uTime * 0.5 + 6.2831 * h);
vec2 r = g + o - f;
if (dot(mr - r, mr - r) > 0.00001) md = min(md, dot(0.5 * (mr + r), normalize(r - mr)));
}
return vec2(md, hash(n + mg + seed * 1.37));
}
void main() {
vec2 px = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y);
float H = uRes.y;
vec2 t = px / H; // 0..aspect across, 0 top .. 1 bottom
float asp = uRes.x / uRes.y;
// ---- the light: a soft beam from above, a little right of centre; the cursor carries its own light ----
float bx = asp * 0.53;
float spread = 0.16 + 0.3 * t.y;
float beam = exp(-pow((t.x - bx + 0.16 * t.y) / spread, 2.0)) * (1.0 - smoothstep(0.1, 0.95, t.y)) * (0.75 + 0.25 * sin(uTime * 0.35));
beam *= uIn;
vec2 mt = uMouse / H;
float cl = exp(-dot(t - mt, t - mt) / 0.018) * uHover;
float light = (beam * 1.05 + cl * 0.9) * uIntensity;
vec3 col = uBg + uLight * (beam * 0.46 + cl * 0.1) * uIntensity;
// ---- the silk moves: the air current, your pull, and the shiver of a pluck ----
vec2 dm = t - mt;
float md2 = dot(dm, dm);
vec2 pull = -dm * exp(-md2 / 0.03) * uPull * 0.55;
vec2 dp = t - uPluckC / H;
float pr = length(dp);
float wave = sin(pr * 60.0 - uPluck * 34.0) * exp(-pow((pr - uPluck * 1.4) / 0.12, 2.0)) * uPluckAmp;
vec2 shake = (dp / max(pr, 0.001)) * wave * 0.012 + vec2(sin(t.y * 40.0 + uTime * 30.0), cos(t.x * 40.0 + uTime * 27.0)) * 0.0015 * uShiver * exp(-md2 / 0.05);
vec2 air = vec2(fbm(t * 1.5 + uTime * 0.05) - 0.5, fbm(t * 1.5 + 9.0 - uTime * 0.04) - 0.5) * 0.035;
float silk = 0.0;
float rim = 0.0;
// the holes: wide ovals torn through the whole web, the same for every sheet
vec2 hq = t + air * 0.8 + pull * 0.6;
hq.y += uScrollY * 0.2;
// laid out like the reference: a big tilted oval at middle right, another low in the middle,
// a dark pocket up on the left; repeated seamlessly across wide screens
float tileW = 0.72;
vec2 hl = vec2(fract(hq.x / tileW) * tileW, hq.y);
// tear the ovals into ragged, organic shapes
hl += (vec2(fbm(hq * 2.3 + 5.0), fbm(hq * 2.3 + 9.0)) - 0.5) * 0.13;
float holes = 0.0;
for (int i = 0; i < 3; i++) {
vec2 hc = i == 0 ? vec2(0.6, 0.45) : i == 1 ? vec2(0.33, 0.74) : vec2(0.08, 0.2);
vec2 hr = i == 0 ? vec2(0.24, 0.1) : i == 1 ? vec2(0.22, 0.11) : vec2(0.12, 0.17);
float ang = i == 0 ? -0.38 : i == 1 ? -0.22 : 0.2;
for (int k = -1; k <= 1; k++) {
vec2 d = hl - hc - vec2(float(k) * tileW, 0.0);
d = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * d;
holes = max(holes, exp(-pow(length(d / hr), 2.6)));
}
}
float hm = 0.62 - holes * 0.42 + (fbm(hq * 3.4 + 1.3) - 0.5) * 0.2;
// the rims of the holes: bundles of long threads running parallel along the edge, pulled taut
float fw = max(fwidth(hm), 1e-5);
float bundle = 0.0;
for (int k = 0; k < 9; k++) {
float fk = float(k);
float iso = 0.33 + fk * 0.014 + (fbm(hq * 5.0 + fk * 3.3) - 0.5) * 0.045;
float th = 1.0 - smoothstep(0.0, 0.85, abs(hm - iso) / fw);
// each thread only runs part of the way round, so the bundle frays
float run = smoothstep(0.5, 0.66, vnoise(hq * 6.5 + fk * 7.1));
// threads out over the hole are fewer and fainter, sagging across it
float over = smoothstep(0.4, 0.33, iso);
bundle += th * run * (0.25 + 0.6 * hash(vec2(fk, 2.0))) * (1.0 - over * 0.55);
}
float bundleRev = smoothstep(0.2, 0.9, uIn);
// the tangle at the rims: silk pulled taut along the edge, cells drawn out along it, fraying into the sheet
float band = exp(-pow((hm - 0.46) / 0.075, 2.0)) * smoothstep(0.38, 0.41, hm);
for (int r = 0; r < 2; r++) {
float fr = float(r);
float rs = 18.0 + fr * 9.0;
float ra = 0.35 + fr * 1.1;
mat2 rr = mat2(cos(ra), -sin(ra), sin(ra), cos(ra));
vec2 rw = vec2(fbm(hq * 3.0 + fr * 2.0), fbm(hq * 3.0 + 6.0 + fr)) - 0.5;
vec2 rp = rr * (hq + rw * 0.08) * vec2(rs, rs * 0.55);
vec2 rd = strands(rp, 40.0 + fr * 9.0);
float rl = 1.0 - smoothstep(0.0, 0.7, rd.x * (H / rs) * 0.6);
bundle += rl * band * (0.35 + 0.65 * rd.y * rd.y) * (1.0 - fr * 0.3);
}
for (int L = 0; L < 4; L++) {
float fl = float(L);
// near sheets have bigger cells and move more; far ones are finer and sit in haze
float depth = 1.0 - fl * 0.24;
float scale = (7.0 + fl * 5.0 + fl * fl * 1.0) * uDensity;
vec2 c = vec2(asp * 0.5, 0.5);
vec2 q = (t - c) / (1.0 + (uZoom - 1.0) * depth * 1.4) + c;
q += uPar * depth * 0.03 + (pull + shake) * depth + air * (0.6 + depth);
q.y += uScrollY * depth * 0.25;
// where this sheet hangs, torn into wide oval holes
// each sheet's own edge sits a little off the next one's, so the rims are thick bundles of thread
float m = hm + (fbm(q * 2.4 + fl * 1.9) - 0.5) * 0.06 + (fl - 1.5) * 0.012;
float sheet = max(smoothstep(0.4, 0.47, m) * (0.6 + 0.4 * smoothstep(0.45, 0.65, m)), step(2.5, fl) * 0.22);
float edge = exp(-pow((m - 0.415) / 0.024, 2.0));
// the threads run along the sheet: cells drawn out along a slowly turning direction
float a = 0.5 + fl * 0.9 + (fbm(q * 0.8 + fl * 2.3) - 0.5) * 0.9;
mat2 rot = mat2(cos(a), -sin(a), sin(a), cos(a));
vec2 w = vec2(fbm(q * 2.2 + fl * 3.1), fbm(q * 2.2 + fl * 5.7 + 2.0)) - 0.5;
// and crowd together at the rims of the holes, where the web is pulled taut
// pulled taut at the rims: the cells there are many and drawn out along the edge
float sc = scale;
vec2 p = rot * (q + w * 0.05) * vec2(sc, sc * 0.6);
vec2 sd = strands(p, fl * 17.0);
float wpx = mix(0.55, 0.95, depth);
float sline = 1.0 - smoothstep(0.0, wpx, sd.x * (H / sc) * 0.6);
float bright = 0.3 + 0.7 * sd.y * sd.y;
// the strands glint in on load, a sheet at a time
float rev = smoothstep(0.0, 0.25, uIn * 1.6 - hash(floor(p)) * 0.5 - fl * 0.18);
float haze = mix(0.35, 1.0, depth);
silk += sline * bright * sheet * 0.9 * haze * rev;
rim += edge * depth * rev * 0.25;
}
silk += bundle * 0.85 * bundleRev;
rim += bundle * 0.3 * bundleRev;
// a few long loose strands run across it all, sagging a little
for (int i = 0; i < 7; i++) {
float fi = float(i);
vec2 h = hash2(vec2(fi, 3.7));
vec2 c = vec2(h.x * asp, h.y) + air * 0.8 + pull * 0.7;
float ang = (hash(vec2(fi, 9.1)) - 0.5) * 2.6;
vec2 dir = vec2(cos(ang), sin(ang));
vec2 nrm = vec2(-dir.y, dir.x);
vec2 r = t - c;
float along = dot(r, dir);
float dist = abs(dot(r, nrm) - 0.06 * along * along);
float th = 1.0 - smoothstep(0.0, 0.9 / H, dist);
silk += th * 0.45 * exp(-along * along * 1.5) * smoothstep(0.0, 0.3, uIn - 0.3);
}
// dust turning slowly in the beam
vec2 dg = t * 26.0 + vec2(uTime * 0.12, -uTime * 0.06);
vec2 dc = floor(dg);
vec2 dh = hash2(dc);
vec2 dpos = dc + 0.5 + 0.35 * vec2(sin(uTime * 0.4 + dh.x * 6.28), cos(uTime * 0.33 + dh.y * 6.28));
float mote = smoothstep(1.4 / H * 26.0, 0.0, length(dg - dpos)) * step(0.72, dh.x) * beam;
// the silk catches the light: bright in the beam, a faint sheen in the dark
float lit = 0.07 + light * 1.7 + (wave * wave) * 2.0;
col += uSilk * silk * lit * 0.8 + uSilk * rim * light * 0.3;
col += uLight * mote * 0.6;
gl_FragColor = vec4(col, 1.0);
}`;
const BLUR = `
precision mediump float;
uniform sampler2D uTex;
uniform vec2 uStep;
varying vec2 vUv;
void main() {
vec4 c = texture2D(uTex, vUv) * 0.2270;
c += (texture2D(uTex, vUv + uStep * 1.3846) + texture2D(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture2D(uTex, vUv + uStep * 3.2308) + texture2D(uTex, vUv - uStep * 3.2308)) * 0.0703;
gl_FragColor = c;
}`;
const BRIGHT = `
precision mediump float;
uniform sampler2D uTex;
varying vec2 vUv;
void main() {
vec3 c = texture2D(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
gl_FragColor = vec4(c * smoothstep(0.5, 0.95, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture2D(uScene, vUv).rgb;
vec3 bl = texture2D(uBloom, vUv).rgb * 0.6 + texture2D(uWide, vUv).rgb * 0.5;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.9, 0.0) * 1.2);
col = min(col, vec3(1.0));
vec2 q = vUv - 0.5;
col *= 1.0 - 0.4 * dot(q, q);
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
export function SilkWeb({
silk = "#dfe3ea",
light = "#b9c6d8",
background = "#0a0c11",
density = 1,
intensity = 1,
glow = 0.6,
speed = 1,
interactive = true,
scroller,
children,
className,
}: SilkWebProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ silk, light, background, density, intensity, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { silk, light, background, density, intensity, glow, speed, interactive };
redraw.current?.();
}, [silk, light, background, density, intensity, glow, speed, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(40% 70% at 55% 0%, ${p.light}55, ${p.background} 80%)`;
canvas.remove();
return;
}
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
gl.getExtension("OES_standard_derivatives");
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, ["uRes", "uMouse", "uPluckC", "uTime", "uIn", "uPull", "uHover", "uPluck", "uPluckAmp", "uZoom", "uScrollY", "uDensity", "uIntensity", "uShiver", "uPar", "uSilk", "uLight", "uBg"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const drawQuad = (pr: WebGLProgram) => {
const a = gl.getAttribLocation(pr, "aQ");
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.enableVertexAttribArray(a);
gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.disableVertexAttribArray(a);
};
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const x of Object.values(T)) {
gl.deleteFramebuffer(x.fb);
gl.deleteTexture(x.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
// the strands are fine lines: render at device resolution, capped for the GPU's sake
dpr = Math.min(window.devicePixelRatio || 1, 1.75);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = canvas.width, sh = canvas.height;
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
};
resize();
// ---- state: every value GSAP moves ----
const s = {
in: still ? 1 : 0,
mx: -1e4,
my: -1e4,
hover: 0,
pull: 0,
shiver: 0,
pluck: 0,
pluckAmp: 0,
pcx: 0,
pcy: 0,
zoom: still ? 1 : 1.12,
scrollY: 0,
px: 0,
py: 0,
};
let time = 0;
const blurPass = (src: Target, dst: Target, dx: number, dy: number) => {
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb);
gl.viewport(0, 0, dst.w, dst.h);
gl.useProgram(blurProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, src.tex);
gl.uniform1i(UB.uTex, 0);
gl.uniform2f(UB.uStep, dx / src.w, dy / src.h);
drawQuad(blurProg);
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, X.scene.w, X.scene.h);
gl.uniform2f(US.uMouse, s.mx * dpr, s.my * dpr);
gl.uniform2f(US.uPluckC, s.pcx * dpr, s.pcy * dpr);
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uIn, s.in);
gl.uniform1f(US.uPull, s.pull);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uShiver, s.shiver);
gl.uniform1f(US.uPluck, s.pluck);
gl.uniform1f(US.uPluckAmp, s.pluckAmp);
gl.uniform1f(US.uZoom, s.zoom);
gl.uniform1f(US.uScrollY, s.scrollY);
gl.uniform2f(US.uPar, s.px, s.py);
gl.uniform1f(US.uDensity, p.density);
gl.uniform1f(US.uIntensity, p.intensity);
gl.uniform3fv(US.uSilk, rgb(p.silk));
gl.uniform3fv(US.uLight, rgb(p.light));
gl.uniform3fv(US.uBg, rgb(p.background));
drawQuad(sceneProg);
gl.bindFramebuffer(gl.FRAMEBUFFER, X.a.fb);
gl.viewport(0, 0, X.a.w, X.a.h);
gl.useProgram(brightProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, X.scene.tex);
gl.uniform1i(UR.uTex, 0);
drawQuad(brightProg);
blurPass(X.a, X.b, 1, 0);
blurPass(X.b, X.a, 0, 1);
blurPass(X.a, X.c, 1, 0);
blurPass(X.c, X.d, 0, 1);
blurPass(X.d, X.c, 1.8, 0);
blurPass(X.c, X.d, 0, 1.8);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.useProgram(compProg);
[X.scene.tex, X.a.tex, X.d.tex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(UC.uScene, 0);
gl.uniform1i(UC.uBloom, 1);
gl.uniform1i(UC.uWide, 2);
gl.uniform1f(UC.uGlow, p.glow);
gl.uniform1f(UC.uTime, time);
drawQuad(compProg);
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
time = 4;
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the beam opens, the strands glint in sheet by sheet, the view settles back ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 3, ease: "power2.inOut" }, 0)
.to(s, { zoom: 1, duration: 3.6, ease: "expo.out" }, 0);
// ---- cursor: the silk stretches toward your finger and catches its light; let go and it shivers back ----
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.7, ease: "power2" });
const pullTo = gsap.quickTo(s, "pull", { duration: 0.9, ease: "power2.out" });
const pxTo = gsap.quickTo(s, "px", { duration: 1.4, ease: "power3" });
const pyTo = gsap.quickTo(s, "py", { duration: 1.4, ease: "power3" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const shiver = () => {
gsap.killTweensOf(s, "shiver");
gsap.fromTo(s, { shiver: 1 }, { shiver: 0, duration: 1.1, ease: "power2.out" });
};
let first = true;
let lp: { x: number; y: number; t: number } | null = null;
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
// a slow hand draws the silk out; a fast one tears through and leaves it shivering
const now = performance.now();
const v = lp ? Math.hypot(p.x - lp.x, p.y - lp.y) / Math.max(8, now - lp.t) : 0;
lp = { ...p, t: now };
pullTo(Math.max(0, 1 - v * 0.8));
if (v > 1.2) shiver();
pxTo((p.x / w - 0.5) * -1);
pyTo((p.y / h - 0.5) * -1);
};
const leave = () => {
first = true;
lp = null;
hoverTo(0);
pullTo(0);
pxTo(0);
pyTo(0);
shiver();
};
// ---- click: you pluck the web, and a vibration ripples out through every strand ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
s.pcx = p.x;
s.pcy = p.y;
gsap.killTweensOf(s, "pluck,pluckAmp");
gsap.fromTo(s, { pluck: 0 }, { pluck: 1, duration: 1.6, ease: "power1.out" });
gsap.fromTo(s, { pluckAmp: 1 }, { pluckAmp: 0, duration: 1.6, ease: "power2.in" });
shiver();
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: you fly into the web, near sheets sliding past the far ones ----
const zoomTo = gsap.quickTo(s, "zoom", { duration: 1.1, ease: "power3" });
const syTo = gsap.quickTo(s, "scrollY", { duration: 1.1, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
if (intro.isActive()) return;
zoomTo(1 + Math.max(0, self.progress - 0.5) * 0.7);
syTo((self.progress - 0.5) * -0.6);
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt * props.current.speed;
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
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 propssilkstringColour of the silk.default "#dfe3ea"default "#dfe3ea"lightstringColour of the light beam and the cursor's light.default "#b9c6d8"default "#b9c6d8"backgroundstringBackground colour in the dark.default "#0a0c11"default "#0a0c11"densitynumberHow dense the web is.default 1default 1intensitynumberStrength of the light.default 1default 1glownumberStrength of the bloom.default 0.6default 0.6speednumberSpeed of the air current.default 1default 1interactivebooleanCursor pull and light, click pluck.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the web.classNamestringSize it, e.g. h-screen w-full.