Halftone Drift
A fine grid of round dots on a warm near-black, each dot's size and brightness following a soft, cloudy light that pools across the top and down one side and thins into sparse specks below, like a photograph of haze screened for print. The clouds never stop drifting. Your cursor is a light that swells the dots under it and bulges them like a lens, a click sends a ring of light through the grid, and scrolling rushes the clouds as the light sinks down the page.
Tweak
LIVELIVEColour
Screen
Motion
Interactive
The cursor is a light that swells the dots, clicks send a ring
Usage
Follows your tweaks.
import { HalftoneDrift } from "@/components/inreact/halftone-drift";
export function Hero() {
return (
<HalftoneDrift
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the dots */}
</HalftoneDrift>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/halftone-drift.jsonOr copy the source
Install the dependencies, then save this as components/inreact/halftone-drift.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);
/**
* Halftone Drift: a field of light printed as a halftone, always drifting.
*
* A fine grid of round dots on a warm near-black. Each dot's size and
* brightness follow a soft, cloudy light that pools across the top and down
* one side and thins into sparse specks below, like a photograph of haze
* screened for print. The light never stops moving: slow clouds drift
* through the screen and the dots swell and shrink as they pass.
*
* It reacts: your cursor is a light, and the dots under it swell and bulge
* away like a lens; a click sends a ring of light out through the grid;
* scrolling flows the clouds faster and lets the light sink down the page.
* On load the dots print in, sweeping down from the top.
*
* <HalftoneDrift className="h-screen w-full">
* <YourHero />
* </HalftoneDrift>
*
* WebGL: one shader draws the dots from a noise light field, then a soft
* bloom at 1/4 and 1/16 size. GSAP drives every motion. Pauses off-screen;
* reduced motion shows a still frame; a CSS dot pattern without WebGL.
*/
export interface HalftoneDriftProps {
/** Background colour. */
background?: string;
/** Colour of the brightest dots. */
dot?: string;
/** Colour of the cursor's light (the dots under it take it on). */
light?: string;
/** Dot pitch, in px at 1000px tall (scales with the height). */
pitch?: number;
/** How much light there is in the field. */
intensity?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the drifting clouds. */
speed?: number;
/** Cursor light, click ripples. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the dots. */
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 SCENE = `
precision highp float;
uniform vec2 uRes, uMouse, uPulseC;
uniform float uPitch, uTime, uFlow, uSink, uIn, uHover, uPulse, uPulseAmp, uIntensity;
uniform vec3 uBg, uDot, uLight;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float vnoise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(i), hash(i + vec2(1, 0)), f.x), mix(hash(i + vec2(0, 1)), hash(i + vec2(1, 1)), f.x), f.y);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 4; i++) {
v += a * vnoise(p);
p = p * 2.03 + vec2(17.1, 9.3);
a *= 0.5;
}
return v;
}
// the light the dots print: bright across the top, a soft band down the left, thinning to specks below,
// broken into slow drifting clouds
vec2 field(vec2 q) {
// the edge where the light gives out is ragged, and it drifts too
float y = q.y + uSink + (fbm(q * 1.7 + vec2(uFlow * 0.35, 3.0)) - 0.5) * 0.2;
float top = 1.0 - smoothstep(0.42, 0.86, y);
float band = exp(-q.x * q.x / 0.018) * smoothstep(0.12, 0.3, y) * (1.0 - smoothstep(0.55, 0.66, y));
vec2 fl = vec2(uFlow * 0.6, -uFlow * 0.25);
float n = fbm(q * 2.6 + fl);
float m = fbm(q * 6.0 - fl * 1.7 + 4.0);
float v = top * (0.55 + 0.75 * (n - 0.5)) + band * 0.7 + (m - 0.5) * 0.28;
// a faint scatter of light survives in the dark below
v += 0.12 * smoothstep(0.55, 0.85, m) * smoothstep(0.5, 0.9, y);
return vec2(v, band);
}
void main() {
vec2 px = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y);
float P = uPitch;
// the cursor's lens: dots near it bulge outward
vec2 dm = px - uMouse;
float md = length(dm);
float lens = exp(-md * md / (uRes.y * uRes.y * 0.012)) * uHover;
vec2 dp = px - uPulseC;
float pd = length(dp);
float ringR = uPulse * uRes.y * 1.3;
float ring = exp(-pow((pd - ringR) / (P * 3.0), 2.0)) * uPulseAmp;
vec2 sp = px - dm * lens * 0.18 - (dp / max(pd, 1.0)) * ring * P * 0.8;
vec2 cell = floor(sp / P);
vec2 cc = (cell + 0.5) * P;
vec2 q = cc / uRes.y;
vec2 fb = field(q);
float v = fb.x * uIntensity;
// the cursor is a light; the ring of a click passes through as a band of light
float cl = exp(-dot(cc - uMouse, cc - uMouse) / (uRes.y * uRes.y * 0.02)) * uHover;
v += cl * 0.55 + ring * 0.5;
// on load the dots print in, sweeping down from the top
float rev = smoothstep(q.y * 0.9 + hash(cell) * 0.12, q.y * 0.9 + hash(cell) * 0.12 + 0.18, uIn * 1.3);
v *= rev;
// in the dark, dots drop out one by one rather than all fading together
float h = hash(cell + 3.1);
float on = smoothstep(h * 0.32, h * 0.32 + 0.04, v);
v = clamp(v, 0.0, 1.0);
// dot area follows the light; the brightest dots are white, faint ones grey
float r = P * 0.5 * pow(v, 0.62) * 0.98;
float d = length(sp - cc);
float aa = 0.9;
float dotm = (1.0 - smoothstep(r - aa, r + aa * 0.4, d)) * on;
// the side band prints big, soft grey dots rather than bright ones
vec3 dc = uDot * (0.42 + 0.6 * pow(v, 0.7)) * (1.0 - 0.32 * fb.y);
dc = mix(dc, uLight * (0.5 + 0.6 * v), clamp(cl * 1.2, 0.0, 0.7));
vec3 col = mix(uBg, dc, dotm);
gl_FragColor = vec4(col, 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.55, 0.95, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
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.45 + texture2D(uWide, vUv).rgb * 0.6;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.9, 0.0) * 1.2);
col = min(col, vec3(1.0));
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 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 HalftoneDrift({
background = "#201c1b",
dot = "#e6e4e2",
light = "#fff1dc",
pitch = 11.7,
intensity = 1,
glow = 0.35,
speed = 1,
interactive = true,
scroller,
children,
className,
}: HalftoneDriftProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ background, dot, light, pitch, intensity, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { background, dot, light, pitch, intensity, glow, speed, interactive };
redraw.current?.();
}, [background, dot, light, pitch, 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, ${p.dot} 1.4px, transparent 1.8px) 0 0 / 10px 10px, linear-gradient(${p.background}00, ${p.background} 70%), ${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.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", "uMouse", "uPulseC", "uPitch", "uTime", "uFlow", "uSink", "uIn", "uHover", "uPulse", "uPulseAmp", "uIntensity", "uBg", "uDot", "uLight"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
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);
};
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, hover: 0, mx: -1e4, my: -1e4, pulse: 0, pulseAmp: 0, pcx: 0, pcy: 0, sink: 0, rush: 0 };
let time = 0, flow = 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;
const p = props.current;
const X = T;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, X.scene.w, X.scene.h);
gl.uniform2f(US.uMouse, s.mx * dpr, s.my * dpr);
gl.uniform2f(US.uPulseC, s.pcx * dpr, s.pcy * dpr);
gl.uniform1f(US.uPitch, Math.max(4 * dpr, (p.pitch / 1000) * X.scene.h));
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uFlow, flow);
gl.uniform1f(US.uSink, s.sink);
gl.uniform1f(US.uIn, s.in);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uPulse, s.pulse);
gl.uniform1f(US.uPulseAmp, s.pulseAmp);
gl.uniform1f(US.uIntensity, p.intensity);
gl.uniform3fv(US.uBg, rgb(p.background));
gl.uniform3fv(US.uDot, rgb(p.dot));
gl.uniform3fv(US.uLight, rgb(p.light));
drawQuad(sceneProg);
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);
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);
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 dots print in, sweeping down from the top ----
const intro = gsap.to(s, { in: 1, duration: 2.4, ease: "power2.inOut", delay: 0.1 });
// ---- cursor: a light that swells the dots under it and bulges them like a lens ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.45, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.45, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.6, ease: "power2" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
let first = true;
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);
hoverTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: a ring of light runs out through the grid ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
s.pcx = p.x;
s.pcy = p.y;
gsap.killTweensOf(s, "pulse,pulseAmp");
gsap.fromTo(s, { pulse: 0 }, { pulse: 1, duration: 1.7, ease: "power2.out" });
gsap.fromTo(s, { pulseAmp: 1 }, { pulseAmp: 0, duration: 1.7, ease: "power1.in" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the clouds rush with the scroll and the light sinks down the page ----
const sinkTo = gsap.quickTo(s, "sink", { duration: 1, ease: "power3" });
const rushTo = gsap.quickTo(s, "rush", { duration: 0.5, ease: "power2" });
const calm = gsap.delayedCall(0.2, () => rushTo(0)).pause();
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
sinkTo(-(self.progress - 0.5) * 0.35);
rushTo(Math.min(4, Math.abs(self.getVelocity()) / 600));
calm.restart(true);
},
});
// ---- loop, only while on screen: the clouds drift on their own ----
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;
flow += dt * props.current.speed * (0.06 + s.rush * 0.1);
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();
calm.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
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>
);
}
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 propsbackgroundstringBackground colour.default "#201c1b"default "#201c1b"dotstringColour of the brightest dots.default "#e6e4e2"default "#e6e4e2"lightstringColour of the cursor's light (the dots under it take it on).default "#fff1dc"default "#fff1dc"pitchnumberDot pitch, in px at 1000px tall (scales with the height).default 11.7default 11.7intensitynumberHow much light there is in the field.default 1default 1glownumberStrength of the bloom.default 0.35default 0.35speednumberSpeed of the drifting clouds.default 1default 1interactivebooleanCursor light and click ripples.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the dots.classNamestringSize it, e.g. h-screen w-full.