Flute Light
A crescent of light seen through dark fluted glass. A bright field of light, with a dark orb biting into it from the side, sits behind a pane of fine vertical ribs, and every rib is a real convex cylinder lens: it shows its own small, inverted image of the light, shaded like polished glass, so the light breaks into a calm rhythm of flutes and its edges dissolve rib by rib. It behaves like liquid glass: the glass never bends, only what you see through it moves. Under your cursor the glass swells like a drop of liquid and magnifies the light, the dark orb drifts after you with a fluid lag, a click sends a refraction ripple shimmering out through the glass, and scrolling slides the pane across the light.
Tweak
LIVELIVEGlass
Light
Interactive
Hover to swell the glass, click for a ripple, scroll to slide the pane
Usage
Follows your tweaks.
import { FluteLight } from "@/components/inreact/flute-light";
export function Hero() {
return (
<FluteLight
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the glass */}
</FluteLight>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/flute-light.jsonOr copy the source
Install the dependencies, then save this as components/inreact/flute-light.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);
/**
* Flute Light: a crescent of light seen through dark fluted glass.
*
* A bright field of light, with a dark orb biting into it from the side, sits
* behind a pane of fine vertical glass ribs. Every rib is a real convex
* cylinder lens: it shows its own small, inverted image of the light behind it,
* shaded like polished glass (a smooth rise, a bright crest, then a sharp fall
* into the groove), so the light breaks into a calm rhythm of glass flutes and
* its edges dissolve rib by rib.
*
* It behaves like liquid glass: the glass itself is rigid and never bends, only
* what you see through it moves. Under your cursor the glass swells like a drop
* of liquid, magnifying the light behind it, and the dark orb drifts after the
* cursor through the light with a fluid lag; a click sends a refraction ripple
* running out through the glass, the light shimmering rib by rib as it passes;
* scrolling slides the whole pane across the light, coasting before it settles.
* On load the light opens up behind the glass.
*
* <FluteLight className="h-screen w-full">
* <YourHero />
* </FluteLight>
*
* One WebGL2 fragment shader, no textures, dithered so the gradients never
* band. Pauses off-screen; reduced motion shows a still frame; a CSS gradient
* without WebGL2.
*/
export interface FluteLightProps {
/** Colour of the light (it is shown through the glass). */
color?: string;
/** Background, seen where there is no light. */
background?: string;
/** Width of each glass rib, in px per 1000px of the frame's size (the geometric mean of its width and height). */
ribs?: number;
/** How much of the scene each rib gathers into itself. */
refraction?: number;
/** Size of the dark orb biting into the light. */
size?: number;
/** Softness of the light's edges. */
softness?: number;
/** Speed of the idle drift. */
speed?: number;
/** Cursor swell and orb, click ripple, scroll slide. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the glass. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
const VERT = `#version 300 es
in vec2 aQ;
void main() { gl_Position = vec4(aQ, 0.0, 1.0); }`;
const FRAG = `#version 300 es
precision highp float;
uniform vec2 uRes, uC, uM;
uniform float uT, uRib, uK, uRin, uRout, uSoft, uIn, uSwell, uSlide;
uniform vec4 uWave[${MAXW}];
uniform vec3 uColor, uBg;
out vec4 o;
float hash(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * 0.1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
float h11(float x) { return fract(sin(x * 91.7) * 43758.5453); }
// the light behind the glass: a bright field, a dark orb biting in from the side, falling dark at the far corners
float light(vec2 p) {
vec2 d = p - uC;
float r = length(d * vec2(1.0, 0.97));
float wob = 0.012 * sin(atan(d.y, d.x) * 3.0 + uT * 0.35);
float inner = smoothstep(uRin - uSoft, uRin + uSoft, r + wob);
float outer = 1.0 - smoothstep(uRout - uSoft * 1.6, uRout + uSoft * 1.6, r - wob);
// brighter low, dimmer high, as in the reference
float level = 0.53 - 0.22 * p.y - 0.3 * smoothstep(0.28, 0.5, p.y);
return inner * outer * level * uIn;
}
void main() {
vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
// the glass is rigid: the flutes never move except when the whole pane slides
float gx = p.x + uSlide;
float w = uRib;
float fx = gx / w;
float lx = fract(fx);
float idx = floor(fx);
float cx = (idx + 0.5) * w - uSlide;
// only the light seen through it moves: a liquid swell under the cursor magnifies, ripples refract
vec2 dm = vec2(cx, p.y) - uM;
float sw = exp(-dot(dm, dm) / 0.028) * uSwell;
float shift = -dm.x * sw * 0.55;
float crest = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uT - W.z;
if (age < 0.0 || age > 3.5) continue;
vec2 dw = vec2(cx, p.y) - W.xy;
float dd = length(dw);
float fr = dd - age * 0.42;
float env = exp(-fr * fr / 0.006) * exp(-age * 1.1) * W.w;
shift += sin(fr * 46.0) * env * 0.035;
crest += (0.5 + 0.5 * sin(fr * 46.0)) * env;
}
// each flute is a convex cylinder lens: an inverted image of a slice of the light, gathered into its width
float span = w * uK * (1.0 + sw * 1.4);
float sx = cx + shift - (lx - 0.5) * span;
float L = light(vec2(sx, p.y)) * 0.5 + light(vec2(sx - span * 0.07, p.y)) * 0.25 + light(vec2(sx + span * 0.07, p.y)) * 0.25;
// polished-glass shading measured from the reference: a smooth rise, a crest at two thirds, a sharp fall into the groove
float rise = smoothstep(-0.15, 0.64, lx);
float fall = 1.0 - 0.9 * smoothstep(0.72, 0.99, lx);
float shade = (0.16 + 0.84 * rise) * fall;
// tiny differences between flutes, as in real cast glass
shade *= 0.96 + 0.08 * h11(idx);
// a drop of liquid glass focuses the light into its heart, and its curved rim catches a faint reflection
float dr = length(p - uM);
float rim = exp(-pow((dr - 0.15) / 0.03, 2.0)) * uSwell;
float v = L * shade * 1.12 * (1.0 + sw * 0.45);
v += (rim * 0.085 + crest * 0.06) * (0.35 + 0.65 * rise) * fall;
vec3 col = mix(uBg, uColor, clamp(v, 0.0, 1.2));
col += (hash(gl_FragCoord.xy) + hash(gl_FragCoord.yx + 19.1) - 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];
}
export function FluteLight({
color = "#ffffff",
background = "#000000",
ribs = 26,
refraction = 3,
size = 1,
softness = 1,
speed = 1,
interactive = true,
scroller,
children,
className,
}: FluteLightProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, background, ribs, refraction, size, softness, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, background, ribs, refraction, size, softness, speed, interactive };
redraw.current?.();
}, [color, background, ribs, refraction, size, softness, 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("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `repeating-linear-gradient(90deg, #0000 0 10px, #0007 14px 17px), radial-gradient(70% 60% at 95% 50%, transparent 45%, ${p.color}88 52%, transparent 90%), ${p.background}`;
canvas.remove();
return;
}
const compile = (type: number, src: string) => {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
return sh;
};
const prog = gl.createProgram()!;
const vs = compile(gl.VERTEX_SHADER, VERT), fs = compile(gl.FRAGMENT_SHADER, FRAG);
gl.attachShader(prog, vs);
gl.attachShader(prog, fs);
gl.bindAttribLocation(prog, 0, "aQ");
gl.linkProgram(prog);
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(prog));
gl.useProgram(prog);
const U = Object.fromEntries(
["uRes", "uC", "uM", "uT", "uRib", "uK", "uRin", "uRout", "uSoft", "uIn", "uSwell", "uSlide", "uWave", "uColor", "uBg"].map((n) => [n, gl.getUniformLocation(prog, n)]),
) as Record<string, WebGLUniformLocation | null>;
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);
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);
};
resize();
// ---- state ----
const s = { intro: still ? 1 : 0, swell: 0, mx: 0, my: 0 };
let time = still ? 4 : 0, slide = 0, slideV = 0;
let lastST = 0;
let hover = false;
// the orb drifts through the light like something suspended in liquid: a soft, viscous follow
const orb = { x: 0, y: 0, vx: 0, vy: 0, tx: 0, ty: 0 };
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
const swellTo = gsap.quickTo(s, "swell", { duration: 0.8, ease: "power2.out" });
const mxTo = gsap.quickTo(s, "mx", { duration: 0.45, ease: "power3.out" });
const myTo = gsap.quickTo(s, "my", { duration: 0.45, ease: "power3.out" });
const geometry = () => {
// the composition is measured from the reference (a tall frame); wider frames scale it up to fill
const aspect = w / h;
const k = Math.max(1, Math.pow(aspect / 0.494, 0.6));
const sz = Math.max(0.4, props.current.size);
return { aspect, k, cx: aspect * 0.5 + 0.053 * k, cy: -0.02, rin: 0.31 * k * sz, rout: 0.58 * k };
};
const draw = () => {
const p = props.current;
const g = geometry();
gl.viewport(0, 0, canvas.width, canvas.height);
gl.uniform2f(U.uRes, canvas.width, canvas.height);
const drift = { x: 0.018 * Math.sin(time * 0.17) * g.k, y: 0.03 * Math.sin(time * 0.11 + 1.3) };
gl.uniform2f(U.uC, g.cx + drift.x + orb.x, g.cy + drift.y + orb.y);
gl.uniform2f(U.uM, s.mx, s.my);
gl.uniform1f(U.uT, time);
// rib width follows the frame's overall size, so tall and wide frames keep a similar count of flutes
gl.uniform1f(U.uRib, ((Math.max(4, p.ribs) / 1000) * Math.sqrt(w * h)) / h);
gl.uniform1f(U.uK, Math.max(0.2, p.refraction));
gl.uniform1f(U.uRin, g.rin * (0.9 + 0.1 * s.intro));
gl.uniform1f(U.uRout, g.rout * (0.75 + 0.25 * s.intro));
gl.uniform1f(U.uSoft, 0.05 * g.k * Math.max(0.2, p.softness));
gl.uniform1f(U.uIn, s.intro);
gl.uniform1f(U.uSwell, s.swell);
gl.uniform1f(U.uSlide, slide);
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(U.uWave, waveBuf);
gl.uniform3fv(U.uColor, rgb(p.color));
gl.uniform3fv(U.uBg, rgb(p.background));
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
const toP = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left - r.width / 2) / r.height, y: (r.height / 2 - (e.clientY - r.top)) / r.height };
};
const move = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const q = toP(e);
if (!hover) {
gsap.set(s, { mx: q.x, my: q.y });
hover = true;
}
mxTo(q.x);
myTo(q.y);
swellTo(1);
// the orb is drawn gently toward the cursor (it never jumps there)
const g = geometry();
orb.tx = (q.x - (g.cx - g.rin * 0.6)) * 0.22;
orb.ty = (q.y - g.cy) * 0.3;
};
const leave = () => {
hover = false;
swellTo(0);
orb.tx = 0;
orb.ty = 0;
};
const down = (e: PointerEvent) => {
if (still || !props.current.interactive) return;
const tg = e.target as HTMLElement | null;
if (e.pointerType === "mouse" && tg && (tg === host || tg === canvas || tg.dataset.fluteLayer !== undefined)) e.preventDefault();
const q = toP(e);
// a refraction ripple runs out through the glass
waves.push({ x: q.x, y: q.y, t: time, s: 1 });
if (waves.length > MAXW) waves.shift();
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll slides the rigid pane across the light, with momentum ----
let lastScroll = 0;
const st = still
? null
: ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
const y = self.scroll();
const dy = y - lastScroll;
lastScroll = y;
lastST = performance.now();
if (!props.current.interactive || Math.abs(dy) > 2000) return;
slideV = Math.max(-0.6, Math.min(0.6, slideV + dy * 0.0006));
},
});
if (st) lastScroll = st.scroll();
const wheel = (e: WheelEvent) => {
if (still || !props.current.interactive) return;
if (performance.now() - lastST < 80) return;
const dy = e.deltaMode === 1 ? e.deltaY * 16 : e.deltaY;
slideV = Math.max(-0.6, Math.min(0.6, slideV + Math.max(-200, Math.min(200, dy)) * 0.0006));
};
host.addEventListener("wheel", wheel, { passive: true });
// ---- loop ----
let visible = true;
let prev = performance.now();
let intro: gsap.core.Tween | null = null;
const tick = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt * Math.max(0, props.current.speed);
// a rigid pane on rails: it keeps sliding, friction brings it to rest
slideV *= Math.exp(-dt * 1.6);
slide += slideV * dt;
if (Math.abs(slide) > 1000) slide = 0;
// the orb in liquid: a soft spring with heavy damping (no bounce, a little lag)
const k = 9, c = 5.2;
orb.vx += (k * (orb.tx - orb.x) - c * orb.vx) * dt;
orb.vy += (k * (orb.ty - orb.y) - c * orb.vy) * dt;
orb.x += orb.vx * dt;
orb.y += orb.vy * dt;
for (let i = waves.length - 1; i >= 0; i--) if (time - waves[i].t > 3.6) waves.splice(i, 1);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
if (still) {
draw();
redraw.current = draw;
} else {
intro = gsap.to(s, { intro: 1, duration: 2.2, ease: "power2.out", delay: 0.05 });
io.observe(host);
gsap.ticker.add(tick);
}
return () => {
redraw.current = null;
gsap.ticker.remove(tick);
intro?.kill();
st?.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
host.removeEventListener("wheel", wheel);
gsap.killTweensOf(s);
gl.deleteProgram(prog);
gl.deleteShader(vs);
gl.deleteShader(fs);
gl.deleteBuffer(vbo);
gl.deleteVertexArray(vao);
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 data-flute-layer="" className="relative z-10 h-full">
{children}
</div>
)}
</div>
);
}
export default FluteLight;
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 light seen through the glass.default "#ffffff"default "#ffffff"backgroundstringBackground, seen where there is no light.default "#000000"default "#000000"ribsnumberWidth of each glass rib, in px per 1000px of the frame's size.default 26default 26refractionnumberHow much of the scene each rib gathers into itself.default 3default 3sizenumberSize of the dark orb biting into the light.default 1default 1softnessnumberSoftness of the light's edges.default 1default 1speednumberSpeed of the idle drift.default 1default 1interactivebooleanCursor swell and orb, click ripple, scroll slide.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the glass.classNamestringSize it, e.g. h-screen w-full.