Stardust Vortex
A swirling cloud of light in deep space, in real 3D: thousands of particles orbit a bright core on a tilted, turbulent disk, a jet of dust pours out of it, chains of glowing beads snake through the space around it and far stars sit behind. Near particles are larger and softer, far ones fine and dim, and the camera slowly circles. The camera leans with your cursor and the dust parts around it, a click sends a shockwave through the cloud, and scrolling flies you into the vortex.
Tweak
LIVELIVELight
Particles
Motion
Interactive
The camera leans with the cursor, clicks send a shockwave
Usage
Follows your tweaks.
import { StardustVortex } from "@/components/inreact/stardust-vortex";
export function Hero() {
return (
<StardustVortex
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the particles */}
</StardustVortex>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/stardust-vortex.jsonOr copy the source
Install the dependencies, then save this as components/inreact/stardust-vortex.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);
/**
* Stardust Vortex: a swirling cloud of light in deep space, in real 3D.
*
* Thousands of points of light orbit a bright core on a tilted, turbulent
* disk, curling into tighter loops near the centre, while a jet of particles
* streams out of it. Chains of glowing beads snake through the space around
* it, and a scattered field of stars sits far behind. Every particle lives in
* 3D: near ones are larger and softer, far ones are fine and dim, and the
* camera slowly circles so the whole thing turns in depth. A real bloom pass
* lets the brightest points glow.
*
* It reacts: the camera leans with your cursor and the particles near it part
* around it; a click sends a shockwave rippling out through the cloud;
* scrolling flies you into the vortex. On load the dust gathers out of a wide
* scatter into the swirl.
*
* <StardustVortex className="h-screen w-full">
* <YourHero />
* </StardustVortex>
*
* WebGL: every particle is placed by the vertex shader (no CPU simulation),
* drawn additively as soft points, 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 StardustVortexProps {
/** Colour of the particles. */
color?: string;
/** Background colour. */
background?: string;
/** How many particles (1 = about 20,000). */
density?: number;
/** Size of the particles. */
size?: number;
/** Brightness. */
intensity?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the swirl. */
speed?: number;
/** Cursor parallax and push, click shockwave. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the particles. */
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 PART_VERT = `
precision highp float;
attribute vec4 aSeed;
attribute vec2 aKind;
uniform float uTime, uIn, uYaw, uPitch, uDist, uAspect, uSize, uPx, uShock, uShockAmp, uHover, uIntensity;
uniform vec2 uMouse;
varying float vB;
varying float vSoft;
const float TAU = 6.2831853;
mat3 rotX(float a) { float c = cos(a), s = sin(a); return mat3(1.0, 0.0, 0.0, 0.0, c, s, 0.0, -s, c); }
mat3 rotY(float a) { float c = cos(a), s = sin(a); return mat3(c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c); }
mat3 rotZ(float a) { float c = cos(a), s = sin(a); return mat3(c, s, 0.0, -s, c, 0.0, 0.0, 0.0, 1.0); }
float hash1(float n) { return fract(sin(n * 127.1) * 43758.5453); }
// a cheap smooth 3D wobble, so orbits curl and never look like clockwork
vec3 wobble(vec3 p, float t) {
return vec3(
sin(p.y * 2.3 + t * 0.7) + sin(p.z * 3.1 - t * 0.5),
sin(p.z * 2.7 + t * 0.6) + sin(p.x * 2.9 + t * 0.4),
sin(p.x * 2.1 - t * 0.8) + sin(p.y * 3.3 + t * 0.3)
) * 0.5;
}
// a bead chain's wandering path through the space around the vortex
vec3 chainPath(float t, float c) {
return vec3(
sin(t * 1.1 + c * 2.1) * 1.5 + sin(t * 0.37 + c) * 0.5,
sin(t * 0.73 + c * 1.3) * 1.15,
cos(t * 0.91 + c * 0.7) * 1.4
);
}
void main() {
float kind = aKind.x;
vec4 h = aSeed;
float t = uTime;
vec3 p;
float bright = 1.0;
float size = 1.0;
if (kind < 0.5) {
// the vortex: orbits on a tilted, puffy disk, faster and tighter near the core
float strand = floor(h.w * 140.0);
bool threaded = fract(h.w * 37.1) < 0.55;
// threaded particles share their strand's orbit and spread along it, so they draw a curling line
float sr = hash1(strand);
float r = threaded ? 0.07 + pow(sr, 1.6) * 0.9 + (h.z - 0.5) * 0.015 : 0.05 + pow(h.x, 1.25) * 1.9;
float w = 0.55 / (r + 0.25);
float a = (threaded ? h.x * 2.4 + sr * 40.0 : h.y * TAU) + t * w;
float thick = threaded ? sin(a * 2.0 + sr * 9.0) * 0.12 * r : (h.z - 0.5) * (0.06 + 0.32 * r);
p = vec3(cos(a) * r, thick, sin(a) * r * 0.85);
// each orbit tips a little differently, so the disk is a swirl of crossing loops, not a plate
float tilt = threaded ? (hash1(strand + 3.0) - 0.5) * 2.4 : (h.w - 0.5) * 1.3 * (1.0 - r * 0.35);
float roll = threaded ? (hash1(strand + 7.0) - 0.5) * 2.0 : (fract(h.x * 7.3) - 0.5) * 0.9;
p = rotX(tilt) * rotZ(roll) * p;
p += wobble(p * 1.6 + h.w * 3.0, t * 0.6) * 0.07 * (0.4 + r);
bright = 0.6 + 1.4 * exp(-r * 3.0);
size = 0.8 + 1.0 * pow(fract(h.w * 13.7), 3.0);
} else if (kind < 1.5) {
// the jet: dust pouring out of the core and fanning wider as it goes
float u = fract(h.x + t * 0.06);
float spread = 0.03 + u * 0.55;
p = vec3(0.05 + u * 2.4, (h.y - 0.5) * spread, (h.z - 0.5) * spread * 1.3);
p += wobble(p * 2.0 + h.w * 5.0, t) * 0.04 * u;
p = rotY(-0.25) * rotZ(0.08) * p;
bright = (1.0 - u) * 1.1 + 0.15;
size = 0.7 + 0.5 * fract(h.w * 9.1);
} else if (kind < 2.5) {
// the far stars: a shell around everything, turning very slowly
float th = h.x * TAU + t * 0.01;
float ph = acos(2.0 * h.y - 1.0);
float rr = 3.0 + h.z * 4.5;
p = vec3(sin(ph) * cos(th), cos(ph), sin(ph) * sin(th)) * rr;
bright = 0.4 + 1.6 * pow(h.w, 5.0);
size = 0.9 + 3.2 * pow(h.w, 8.0);
} else {
// bead chains: evenly spaced beads gliding along a path, the head the brightest
float c = aKind.y;
float k = h.x;
float tt = t * 0.22 - k * 0.9 + c * 1.9;
p = chainPath(tt, c);
bright = 2.2 * (1.0 - k * 0.6);
size = 2.6 * (1.0 - k * 0.55);
}
// on load: the dust gathers out of a wide scatter
float delay = fract(h.w * 17.3) * 0.35;
float g = smoothstep(delay, delay + 0.65, uIn);
vec3 scatter = normalize(h.xyz - 0.5 + 0.001) * (2.5 + h.w * 3.0);
p = mix(scatter, p, g);
// a click's shockwave: a shell of push running out from the core
float rad = length(p);
float front = uShock * 3.5;
float sh = exp(-pow((rad - front) / 0.35, 2.0)) * uShockAmp;
p += normalize(p + 0.0001) * sh * 0.35;
bright *= 1.0 + sh * 1.5;
// the camera: orbiting slowly, leaning with the cursor
vec3 v = rotX(uPitch) * rotY(uYaw) * p;
v.z += uDist;
float z = max(v.z, 0.05);
vec2 ndc = vec2(v.x / uAspect, v.y) * 1.7 / z;
// particles near the cursor part around it
vec2 dm = ndc - uMouse;
float md = length(dm * vec2(uAspect, 1.0));
ndc += (dm / max(md, 0.001)) * exp(-md * md / 0.03) * 0.06 * uHover;
gl_Position = vec4(ndc, 0.0, 1.0);
// nearer is larger and softer; very near points spread into soft discs
float ps = uSize * uPx * size * 4.2 / z;
gl_PointSize = clamp(ps, 1.0, 22.0);
vSoft = smoothstep(3.0, 18.0, ps);
// depth: far particles fade into the dark
vB = bright * g * uIntensity * clamp(13.0 / (z * z), 0.15, 2.2) * smoothstep(0.9, 2.0, z);
}`;
const PART_FRAG = `
precision highp float;
uniform vec3 uColor;
varying float vB;
varying float vSoft;
void main() {
vec2 d = gl_PointCoord - 0.5;
float r2 = dot(d, d) * 4.0;
// a hot core with a soft falloff; big near points become gentle discs
float core = exp(-r2 * mix(9.0, 3.0, vSoft));
float a = core * (1.0 - smoothstep(0.7, 1.0, r2)) * mix(1.0, 0.45, vSoft);
gl_FragColor = vec4(uColor * a * vB, 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.35, 0.95, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
uniform vec3 uBg;
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.7 + 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 = uBg + min(col, vec3(1.0));
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = 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];
}
const CHAINS = 5;
const BEADS = 34;
/** every particle's seeds and kind: 0 vortex, 1 jet, 2 star, 3 bead (with its chain) */
function buildParticles(scale: number) {
const nV = Math.round(15000 * scale), nJ = Math.round(3500 * scale), nS = Math.round(2600 * scale);
const n = nV + nJ + nS + CHAINS * BEADS;
const seed = new Float32Array(n * 4);
const kind = new Float32Array(n * 2);
let i = 0;
const push = (k: number, c: number, x?: number) => {
seed.set([x ?? Math.random(), Math.random(), Math.random(), Math.random()], i * 4);
kind.set([k, c], i * 2);
i++;
};
for (let j = 0; j < nV; j++) push(0, 0);
for (let j = 0; j < nJ; j++) push(1, 0);
for (let j = 0; j < nS; j++) push(2, 0);
for (let c = 0; c < CHAINS; c++) for (let b = 0; b < BEADS; b++) push(3, c, b / BEADS);
return { seed, kind, n };
}
export function StardustVortex({
color = "#f2f4fa",
background = "#000000",
density = 1,
size = 1,
intensity = 1,
glow = 0.8,
speed = 1,
interactive = true,
scroller,
children,
className,
}: StardustVortexProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, background, density, size, intensity, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, background, density, size, intensity, glow, speed, interactive };
redraw.current?.();
}, [color, background, density, size, 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(circle at 50% 50%, ${p.color}55, ${p.background} 30%)`;
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.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const partProg = build(PART_VERT, PART_FRAG);
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 UP = uni(partProg, ["uTime", "uIn", "uYaw", "uPitch", "uDist", "uAspect", "uSize", "uPx", "uShock", "uShockAmp", "uHover", "uIntensity", "uMouse", "uColor"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime", "uBg"]);
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);
};
// ---- the particles (rebuilt when the density changes) ----
const seedBuf = gl.createBuffer();
const kindBuf = gl.createBuffer();
let count = 0, builtFor = -1;
const ensureParticles = () => {
const d = Math.max(0.1, Math.min(3, props.current.density));
if (d === builtFor) return;
builtFor = d;
const P = buildParticles(d);
count = P.n;
gl.bindBuffer(gl.ARRAY_BUFFER, seedBuf);
gl.bufferData(gl.ARRAY_BUFFER, P.seed, gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, kindBuf);
gl.bufferData(gl.ARRAY_BUFFER, P.kind, gl.STATIC_DRAW);
};
ensureParticles();
const aSeed = gl.getAttribLocation(partProg, "aSeed");
const aKind = gl.getAttribLocation(partProg, "aKind");
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const x of Object.values(T)) {
gl.deleteFramebuffer(x.fb);
gl.deleteTexture(x.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 2);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = canvas.width, sh = canvas.height;
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
};
resize();
// ---- state: every value GSAP moves ----
const s = { in: still ? 1 : 0, yaw: 0, pitch: 0.32, lx: 0, ly: 0, dist: still ? 3.6 : 5.2, push: 0, hover: 0, mx: 0, my: 0, shock: 0, shockAmp: 0 };
let time = still ? 6 : 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;
ensureParticles();
const p = props.current;
const X = T;
// 1. the particles, added up as light
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.clearColor(0, 0, 0, 1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE);
gl.useProgram(partProg);
gl.uniform1f(UP.uTime, time);
gl.uniform1f(UP.uIn, s.in);
gl.uniform1f(UP.uYaw, s.yaw + s.lx);
gl.uniform1f(UP.uPitch, s.pitch + s.ly);
gl.uniform1f(UP.uDist, s.dist - s.push);
gl.uniform1f(UP.uAspect, X.scene.w / X.scene.h);
gl.uniform1f(UP.uSize, p.size);
gl.uniform1f(UP.uPx, (X.scene.h / 1000) * 2.2);
gl.uniform1f(UP.uShock, s.shock);
gl.uniform1f(UP.uShockAmp, s.shockAmp);
gl.uniform1f(UP.uHover, s.hover);
gl.uniform1f(UP.uIntensity, p.intensity);
gl.uniform2f(UP.uMouse, s.mx, s.my);
gl.uniform3fv(UP.uColor, rgb(p.color));
gl.bindBuffer(gl.ARRAY_BUFFER, seedBuf);
gl.enableVertexAttribArray(aSeed);
gl.vertexAttribPointer(aSeed, 4, gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, kindBuf);
gl.enableVertexAttribArray(aKind);
gl.vertexAttribPointer(aKind, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.POINTS, 0, count);
gl.disableVertexAttribArray(aSeed);
gl.disableVertexAttribArray(aKind);
gl.disable(gl.BLEND);
// 2. bloom
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);
// 3. composite
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);
gl.uniform3fv(UC.uBg, rgb(p.background));
drawQuad(compProg);
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the dust gathers into the swirl as the camera drifts in ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 3.2, ease: "power2.inOut" }, 0)
.to(s, { dist: 3.6, duration: 4, ease: "expo.out" }, 0);
// ---- cursor: the camera leans and the particles near it part around it ----
const lxTo = gsap.quickTo(s, "lx", { duration: 1.8, ease: "power3" });
const lyTo = gsap.quickTo(s, "ly", { duration: 1.8, ease: "power3" });
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 local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left) / r.width, y: (e.clientY - r.top) / r.height };
};
let first = true;
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const nx = p.x * 2 - 1, ny = 1 - p.y * 2;
if (first) {
gsap.set(s, { mx: nx, my: ny });
first = false;
}
mxTo(nx);
myTo(ny);
hoverTo(1);
lxTo(nx * 0.35);
lyTo(-ny * 0.18);
};
const leave = () => {
first = true;
hoverTo(0);
lxTo(0);
lyTo(0);
};
// ---- click: a shockwave runs out through the cloud ----
const down = () => {
if (!props.current.interactive) return;
gsap.killTweensOf(s, "shock,shockAmp");
gsap.fromTo(s, { shock: 0 }, { shock: 1, duration: 1.8, ease: "power2.out" });
gsap.timeline().fromTo(s, { shockAmp: 0 }, { shockAmp: 1, duration: 0.15, ease: "power2.out" }).to(s, { shockAmp: 0, duration: 1.6, ease: "power2.in" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: fly into the vortex ----
const pushTo = gsap.quickTo(s, "push", { duration: 1.4, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
if (intro.isActive()) return;
pushTo(Math.max(0, self.progress - 0.5) * 3);
},
});
// ---- loop, only while on screen: the swirl turns and the camera slowly circles ----
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;
s.yaw += dt * 0.05 * 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();
gl.deleteBuffer(seedBuf);
gl.deleteBuffer(kindBuf);
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 propscolorstringColour of the particles.default "#f2f4fa"default "#f2f4fa"backgroundstringBackground colour.default "#000000"default "#000000"densitynumberHow many particles (1 = about 20,000).default 1default 1sizenumberSize of the particles.default 1default 1intensitynumberBrightness.default 1default 1glownumberStrength of the bloom.default 0.8default 0.8speednumberSpeed of the swirl.default 1default 1interactivebooleanCursor parallax and push, click shockwave.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the particles.classNamestringSize it, e.g. h-screen w-full.