Backgrounds08 / 118
Fluted Glass
A soft orb of lavender-white light, falling off through violet into deep indigo, seen through a pane of vertical ribbed glass. Each rib is a little lens that stretches the light into stepped gradients with a fine highlight and a touch of rainbow at the rim. The light drifts toward your cursor, a click blooms a pulse, and scrolling slides the glass across the light.
WebGLWebGLRefracting glass ribsRefracting glass ribsCursor lightCursor lightGSAPGSAPReduced-motion safeReduced-motion safe
Move the lightClick for a pulse
Tweak
LIVELIVELight
#ddd4dc
#a395b0
#353aa6
#030308
1.00
Glass
27px
5.6
Motion
1.00
Interactive
Light follows the cursor, clicks pulse
Usage
Follows your tweaks.
usage.tsx
import { FlutedGlass } from "@/components/inreact/fluted-glass";
export function Hero() {
return (
<FlutedGlass
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the glass */}
</FlutedGlass>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/fluted-glass.jsonOr copy the source
Install the dependencies, then save this as components/inreact/fluted-glass.tsx.
terminal
npm install gsapcomponents/inreact/fluted-glass.tsx
"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Fluted Glass: a soft orb of light seen through ribbed glass.
*
* A glowing orb of lavender-white light, falling off through violet into
* deep indigo and black, sits behind a pane of vertical glass ribs. Each rib
* is a little cylindrical lens: it stretches a slice of the light behind it
* into a stepped gradient, edged with a fine highlight and a soft groove, and
* splits the light into a faint rainbow at the orb's rim.
*
* It reacts: the light drifts toward your cursor and the ribs refract it as
* it moves, faster movement smearing it wider; a click sends a pulse of light
* blooming out from the orb; scrolling slides the glass across the light and
* lifts the orb. On load the light rises and the glass comes into focus.
*
* <FlutedGlass className="h-screen w-full">
* <YourHero />
* </FlutedGlass>
*
* One WebGL fragment shader, no textures. GSAP drives every motion. Pauses
* off-screen; reduced motion shows a still frame; a CSS gradient without WebGL.
*/
export interface FlutedGlassProps {
/** Colour of the hot centre of the light. */
core?: string;
/** Colour of the glow around it. */
glow?: string;
/** Colour the light falls off into at its rim. */
rim?: string;
/** Background. */
background?: string;
/** Width of each glass rib, in px at 1000px tall (scales with the height). */
ribs?: number;
/** How strongly each rib refracts the light. */
refraction?: number;
/** Size of the orb of light. */
size?: number;
/** Speed of the idle drift. */
speed?: number;
/** Cursor light, click pulses. */
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 VERT = `attribute vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;
const FRAG = `
precision highp float;
uniform vec2 uRes, uOrb;
uniform float uTime, uRib, uRefract, uSize, uIn, uPulse, uSlide, uSmear;
uniform vec3 uCore, uGlow, uRim, uBg;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
// the light behind the glass: a soft orb, lavender-white at its heart, through violet into indigo and black
vec3 light(vec2 p) {
float t = uTime;
vec2 d = p - uOrb;
d.x *= 0.92;
// the orb breathes and its edge wobbles very slightly, so it never sits still
float R = 0.37 * uSize * (1.0 + 0.03 * sin(t * 0.7)) * (1.0 + uPulse * 0.35);
float r = length(d) / R;
r *= 1.0 + 0.04 * sin(atan(d.y, d.x) * 3.0 + t * 0.5);
// a defined orb: its light holds, then falls off quickly through the rim into black
float core = exp(-r * r * 1.8);
float halo = exp(-pow(r, 5.0) * 0.8);
float edge = exp(-pow((r - 1.0) / 0.22, 2.0));
vec3 c = uBg;
c = mix(c, uRim, smoothstep(0.0, 0.9, halo) * 0.85);
c += uRim * edge * 0.38;
c = mix(c, uGlow, smoothstep(0.3, 0.95, halo) * 0.85);
c = mix(c, uCore, core * 0.9);
// a dark band of night across the top, a faint violet sweep above the orb
c *= smoothstep(0.62, 0.3, p.y - uOrb.y * 0.25);
c += uRim * exp(-pow((p.y - (uOrb.y + R * 1.25)) / 0.05, 2.0)) * exp(-pow((p.x - uOrb.x) / 0.45, 2.0)) * 0.35;
// the pulse: a ring of light blooming outward
c += uGlow * uPulse * exp(-pow(r - (1.0 + (1.0 - uPulse) * 1.6), 2.0) * 6.0) * 0.6;
return c * uIn;
}
void main() {
vec2 p = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
// the glass: vertical ribs, each a little cylindrical lens
float w = uRib;
float gx = p.x + uSlide;
float lx = fract(gx / w);
float cx = (floor(gx / w) + 0.5) * w - uSlide;
// each rib stretches a wider slice of the light behind it: the stepped, sawtooth gradients
float k = uRefract * (1.0 + uSmear);
float spread = (lx - 0.5) * w * k;
// a touch of dispersion at the edges of the light
float disp = (lx - 0.5) * w * 0.12 * uRefract;
vec3 col;
col.r = light(vec2(cx + spread + disp, p.y)).r;
col.g = light(vec2(cx + spread, p.y)).g;
col.b = light(vec2(cx + spread - disp, p.y)).b;
// rib shading: a soft groove on the left edge, a fine highlight on the right where the light catches
float groove = smoothstep(0.0, 0.22, lx);
col *= 0.8 + 0.2 * groove;
vec3 behind = light(vec2(cx, p.y));
float lum = dot(behind, vec3(0.3, 0.55, 0.15));
col += mix(uRim, uCore, 0.5) * pow(lx, 22.0) * (0.15 + lum * 0.9) * 0.5;
// gentle vignette and fine grain
vec2 q = gl_FragCoord.xy / uRes - 0.5;
col *= 1.0 - 0.35 * dot(q * vec2(1.2, 0.8), q * vec2(1.2, 0.8));
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = 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 FlutedGlass({
core = "#ddd4dc",
glow = "#a395b0",
rim = "#353aa6",
background = "#030308",
ribs = 27,
refraction = 5.6,
size = 1,
speed = 1,
interactive = true,
scroller,
children,
className,
}: FlutedGlassProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ core, glow, rim, background, ribs, refraction, size, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { core, glow, rim, background, ribs, refraction, size, speed, interactive };
redraw.current?.();
}, [core, glow, rim, background, ribs, refraction, size, 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;";
host.prepend(canvas);
const gl = canvas.getContext("webgl", { alpha: false, antialias: false });
if (!gl) {
const p = props.current;
host.style.background = `repeating-linear-gradient(90deg, #0000 0 22px, #0003 22px 27px), radial-gradient(45% 40% at 50% 64%, ${p.core}, ${p.glow} 40%, ${p.rim} 70%, ${p.background})`;
canvas.remove();
return;
}
const prog = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, VERT],
[gl.FRAGMENT_SHADER, FRAG],
] 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(prog, sh);
}
gl.linkProgram(prog);
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(prog));
gl.useProgram(prog);
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const aPos = gl.getAttribLocation(prog, "aPos");
gl.enableVertexAttribArray(aPos);
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
const U = Object.fromEntries(
["uRes", "uOrb", "uTime", "uRib", "uRefract", "uSize", "uIn", "uPulse", "uSlide", "uSmear", "uCore", "uGlow", "uRim", "uBg"].map((n) => [n, gl.getUniformLocation(prog, n)]),
) as Record<string, WebGLUniformLocation | null>;
let w = 1, h = 1;
const resize = () => {
const 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);
gl.viewport(0, 0, canvas.width, canvas.height);
};
resize();
// ---- state: every value moved by GSAP ----
// the orb rests a little low and centred, where it sits in the reference
// left of centre, so the right edge falls into darkness where the ribs bend the rim into arcs
const rest = { x: -0.2, y: -0.1 };
const s = { ox: rest.x, oy: still ? rest.y : rest.y - 0.45, in: still ? 1 : 0, focus: still ? 1 : 0.25, pulse: 0, slide: 0, smear: 0, lift: 0, dx: 0, dy: 0 };
let time = 0;
const draw = () => {
const p = props.current;
gl.uniform2f(U.uRes, canvas.width, canvas.height);
gl.uniform2f(U.uOrb, s.ox + s.dx, s.oy + s.lift + s.dy);
gl.uniform1f(U.uTime, time);
gl.uniform1f(U.uRib, Math.max(4, p.ribs) / 1000);
gl.uniform1f(U.uRefract, p.refraction * s.focus);
gl.uniform1f(U.uSize, p.size);
gl.uniform1f(U.uIn, s.in);
gl.uniform1f(U.uPulse, s.pulse);
gl.uniform1f(U.uSlide, s.slide);
gl.uniform1f(U.uSmear, s.smear);
gl.uniform3fv(U.uCore, rgb(p.core));
gl.uniform3fv(U.uGlow, rgb(p.glow));
gl.uniform3fv(U.uRim, rgb(p.rim));
gl.uniform3fv(U.uBg, rgb(p.background));
gl.drawArrays(gl.TRIANGLES, 0, 3);
};
const ro = new ResizeObserver(() => {
resize();
if (still) draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the light rises behind the glass and the ribs come into focus ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 1.8, ease: "power2.out" }, 0)
.to(s, { oy: rest.y, duration: 2.6, ease: "expo.out" }, 0)
.to(s, { focus: 1, duration: 2.8, ease: "power3.inOut" }, 0.2);
// ---- idle: the light drifts slowly when nobody is pointing ----
const drift = gsap.to(s, { dx: 0.05, dy: 0.03, duration: 5.5, ease: "sine.inOut", yoyo: true, repeat: -1, delay: 2.5 });
// ---- cursor: the light follows you; the faster you move, the wider the glass smears it ----
const oxTo = gsap.quickTo(s, "ox", { duration: 1.4, ease: "power3" });
const oyTo = gsap.quickTo(s, "oy", { duration: 1.4, ease: "power3" });
const smearTo = gsap.quickTo(s, "smear", { duration: 0.5, ease: "power2.out" });
const calm = gsap.delayedCall(0.12, () => smearTo(0)).pause();
let lp: { x: number; y: number; t: number } | null = null;
const toP = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left - r.width / 2) / r.height, y: -(e.clientY - r.top - r.height / 2) / r.height };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive || intro.isActive()) return;
const p = toP(e);
// the light leans toward the cursor rather than jumping to it
oxTo(rest.x + p.x * 0.7);
oyTo(rest.y + (p.y - rest.y) * 0.6);
const now = performance.now();
if (lp) {
const v = Math.hypot(p.x - lp.x, p.y - lp.y) / Math.max(8, now - lp.t);
smearTo(Math.min(1.4, v * 900));
calm.restart(true);
}
lp = { ...p, t: now };
};
const leave = () => {
lp = null;
oxTo(rest.x);
oyTo(rest.y);
smearTo(0);
};
const down = () => {
if (!props.current.interactive) return;
gsap.fromTo(s, { pulse: 1 }, { pulse: 0, duration: 1.8, ease: "power2.out", overwrite: "auto" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the glass slides across the light and the orb lifts ----
const slideTo = gsap.quickTo(s, "slide", { duration: 1.2, ease: "power3" });
const liftTo = gsap.quickTo(s, "lift", { duration: 1.4, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
slideTo(self.progress * 0.5);
liftTo((self.progress - 0.5) * 0.3);
smearTo(Math.min(1.4, Math.abs(self.getVelocity()) / 2500));
calm.restart(true);
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const tick = () => {
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(tick);
return () => {
gsap.ticker.remove(tick);
intro.kill();
drift.kill();
calm.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
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
12 propscorestringColour of the hot centre of the light.default "#ddd4dc"default "#ddd4dc"glowstringColour of the glow around it.default "#a395b0"default "#a395b0"rimstringColour the light falls off into at its rim.default "#353aa6"default "#353aa6"backgroundstringBackground.default "#030308"default "#030308"ribsnumberWidth of each glass rib, in px at 1000px tall (scales with the height).default 27default 27refractionnumberHow strongly each rib refracts the light.default 5.6default 5.6sizenumberSize of the orb of light.default 1default 1speednumberSpeed of the idle drift.default 1default 1interactivebooleanCursor light and click pulses.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.