Canopy Vortex
Look straight up into a forest that spirals into the sun. A real photograph brought to life: trunks and a lace of branches twist into a glowing eye while light breaks through the leaves in jewel colours. You drift endlessly up into the vortex as the canopy turns, with a camera's radial zoom blur and focal blur toward the edges and a soft, dreamy bloom around every point of light. A depth map gives true 2.5D parallax, so the near trunks swing past the far canopy as you move the cursor; the leaves lift and part under your hand and the light behind them brightens, and the points of light twinkle as if the leaves were moving in the wind. A click sends a ripple through the canopy and a surge upward, scrolling climbs and twists the vortex, and on load you fall out of the eye into the forest. Bring your own photo and depth map to make it yours.
Tweak
LIVELIVEMotion
Interactive
Depth parallax and parting leaves, click to surge
Lens
Usage
Follows your tweaks.
import { CanopyVortex } from "@/components/inreact/canopy-vortex";
export function Hero() {
return (
<CanopyVortex
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the canopy */}
</CanopyVortex>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/canopy-vortex.jsonOr copy the source
Install the dependencies, then save this as components/inreact/canopy-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);
/**
* Canopy Vortex: look straight up into a forest that spirals into the sun.
*
* A real photograph brought to life. Trunks and a lace of branches twist into
* a glowing eye while light breaks through the leaves in jewel colours. You
* drift slowly up into the vortex, the canopy turning as you rise, with a
* camera's radial zoom blur and focal blur at the edges and a soft, dreamy
* bloom around every point of light.
*
* It reacts: a depth map makes the near trunks swing past the far canopy as
* the cursor moves (real 2.5D parallax), the leaves lift and part under the
* cursor and the light behind them brightens, and the points of light twinkle
* as if the leaves were moving in the wind. A click sends a ripple through the
* canopy and a surge upward with a burst of zoom blur, scrolling climbs and
* twists the vortex, and on load you fall out of the eye into the forest.
*
* <CanopyVortex className="h-screen w-full">
* <YourHero />
* </CanopyVortex>
*
* Bring your own photo with `image`, `depthImage` (white = near) and `eye`
* (where the vortex centre is in the photo, 0 to 1). The photo is extended
* past its edges along lines through the eye, so wide screens never show a
* border. WebGL2, mipmapped focal blur, real bloom (1/4 and 1/16 size).
* Pauses off-screen; reduced motion shows a still frame; the plain photo
* without WebGL2.
*/
export interface CanopyVortexProps {
/** The photo. */
image?: string;
/** Its depth map, white = near. */
depthImage?: string;
/** The vortex centre in the photo, [x, y] from 0 to 1. */
eye?: [number, number];
/** How much of the screen width the photo spans before it is extended (1 = cover). */
fit?: number;
/** Speed of the climb, the turning and the twinkle. */
speed?: number;
/** Strength of the dreamy bloom. */
glow?: number;
/** Strength of the radial zoom blur and focal blur at the edges. */
blur?: number;
/** Depth parallax strength. */
parallax?: number;
/** Twinkle of the points of light. */
twinkle?: number;
/** Tint of the light around the cursor. */
light?: string;
/** Background shown while the photo loads. */
background?: string;
/** Parallax, parting leaves and cursor light, click surge, scroll climb. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the canopy. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const ZK = 1.09; // zoom per loop of the endless climb
const QUAD = `#version 300 es
in vec2 aQ; out vec2 vUv;
void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `#version 300 es
precision highp float;
uniform sampler2D uImg, uDepth;
uniform vec2 uRes, uImgSize, uEye, uEyeScr, uMouse, uPar; // px; uEye in image px
uniform float uDpr, uScale, uTime, uLoop, uZoom, uTurn, uHover, uFlash, uSurge, uBlur, uTwinkle, uIntro, uLod0;
uniform vec3 uLight;
uniform vec4 uWave[${MAXW}];
in vec2 vUv;
out vec4 o;
float h21(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
// past the photo's edge, the canopy continues as its own mirror image; 'past' says how far
// outside we are (1 = inside), so the lens can blur and shade it into the frame
vec2 inside(vec2 ip, out float past) {
vec2 t = ip / uImgSize;
vec2 out2 = max(-t, t - 1.0);
past = 1.0 + max(0.0, max(out2.x * uImgSize.x, out2.y * uImgSize.y)) / (0.12 * min(uImgSize.x, uImgSize.y));
t = 1.0 - abs(1.0 - mod(t, 2.0));
return t * uImgSize;
}
// one layer of the endless climb: the photo at zoom z, turned with the vortex
vec3 layer(vec2 q, float z, float lod, float blurAmt, float jit) {
float ang = uTurn * log(z);
float c = cos(ang), s = sin(ang);
vec2 qq = mat2(c, -s, s, c) * q / z;
vec3 acc = vec3(0.0);
float past = 1.0;
// radial zoom blur: samples spread along the ray to the eye
for (int i = 0; i < 8; i++) {
float t = (float(i) + jit) / 8.0;
vec2 ip = inside(uEye + qq * (1.0 - blurAmt * t) / uScale, past);
acc += textureLod(uImg, ip / uImgSize, lod + min(3.5, (past - 1.0) * 2.2)).rgb;
}
acc /= 8.0;
// past the photo's edge, fade gently into shade
return acc * mix(1.0, 0.42, smoothstep(1.0, 2.6, past));
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float minD = min(uRes.x, uRes.y);
vec2 q = p - uEyeScr;
float r = length(q) / minD;
// depth at this point drives the parallax: near trunks swing further than the far canopy
vec2 ip0 = uEye + q / (uScale * uZoom);
float unused;
float dep = texture(uDepth, inside(ip0, unused) / uImgSize).r;
q -= uPar * (dep - 0.35);
// the leaves lift and part around the cursor
vec2 dm = p - uMouse;
float near = exp(-dot(dm, dm) / (0.045 * minD * minD)) * uHover;
q += dm * near * 0.08;
// click ripples roll out through the canopy
float rip = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 2.4) continue;
vec2 dw = p - W.xy;
float rr = length(dw) / minD;
float fr = rr - age * 0.7;
float k = exp(-fr * fr / 0.006) * exp(-age * 1.5) * W.w;
q += normalize(dw + 1e-4) * k * sin(fr * 60.0) * minD * 0.012;
rip += k;
}
// the edges blur like a lens: zoom blur along rays, focal blur by distance and depth
float edge = smoothstep(0.3, 1.05, r);
float blurAmt = uBlur * (edge * 0.04 + uSurge * 0.12 * smoothstep(0.05, 0.6, r));
float lod = uLod0 + uBlur * (edge * 1.3 + uSurge * 1.2 * smoothstep(0.05, 0.6, r)) * (1.1 - dep * 0.4);
float jit = h21(gl_FragCoord.xy);
// the endless climb: two copies one loop apart, cross-faded, so the zoom never ends
float f = fract(uLoop);
float zA = uZoom * pow(${ZK.toFixed(3)}, f);
float zB = uZoom * pow(${ZK.toFixed(3)}, f - 1.0);
float wB = smoothstep(0.0, 1.0, f);
vec3 col = mix(layer(q, zA, lod, blurAmt, jit), layer(q, zB, lod, blurAmt, jit), wB);
// points of light twinkle as if the leaves were moving in the wind
float lum = dot(col, vec3(0.299, 0.587, 0.114));
vec2 cell = floor((uEye + q / (uScale * uZoom)) / 16.0);
float tw = sin(uTime * (1.5 + 2.5 * h21(cell)) + h21(cell + 7.0) * 6.2831);
col *= 1.0 + uTwinkle * smoothstep(0.4, 0.85, lum) * tw * 0.22;
// the cursor's light pours through the parted leaves
col *= 1.0 + near * (0.25 + 0.6 * smoothstep(0.25, 0.7, lum));
col += uLight * near * smoothstep(0.3, 0.8, lum) * 0.12;
col *= 1.0 + rip * 0.5;
col += uLight * uFlash * 0.12 * exp(-r * 3.0);
// on load you fall out of the eye: the light opens from the centre outward
col *= smoothstep(uIntro * 1.5 + 0.02, uIntro * 1.5 - 0.35, r) * smoothstep(0.0, 0.3, uIntro);
o = vec4(col, 1.0);
}`;
const BLUR = `#version 300 es
precision mediump float;
uniform sampler2D uTex; uniform vec2 uStep; in vec2 vUv; out vec4 o;
void main() {
vec4 c = texture(uTex, vUv) * 0.2270;
c += (texture(uTex, vUv + uStep * 1.3846) + texture(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture(uTex, vUv + uStep * 3.2308) + texture(uTex, vUv - uStep * 3.2308)) * 0.0703;
o = c;
}`;
const BRIGHT = `#version 300 es
precision mediump float;
uniform sampler2D uTex; in vec2 vUv; out vec4 o;
void main() {
vec3 c = texture(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
o = vec4(c * smoothstep(0.55, 1.0, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision highp float;
uniform sampler2D uScene, uBloom, uWide;
uniform vec2 uEye; // eye in uv
uniform vec2 uAspect;
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() {
vec2 d = vUv - uEye;
float r = length(d * uAspect);
// a whisper of lens colour fringing toward the edges
float ca = smoothstep(0.3, 1.0, r) * 0.004;
vec3 sc;
sc.r = texture(uScene, vUv + d * ca).r;
sc.g = texture(uScene, vUv).g;
sc.b = texture(uScene, vUv - d * ca).b;
// dreamy bloom: a tight glow around each point of light plus a soft wide halation
vec3 bl = texture(uBloom, vUv).rgb * 0.75 + texture(uWide, vUv).rgb * 0.35;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.78, 0.0) * 0.85);
col += (h(gl_FragCoord.xy) - 0.5) / 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;
}
};
const DEFAULT_EYE: [number, number] = [0.491, 0.591];
export function CanopyVortex({
image = "/backgrounds/canopy-vortex/canopy.jpg",
depthImage = "/backgrounds/canopy-vortex/depth.png",
eye = DEFAULT_EYE,
fit = 0.85,
speed = 1,
glow = 0.5,
blur = 1,
parallax = 1,
twinkle = 1,
light = "#ffe6b8",
background = "#050806",
interactive = true,
scroller,
children,
className,
}: CanopyVortexProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ eye, fit, speed, glow, blur, parallax, twinkle, light, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { eye, fit, speed, glow, blur, parallax, twinkle, light, interactive };
redraw.current?.();
}, [eye, fit, speed, glow, blur, parallax, twinkle, light, interactive]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;opacity:0;transition:opacity .6s ease;";
host.prepend(canvas);
const gl = canvas.getContext("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
host.style.backgroundImage = `url(${image})`;
host.style.backgroundSize = "cover";
host.style.backgroundPosition = `${props.current.eye[0] * 100}% ${props.current.eye[1] * 100}%`;
canvas.remove();
return;
}
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.bindAttribLocation(pr, 0, "aQ");
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, [
"uImg", "uDepth", "uRes", "uImgSize", "uEye", "uEyeScr", "uMouse", "uPar", "uDpr", "uScale", "uTime", "uLoop", "uZoom",
"uTurn", "uHover", "uFlash", "uSurge", "uBlur", "uTwinkle", "uIntro", "uLod0", "uLight", "uWave",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uEye", "uAspect", "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;
};
let w = 1, h = 1, dpr = 1, rs = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 1.5);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
// the photo is soft, so on dense screens the scene renders a little under full size
const base = dpr > 1 ? 0.8 : 1;
const sw = Math.max(1, Math.round(canvas.width * base * rs)), sh = Math.max(1, Math.round(canvas.height * base * 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)),
};
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, flash: 0, surge: 0, sv: 0, climb: 0 };
const px = spring(0), py = spring(0); // parallax, -1..1
const zoom = spring(still ? 1 : 1.55);
const turn = spring(0.55);
let flow = 0, loop = 0;
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
// ---- the photo (mipmapped, for focal blur) and its depth ----
const imgTex = gl.createTexture()!;
const depTex = gl.createTexture()!;
let imgW = 1, imgH = 1, ready = 0;
let disposed = false;
// the eye at the centre, the photo spanning `fit` of the width (and at least the full height)
const layout = () => {
const p = props.current;
const scale = Math.max(h / imgH, (w * Math.max(0.3, p.fit)) / imgW);
return { scale, ex: w * 0.5, ey: h * 0.5 };
};
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 L = layout();
const minD = Math.min(w, h);
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, depTex);
gl.uniform1i(US.uDepth, 1);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uImgSize, imgW, imgH);
gl.uniform2f(US.uEye, p.eye[0] * imgW, p.eye[1] * imgH);
gl.uniform2f(US.uEyeScr, L.ex, L.ey);
gl.uniform2f(US.uMouse, s.mx, s.my);
const par = minD * 0.035 * Math.max(0, p.parallax);
gl.uniform2f(US.uPar, px.x * par, py.x * par);
gl.uniform1f(US.uDpr, dpr * sceneScale);
gl.uniform1f(US.uScale, L.scale);
gl.uniform1f(US.uTime, flow);
gl.uniform1f(US.uLoop, loop);
gl.uniform1f(US.uZoom, zoom.x);
gl.uniform1f(US.uTurn, turn.x);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uFlash, s.flash);
gl.uniform1f(US.uSurge, s.surge + Math.min(1, Math.abs(s.sv)) * 0.6 + Math.max(0, zoom.x - 1) * 1.2);
gl.uniform1f(US.uBlur, Math.max(0, p.blur));
gl.uniform1f(US.uTwinkle, still ? 0 : Math.max(0, p.twinkle));
gl.uniform1f(US.uIntro, s.intro);
// match texture detail to screen size so nothing shimmers
gl.uniform1f(US.uLod0, Math.max(0, Math.log2(1 / (L.scale * dpr * sceneScale))));
gl.uniform3fv(US.uLight, rgb(p.light));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
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.uniform2f(UC.uEye, L.ex / w, 1 - L.ey / h);
gl.uniform2f(UC.uAspect, w / minD, h / minD);
gl.uniform1f(UC.uGlow, Math.max(0, p.glow));
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
// ---- cursor: parallax by depth, the leaves part, the light pours through ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.5, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.5, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.8, ease: "sine.inOut" });
let first = true;
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);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
px.goal = (p.x / w) * 2 - 1;
py.goal = (p.y / h) * 2 - 1;
};
const leave = () => {
first = true;
hoverTo(0);
px.goal = 0;
py.goal = 0;
};
// ---- click: a ripple through the canopy and a surge upward ----
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();
gsap.killTweensOf(s, "flash,surge");
gsap.timeline().to(s, { flash: 1, duration: 0.22, ease: "sine.out" }).to(s, { flash: 0, duration: 1.3, ease: "sine.inOut" });
gsap.timeline().to(s, { surge: 1, duration: 0.3, ease: "power2.out" }).to(s, { surge: 0, duration: 1.6, ease: "power2.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: climb and twist with scroll speed, rise a little with progress ----
const svTo = gsap.quickTo(s, "sv", { duration: 0.5, ease: "power2.out" });
const climbTo = gsap.quickTo(s, "climb", { duration: 1.0, ease: "power3" });
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;
climbTo(Math.max(0, self.progress - 0.5) * 0.5);
svTo(Math.max(-1.5, Math.min(1.5, self.getVelocity() / 1800)));
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 endless climb: steady, faster on a click or while scrolling
loop += dt * (0.12 * sp + s.surge * 0.9 + Math.abs(s.sv) * 0.5) * s.intro;
zoom.goal = 1 + s.climb + s.surge * 0.06;
turn.goal = 0.55 + s.sv * 0.6 + Math.sin(flow * 0.21) * 0.15;
step(zoom, 14, 6.2, dt);
step(turn, 6, 4.2, dt);
step(px, 16, 6.5, dt);
step(py, 16, 6.5, dt);
for (let i = waves.length - 1; i >= 0; i--) if (flow - waves[i].t > 2.5) 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;
}
// on load: fall out of the eye into the forest
intro = gsap.to(s, { intro: 1, duration: 2.6, ease: "power2.out", delay: 0.05 });
zoom.goal = 1;
prev = performance.now();
io.observe(host);
gsap.ticker.add(tick);
};
const load = (src: string, tex: WebGLTexture, mip: boolean, 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);
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.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
if (mip) {
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);
} else gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
onSize?.(im.naturalWidth, im.naturalHeight);
ready++;
if (ready === 2) start();
};
im.src = src;
};
load(image, imgTex, true, (iw, ih) => {
imgW = iw;
imgH = ih;
});
load(depthImage, depTex, false);
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(depTex);
gl.deleteProgram(sceneProg);
gl.deleteProgram(blurProg);
gl.deleteProgram(brightProg);
gl.deleteProgram(compProg);
gl.deleteBuffer(vbo);
gl.deleteVertexArray(vao);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [image, depthImage, 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 CanopyVortex;
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 photo.default "/backgrounds/canopy-vortex/canopy.jpg"default "/backgrounds/canopy-vortex/canopy.jpg"depthImagestringIts depth map, white = near (parallax and focal blur).default "/backgrounds/canopy-vortex/depth.png"default "/backgrounds/canopy-vortex/depth.png"eye[number, number]The vortex centre in the photo, 0 to 1.default [0.491, 0.591]default [0.491, 0.591]fitnumberHow much of the screen width the photo spans before it is extended along rays through the eye (1 = cover).default 0.85default 0.85speednumberSpeed of the climb, the turning and the twinkle.default 1default 1glownumberStrength of the dreamy bloom.default 0.5default 0.5blurnumberStrength of the radial zoom blur and focal blur toward the edges.default 1default 1parallaxnumberDepth parallax strength.default 1default 1twinklenumberTwinkle of the points of light.default 1default 1lightstringTint of the light around the cursor.default "#ffe6b8"default "#ffe6b8"backgroundstringShown while the photo loads.default "#050806"default "#050806"interactivebooleanParallax, parting leaves and cursor light, click surge, scroll climb.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the canopy.classNamestringSize it, e.g. h-screen w-full.