Cipher Rain
A living curtain of code. Columns of digits, hex and technical symbols rain down through three layers of depth: near ones large and electric cyan, far ones small and drifting in a blue-violet haze, every column led by a white-hot head and a trail that re-ciphers as it falls, lifted by a real bloom while the blacks stay black. Your cursor is a decoding lens that magnifies the rain and makes it brighten and scramble while the layers shift in parallax, a click sends a shockwave that bends and lights the rain, scrolling makes it rush, and an optional word is spelled out in glyphs, lit by every drop that runs through it.
Tweak
LIVELIVEColour
Rain
Layout
Motion
Interactive
Cursor decoding lens, click shockwave
Usage
Follows your tweaks.
import { CipherRain } from "@/components/inreact/cipher-rain";
export function Hero() {
return (
<CipherRain
text="CODE"
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the rain */}
</CipherRain>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/cipher-rain.jsonOr copy the source
Install the dependencies, then save this as components/inreact/cipher-rain.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);
/**
* Cipher Rain: a living curtain of code falling through three layers of depth.
*
* Columns of glyphs (digits, hex and technical symbols) rain down past the
* viewer: near columns large and bright, far ones small and drifting in a
* blue-violet haze. Every column has a white-hot head and a trail that fades
* behind it, and glyphs keep re-ciphering as they fall. A real bloom lifts the
* heads; the blacks stay black.
*
* It reacts: your cursor is a decoding lens. It magnifies the rain beneath it,
* the glyphs around it brighten and scramble, and the three layers shift in
* parallax. A click sends a shockwave that bends and lights the rain. Scrolling
* makes the rain rush and the layers glide past each other. On load the
* curtain dissolves in from the top. Pass `text` and the rain spells out a word
* in glyphs, lit by every drop that runs through it; `focus` calms the centre
* so a headline on top stays readable.
*
* <CipherRain className="h-screen w-full" text="CODE">
* <YourHero />
* </CipherRain>
*
* WebGL2: one shader draws the rain from a glyph atlas (sampled with explicit
* gradients, so cell edges never show seams), then a 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 WebGL2.
*/
export interface CipherRainProps {
/** Colour of the near rain. */
color?: string;
/** Colour of the far rain, deep in the haze. */
depthColor?: string;
/** Colour of the white-hot heads. */
headColor?: string;
/** Background colour. */
background?: string;
/** A word the rain spells out in glyphs. Empty for none. */
text?: string;
/** How many columns are falling, 0 to 1. */
density?: number;
/** Speed of the rain. */
speed?: number;
/** Strength of the bloom around the heads. */
glow?: number;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** Cursor lens, click shockwave. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the rain. */
children?: ReactNode;
className?: string;
}
// digits, hex and technical symbols: clearly code, never katakana
const GLYPHS = Array.from("0123456789ABCDEF<>/\\=+*#%&$@:;.|[]{}()^~?!∑∆Ωλπ∞≡≈±×÷√∂∫◊■□▲△◇○●").slice(0, 64);
const GLYPH_COUNT = GLYPHS.length;
const ATLAS_N = 8; // 8 x 8 glyph cells
const CELL = 64; // atlas cell size in px
const MAXW = 4; // shockwaves in flight
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 vec2 uRes; // css px
uniform float uDpr, uTime, uFall, uIntro, uDensity, uFocus, uHover, uTextOn, uTextIn, uScale;
uniform vec2 uMouse, uPar; // cursor in css px (top-left origin), parallax -1..1
uniform float uScrollY;
uniform vec3 uColor, uDepth, uHead, uBg;
uniform vec4 uWave[${MAXW}]; // x, y (css px), start time, strength
uniform sampler2D uAtlas, uText;
in vec2 vUv;
out vec4 o;
float h11(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
// one layer of rain: cell size, speed, parallax depth
vec3 layer(vec2 p, float k, float cs, float spd, float par, vec3 tint, float bright) {
// parallax: near layers slide further with the cursor and scroll
vec2 q = p + uPar * par * vec2(40.0, 26.0) + vec2(0.0, uScrollY * par);
// the cursor lens magnifies the rain beneath it
vec2 dm = p - uMouse;
float R = (200.0 + cs * 4.0) * uScale;
float lens = exp(-dot(dm, dm) / (R * R)) * uHover;
q -= dm * lens * 0.16;
// shockwaves bend the rain outward as they pass
float wave = 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.2) continue;
vec2 d = p - W.xy;
float r = length(d);
float front = age * 620.0;
float band = exp(-pow((r - front) / 60.0, 2.0)) * exp(-age * 1.6) * W.w;
q -= d / max(r, 1.0) * band * 14.0;
wave = max(wave, band);
}
vec2 g = q / cs;
vec2 cell = floor(g);
vec2 f = fract(g);
float col = cell.x + k * 131.0;
float rows = uRes.y / cs;
float lit = 0.0, head = 0.0;
// two drops per column, each with its own speed, length and phase
for (int j = 0; j < 2; j++) {
float s = col + float(j) * 57.3;
if (h11(s * 1.7 + 3.1) > uDensity) continue;
float v = mix(0.55, 1.45, h11(s + 9.2)) * spd;
float len = mix(7.0, 26.0, h11(s + 2.7));
float span = rows + len + 6.0;
float hd = mod(uFall * v + h11(s + 4.4) * span, span) - 3.0;
float d = hd - cell.y;
if (d >= 0.0 && d < len) {
lit = max(lit, pow(1.0 - d / len, 1.7));
head = max(head, 1.0 - smoothstep(0.0, 1.2, d));
}
}
// the word, built out of whole glyph cells on the middle layer; the near rain quiets behind it
float word = 0.0, behind = 0.0;
if (uTextOn > 0.5) {
// a soft halo around the letters quiets all rain there, so the word reads
behind = texture(uText, p / uRes).g * uTextIn;
if (k > 0.5 && k < 1.5) {
vec2 c = (cell + 0.5) * cs - uPar * par * vec2(40.0, 26.0) - vec2(0.0, uScrollY * par);
word = step(0.5, texture(uText, vec2(c.x / uRes.x, c.y / uRes.y)).r) * uTextIn;
}
}
float decode = lens * smoothstep(0.0, 1.0, lit + 0.25);
// glyphs re-cipher as they fall: faster near the head, near the cursor and in the word
float rate = 1.5 + head * 14.0 + decode * 18.0 + word * 3.0;
float gi = floor(h21(cell + floor(uTime * rate * mix(0.6, 1.4, h11(col))) * 0.37) * ${GLYPH_COUNT}.0);
vec2 slot = vec2(mod(gi, ${ATLAS_N}.0), floor(gi / ${ATLAS_N}.0));
// the glyph sits inside its cell with a small margin; explicit gradients avoid seams
// word glyphs grow to fill their cells so the lettering reads solid
float gscale = mix(1.12, 0.9, word);
vec2 inner = (f - 0.5) * gscale + 0.5;
vec2 uv = (slot + clamp(inner, 0.0, 1.0)) / ${ATLAS_N}.0;
vec2 gd = vec2(gscale / (cs * uDpr) / ${ATLAS_N}.0);
float a = textureGrad(uAtlas, uv, vec2(gd.x, 0.0), vec2(0.0, gd.y)).r;
if (inner.x < 0.0 || inner.x > 1.0 || inner.y < 0.0 || inner.y > 1.0) a = 0.0;
float b = lit * bright * (1.0 - 0.9 * behind * (1.0 - word)) + word * (1.15 + lit * 0.8) + decode * 0.9 + wave * 0.7 * (lit + 0.2);
vec3 c = mix(tint, uHead, clamp(head * 0.85 + decode * 0.45 + word * 0.6, 0.0, 1.0));
c *= b + head * 1.6;
// the word's cells are faintly backlit, like a lit LED matrix, with soft rounded edges
vec2 e = abs(f - 0.5);
float cellFill = word * smoothstep(0.5, 0.36, max(e.x, e.y)) * (0.07 + lit * 0.08);
return c * a + tint * cellFill;
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
// far: small, slow, deep blue-violet haze; near: large, fast, bright
vec3 col = uBg;
// the grid scales with the viewport: finer rain (and legible words) on phones
col += layer(p, 0.0, 11.0 * uScale, 0.55, 0.25, uDepth, 0.38);
col += layer(p, 1.0, 16.0 * uScale, 0.8, 0.6, mix(uDepth, uColor, 0.6), 0.62);
col += layer(p, 2.0, 23.0 * uScale, 1.0, 1.0, uColor, 0.9);
// a calm zone in the centre so headlines read
vec2 c = (p - uRes * vec2(0.5, 0.48)) / uRes.y;
float calm = 1.0 - uFocus * 0.72 * exp(-dot(c * vec2(0.85, 1.6), c * vec2(0.85, 1.6)) / 0.11);
col = uBg + (col - uBg) * calm;
// intro: the curtain dissolves in from the top, column by column
float rowN = p.y / uRes.y;
float n = h21(floor(vec2(p.x / 16.0, 0.0)));
float show = smoothstep(rowN - 0.08, rowN + 0.02, uIntro * 1.25 - n * 0.2);
col = uBg + (col - uBg) * show;
// tiny dither so the haze never bands
col += (h21(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
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.1, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision mediump float;
uniform sampler2D uScene, uBloom, uWide; uniform float uGlow, uTime; in vec2 vUv; out vec4 o;
float h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.55 + texture(uWide, vUv).rgb * 0.45;
vec3 x = sc + bl * uGlow;
// soft shoulder: highlights roll off instead of clipping, blacks untouched
vec3 col = x / (1.0 + max(x - 0.8, 0.0) * 1.2);
col += (h(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
o = 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];
}
export function CipherRain({
color = "#3ee6ff",
depthColor = "#5a5cff",
headColor = "#effcff",
background = "#020509",
text = "",
density = 0.55,
speed = 1,
glow = 0.8,
focus = 0.3,
interactive = true,
scroller,
children,
className,
}: CipherRainProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, depthColor, headColor, background, density, speed, glow, focus, interactive });
const redraw = useRef<(() => void) | null>(null);
const setWord = useRef<((t: string) => void) | null>(null);
useEffect(() => {
props.current = { color, depthColor, headColor, background, density, speed, glow, focus, interactive };
redraw.current?.();
}, [color, depthColor, headColor, background, density, speed, glow, focus, interactive]);
const textRef = useRef(text);
useEffect(() => {
textRef.current = text;
setWord.current?.(text);
}, [text]);
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 = `linear-gradient(180deg, ${p.color}22, ${p.background} 60%), ${p.background}`;
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, [
"uRes", "uDpr", "uTime", "uFall", "uIntro", "uDensity", "uFocus", "uHover", "uTextOn", "uTextIn", "uScale",
"uMouse", "uPar", "uScrollY", "uColor", "uDepth", "uHead", "uBg", "uWave", "uAtlas", "uText",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
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);
// ---- glyph atlas: white glyphs, one per cell, mipmapped for the small far layer ----
const atlasTex = gl.createTexture()!;
{
const c = document.createElement("canvas");
c.width = c.height = ATLAS_N * CELL;
const x = c.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, c.width, c.height);
x.fillStyle = "#fff";
x.textAlign = "center";
x.textBaseline = "middle";
x.font = `600 ${CELL * 0.72}px ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace`;
GLYPHS.forEach((g, i) => {
x.fillText(g, (i % ATLAS_N + 0.5) * CELL, (Math.floor(i / ATLAS_N) + 0.54) * CELL);
});
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_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);
}
// ---- the word mask: rendered once per text / size, sampled at each cell's centre ----
const textTex = gl.createTexture()!;
let textOn = 0;
const wordCanvas = document.createElement("canvas");
const drawWord = (word: string) => {
const W = Math.max(64, Math.round(host.clientWidth / 4));
const H = Math.max(64, Math.round(host.clientHeight / 4));
wordCanvas.width = W;
wordCanvas.height = H;
const x = wordCanvas.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, W, H);
textOn = word.trim() ? 1 : 0;
if (textOn) {
let size = H * 0.42;
const font = (px: number) => `700 ${px}px ui-sans-serif, system-ui, "Helvetica Neue", Arial, sans-serif`;
x.font = font(size);
const fit = (W * 0.9) / Math.max(1, x.measureText(word).width);
if (fit < 1) size *= fit;
// red: the crisp letters; green: a soft halo around them
const paint = (blur: number, style: string) => {
x.save();
x.globalCompositeOperation = "lighter";
x.filter = blur ? `blur(${blur}px)` : "none";
x.font = font(size);
x.fillStyle = style;
x.textAlign = "center";
x.textBaseline = "middle";
x.fillText(word, W / 2, H * 0.48);
if (blur) x.fillText(word, W / 2, H * 0.48);
x.restore();
};
paint(Math.max(3, size * 0.16), "#00ff00");
paint(0, "#ff0000");
}
gl.bindTexture(gl.TEXTURE_2D, textTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, wordCanvas);
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);
};
// ---- render targets ----
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;
const resize = () => {
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)),
};
drawWord(textRef.current);
};
resize();
// ---- everything GSAP moves ----
const s = { intro: still ? 1 : 0, textIn: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, px: 0, py: 0, scrollY: 0, boost: 0 };
let fall = still ? 37 : 0;
const t0 = performance.now();
const clock = () => (still ? 12 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
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) return;
const p = props.current;
const X = T;
const now = clock();
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, w, h);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uScale, Math.max(0.6, Math.min(1, w / 1100)));
gl.uniform1f(US.uTime, now);
gl.uniform1f(US.uFall, fall);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uDensity, Math.max(0, Math.min(1, p.density)));
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uTextOn, textOn);
gl.uniform1f(US.uTextIn, s.textIn);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform2f(US.uPar, s.px, s.py);
gl.uniform1f(US.uScrollY, s.scrollY);
gl.uniform3fv(US.uColor, rgb(p.color));
gl.uniform3fv(US.uDepth, rgb(p.depthColor));
gl.uniform3fv(US.uHead, rgb(p.headColor));
gl.uniform3fv(US.uBg, rgb(p.background));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.uniform1i(US.uAtlas, 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, textTex);
gl.uniform1i(US.uText, 1);
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.uniform1f(UC.uGlow, p.glow);
gl.uniform1f(UC.uTime, now);
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
setWord.current = (word: string) => {
drawWord(word);
if (!still && word.trim()) gsap.fromTo(s, { textIn: 0 }, { textIn: 1, duration: 1.6, ease: "power2.out", overwrite: "auto" });
draw();
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
setWord.current = null;
ro.disconnect();
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the curtain dissolves in from the top, then the word resolves ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { intro: 1, duration: 2.4, ease: "power2.inOut" }, 0)
.to(s, { textIn: 1, duration: 1.8, ease: "power2.out" }, 1.4);
// ---- cursor: a decoding lens and depth parallax ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.35, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.35, ease: "power3" });
const pxTo = gsap.quickTo(s, "px", { duration: 1.2, ease: "power3" });
const pyTo = gsap.quickTo(s, "py", { duration: 1.2, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.6, ease: "power2.inOut" });
let first = true;
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top, nx: (e.clientX - r.left) / r.width - 0.5, ny: (e.clientY - r.top) / r.height - 0.5 };
};
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);
pxTo(-p.nx * 2);
pyTo(-p.ny * 2);
hoverTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
pxTo(0);
pyTo(0);
};
// ---- click: a shockwave that bends and lights the rain ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: clock(), s: 1 });
if (waves.length > MAXW) waves.shift();
gsap.fromTo(s, { boost: 1.6 }, { boost: 0, duration: 1.2, ease: "power3.out", overwrite: "auto" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the rain rushes with scroll speed and the layers glide in depth ----
const scrollYTo = gsap.quickTo(s, "scrollY", { duration: 0.9, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
scrollYTo((self.progress - 0.5) * -120);
const v = Math.min(1, Math.abs(self.getVelocity()) / 2500);
if (v > s.boost) gsap.to(s, { boost: v * 2.2, duration: 0.25, ease: "power2.out", overwrite: "auto", onComplete: () => void gsap.to(s, { boost: 0, duration: 1.4, ease: "power2.out" }) });
},
});
// ---- 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;
fall += dt * 9 * props.current.speed * (1 + s.boost);
const c = clock();
for (let i = waves.length - 1; i >= 0; i--) if (c - waves[i].t > 2.4) waves.splice(i, 1);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
redraw.current = null;
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);
setWord.current = null;
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>
);
}
export default CipherRain;
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
13 propscolorstringColour of the near rain.default "#3ee6ff"default "#3ee6ff"depthColorstringColour of the far rain, deep in the haze.default "#5a5cff"default "#5a5cff"headColorstringColour of the white-hot heads.default "#effcff"default "#effcff"backgroundstringBackground colour.default "#020509"default "#020509"textstringA word the rain spells out in glyphs. Empty for none.default ""default ""densitynumberHow many columns are falling, 0 to 1.default 0.55default 0.55speednumberSpeed of the rain.default 1default 1glownumberStrength of the bloom around the heads.default 0.8default 0.8focusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.3default 0.3interactivebooleanCursor lens and click shockwave.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the rain.classNamestringSize it, e.g. h-screen w-full.