Components81 / 118
Bulge Gallery
A sideways project gallery whose photos bend with speed: drag or flick and they bulge into curved screens with a faint colour split, then pinch back for an instant as they stop. Each project resolves out of pixel blocks the first time it's in view, and pointing at a photo ripples a ring of pixels out from the cursor.
GalleryGalleryWebGLWebGLDragDragPixel revealPixel revealSquash & stretchSquash & stretchGSAPGSAP
Drag or flick sideways, fastPoint at a photo
Tweak
LIVELIVELook
#141414
Usage
Follows your tweaks.
usage.tsx
import { BulgeGallery } from "@/components/inreact/bulge-gallery";
const projects = [
{ title: "Cedar Cabin", label: "Project", tag: "Atelier North", image: "/work/cabin.jpg", href: "/work/cabin" },
{ title: "Maison Ora", label: "Project", tag: "Studio Lume", image: "/work/ora.jpg", href: "/work/ora" },
// ...
];
export function Work() {
return <BulgeGallery items={projects} height={520} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/bulge-gallery.jsonOr copy the source
Install the dependencies, then save this as components/inreact/bulge-gallery.tsx.
terminal
npm install gsap threecomponents/inreact/bulge-gallery.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useRef, useState } from "react";
/**
* Bulge Gallery: a sideways project gallery whose photos bend with speed.
*
* A row of projects on a dark page. Drag, flick or scroll it and every photo
* bulges into a curved screen (the faster it moves, the rounder it gets) with
* a faint colour split along the motion; when it stops it pinches back for an
* instant before settling flat, like a squash after a stretch. Each project
* resolves out of coarse pixel blocks the first time it comes into view, and
* pointing at a photo sends a ring of pixels rippling out from the cursor.
* WebGL (three) + GSAP.
*
* <BulgeGallery items={[{ title: "Cedar Cabin", label: "Project", tag: "Atelier N", image: "/cabin.jpg" }]} />
*/
export interface BulgeItem {
title: string;
/** Small label above the title. */
label?: string;
/** Small credit under the photo. */
tag?: string;
image: string;
href?: string;
}
export interface BulgeGalleryProps {
items: BulgeItem[];
height?: number;
/** Background colour. */
background?: string;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
const M = 1.16; // each quad is drawn larger than its photo, so the bulge has room
const VERT = /* glsl */ `
varying vec2 vUv;
void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`;
const FRAG = /* glsl */ `
precision highp float;
varying vec2 vUv;
uniform sampler2D uTex;
uniform vec2 uSize; // the photo's size, px
uniform float uTexAspect;
uniform float uBulge; // + bulges out with speed, - pinches as it stops
uniform float uSplit; // colour split along the motion
uniform float uPix; // pixel block size for the reveal, px (0 = sharp)
uniform vec2 uMouse; // cursor, in photo uv
uniform float uWave; // radius of the hover ripple, px (0 = none)
uniform float uFade;
vec2 cover(vec2 s) {
float pa = uSize.x / uSize.y;
vec2 sc = pa > uTexAspect ? vec2(1.0, uTexAspect / pa) : vec2(pa / uTexAspect, 1.0);
return (s - 0.5) * sc + 0.5;
}
vec4 tex(vec2 s) { return texture2D(uTex, cover(s)); }
void main() {
vec2 p = (vUv - 0.5) * ${M.toFixed(2)}; // photo space, -0.5..0.5 at rest
vec2 asp = vec2(uSize.x / uSize.y, 1.0);
vec2 pa = p * asp;
float r2 = dot(pa, pa) / dot(asp * 0.5, asp * 0.5);
// a curved screen: the sides bow out, the corners stay tucked
vec2 s = p * (1.0 + uBulge * 0.55 * r2) / (1.0 + uBulge * 0.55 * 0.5) + 0.5;
if (s.x < 0.0 || s.x > 1.0 || s.y < 0.0 || s.y > 1.0) { gl_FragColor = vec4(0.0); return; }
// soft rounded corners
vec2 q = abs(s - 0.5) * uSize - (uSize * 0.5 - 10.0);
float cr = length(max(q, 0.0)) - 10.0;
float a = clamp(0.5 - cr, 0.0, 1.0);
// pixel blocks: the reveal, and a ring rippling out from the cursor
float block = uPix;
vec2 px = s * uSize;
float ring = uWave > 0.0 ? exp(-pow((length(px - uMouse * uSize) - uWave) / 26.0, 2.0)) : 0.0;
block = max(block, ring * 18.0);
if (block > 1.5) s = (floor(px / block) + 0.5) * block / uSize;
vec2 off = vec2(uSplit, 0.0);
vec3 col = vec3(tex(s + off).r, tex(s).g, tex(s - off).b);
col += ring * 0.06;
gl_FragColor = vec4(col * a * uFade, a * uFade);
}`;
export function BulgeGallery({ items, height = 460, background = "#141414", className }: BulgeGalleryProps) {
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const labels = useRef<(HTMLDivElement | null)[]>([]);
const barRef = useRef<HTMLDivElement>(null);
const [W, setW] = useState(0);
const n = items.length;
useEffect(() => {
const el = rootRef.current;
if (!el) return;
const ro = new ResizeObserver(([e]) => setW(e.contentRect.width));
ro.observe(el);
return () => ro.disconnect();
}, []);
useEffect(() => {
const host = hostRef.current, root = rootRef.current;
if (!host || !root || !W || !n) return;
const still = reduced();
const H = height;
const cw = Math.round(clamp(160, 620, Math.min(W * 0.46, H * 0.5 * 1.45)));
const ch = Math.round(cw / 1.45);
const gap = Math.round(cw * 0.3);
const step = cw + gap;
const top = Math.round(H * 0.5 - ch * 0.5 + H * 0.02);
const span = (n - 1) * step;
const pr = Math.min(2, window.devicePixelRatio || 1);
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;pointer-events:none;";
host.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, alpha: true, premultipliedAlpha: true, antialias: true });
} catch {
canvas.remove();
return;
}
renderer.setPixelRatio(pr);
renderer.setSize(W, H, false);
renderer.setClearColor(0x000000, 0);
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(0, W, H, 0, -1, 1);
const loader = new THREE.TextureLoader();
const geo = new THREE.PlaneGeometry(cw * M, ch * M);
const planes = items.map((it) => {
const mat = new THREE.ShaderMaterial({
vertexShader: VERT,
fragmentShader: FRAG,
transparent: true,
depthTest: false,
blending: THREE.CustomBlending,
blendSrc: THREE.OneFactor,
blendDst: THREE.OneMinusSrcAlphaFactor,
uniforms: {
uTex: { value: null },
uSize: { value: new THREE.Vector2(cw, ch) },
uTexAspect: { value: 1.5 },
uBulge: { value: 0 },
uSplit: { value: 0 },
uPix: { value: 48 },
uMouse: { value: new THREE.Vector2(-9, -9) },
uWave: { value: 0 },
uFade: { value: 0 },
},
});
loader.load(it.image, (t) => {
t.colorSpace = THREE.SRGBColorSpace;
t.minFilter = THREE.LinearFilter;
t.generateMipmaps = false;
mat.uniforms.uTex.value = t;
mat.uniforms.uTexAspect.value = t.image.width / t.image.height;
});
const mesh = new THREE.Mesh(geo, mat);
scene.add(mesh);
return { mesh, mat, seen: false, hov: 0, wave: { r: 0 } };
});
// scroll: x is the gallery offset, with inertia and a spring at the ends
const st = { x: 0, v: 0, target: 0, drag: false, bend: 0, vbend: 0, lastX: 0, vel: 0 };
let hover = -1;
const lastLabel = items.map(() => "");
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
const h = dt / 2;
for (let i = 0; i < 2; i++) {
if (!st.drag) {
if (still) st.x = st.target;
else {
const k = 42, c = 2 * 0.95 * Math.sqrt(k);
st.v += (k * (st.target - st.x) - c * st.v) * h;
st.x += st.v * h;
}
}
}
// speed, frame to frame (drags move x between frames, so measure across them)
const raw = (st.x - st.lastX) / Math.max(dt, 1e-3);
st.lastX = st.x;
st.vel += (raw - st.vel) * 0.35;
const vel = st.vel; // px/s
// the bend follows speed, and overshoots past flat when it stops (a squash)
const want = still ? 0 : clamp(0, 0.6, Math.abs(vel) * 0.00035);
const kb = 160, cb = 2 * 0.3 * Math.sqrt(kb);
st.vbend += (kb * (want - st.bend) - cb * st.vbend) * dt;
st.bend += st.vbend * dt;
const split = still ? 0 : clamp(-0.012, 0.012, vel * 0.0000075);
const cx0 = W * 0.5 - cw * 0.5;
planes.forEach((pl, k) => {
const x = cx0 + k * step - st.x;
const visible = x + cw > -cw * 0.3 && x < W + cw * 0.3;
pl.mesh.visible = visible;
pl.mesh.position.set(x + cw / 2, H - (top + ch / 2), 0);
const u = pl.mat.uniforms;
u.uBulge.value = st.bend;
u.uSplit.value = split;
// first time in view: resolve out of pixel blocks
if (visible && !pl.seen && u.uTex.value) {
pl.seen = true;
if (still) {
u.uPix.value = 0;
u.uFade.value = 1;
} else {
const o = { p: 48, f: 0 };
gsap.to(o, {
p: 0,
f: 1,
duration: 0.7,
ease: "steps(6)",
onUpdate: () => {
u.uPix.value = o.p;
u.uFade.value = Math.min(1, o.f * 1.6);
},
});
}
}
u.uWave.value = pl.wave.r;
const lab = labels.current[k];
if (lab) {
const key = `${x.toFixed(1)}|${visible}`;
if (key !== lastLabel[k]) {
lab.style.transform = `translate3d(${x.toFixed(1)}px,${top}px,0)`;
lab.style.visibility = visible ? "visible" : "hidden";
lastLabel[k] = key;
}
}
});
if (barRef.current) barRef.current.style.transform = `scaleX(${span ? clamp(0.05, 1, (st.x + step * 0.5) / (span + step * 0.5)).toFixed(4) : 1})`;
renderer.render(scene, camera);
};
gsap.ticker.add(tick);
const local = (e: { clientX: number; clientY: number }) => {
const r = root.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const which = (q: { x: number; y: number }) => {
const cx0 = W * 0.5 - cw * 0.5;
for (let k = 0; k < n; k++) {
const x = cx0 + k * step - st.x;
if (q.x >= x && q.x <= x + cw && q.y >= top && q.y <= top + ch) return { k, u: (q.x - x) / cw, v: 1 - (q.y - top) / ch };
}
return null;
};
// drag / flick
let sx = 0, s0 = 0, lx = 0, lt = 0, moved = 0, id = -1, vv = 0;
const onDown = (e: PointerEvent) => {
if (e.button !== 0) return;
id = e.pointerId;
st.drag = true;
sx = lx = e.clientX;
s0 = st.x;
lt = performance.now();
moved = 0;
vv = 0;
};
const onMove = (e: PointerEvent) => {
const q = local(e);
const hit = which(q);
const k = hit ? hit.k : -1;
if (k !== hover) {
hover = k;
// a ring of pixels ripples out from where you came in
if (hit && !still) {
const pl = planes[k];
gsap.killTweensOf(pl.wave);
pl.wave.r = 1;
gsap.to(pl.wave, { r: Math.hypot(cw, ch), duration: 0.9, ease: "power2.out", onComplete: () => void (pl.wave.r = 0) });
}
}
if (hit) planes[hit.k].mat.uniforms.uMouse.value.set(hit.u, hit.v);
if (e.pointerId !== id || !st.drag) return;
const dx = e.clientX - sx;
moved = Math.max(moved, Math.abs(dx));
if (moved > 4 && !root.hasPointerCapture(e.pointerId)) {
try {
root.setPointerCapture(e.pointerId);
} catch {
/* capture is a nicety */
}
}
const now = performance.now();
vv = vv * 0.6 + (-(e.clientX - lx) / Math.max(1, now - lt)) * 1000 * 0.4;
lx = e.clientX;
lt = now;
let x = s0 - dx;
if (x < 0) x = -Math.pow(-x, 0.8);
if (x > span) x = span + Math.pow(x - span, 0.8);
st.x = x;
st.target = x;
};
const snap = (x: number) => clamp(0, span, Math.round(x / step) * step);
const onUp = (e: PointerEvent) => {
if (e.pointerId !== id) return;
id = -1;
if (!st.drag) return;
st.drag = false;
st.v = vv;
if (moved < 5) {
const hit = which(local(e));
if (hit) {
const it = items[hit.k];
if (it.href) window.location.href = it.href;
else st.target = snap(hit.k * step);
}
return;
}
st.target = snap(st.x + vv * 0.32);
};
const onLeave = () => {
hover = -1;
};
// the wheel scrolls the gallery while you're over it, and lets the page go at the ends
let wheelEnd = 0;
const onWheel = (e: WheelEvent) => {
const d = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY;
const next = clamp(0, span, st.target + d);
if (next === st.target && Math.abs(e.deltaX) <= Math.abs(e.deltaY)) return; // at an end: let the page scroll
e.preventDefault();
st.target = next;
window.clearTimeout(wheelEnd);
wheelEnd = window.setTimeout(() => void (st.target = snap(st.target)), 140);
};
const onKey = (e: KeyboardEvent) => {
if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return;
e.preventDefault();
st.target = snap(st.target + (e.key === "ArrowRight" ? step : -step));
};
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerup", onUp);
root.addEventListener("pointercancel", onUp);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("wheel", onWheel, { passive: false });
root.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
window.clearTimeout(wheelEnd);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("pointercancel", onUp);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("wheel", onWheel);
root.removeEventListener("keydown", onKey);
planes.forEach((pl) => {
gsap.killTweensOf(pl.wave);
pl.mat.uniforms.uTex.value?.dispose();
pl.mat.dispose();
});
geo.dispose();
renderer.dispose();
canvas.remove();
};
}, [W, height, n, items]);
const H = height;
const cw = Math.round(clamp(160, 620, Math.min(W * 0.46, H * 0.5 * 1.45)));
const ch = Math.round(cw / 1.45);
return (
<div
ref={rootRef}
tabIndex={0}
role="region"
aria-roledescription="carousel"
aria-label="Projects"
className={["relative w-full cursor-grab touch-pan-y overflow-hidden outline-none select-none active:cursor-grabbing", className].filter(Boolean).join(" ")}
style={{ height, background }}
>
<div ref={hostRef} aria-hidden="true" className="absolute inset-0" />
{/* titles ride with their photos */}
{W > 0 &&
items.map((it, k) => (
<div key={k} ref={(el) => void (labels.current[k] = el)} className="pointer-events-none absolute top-0 left-0 will-change-transform" style={{ width: cw, height: ch }}>
{/* type is sized from the photo, so it scales with the gallery */}
<div className="absolute left-0 -translate-x-[14%] -translate-y-full whitespace-nowrap" style={{ top: -cw * 0.012 }}>
{it.label && <div className="tracking-[0.06em] text-white/45" style={{ fontSize: Math.max(8, cw * 0.028) }}>{it.label}</div>}
<div className="leading-tight font-medium tracking-[-0.02em] text-white" style={{ fontSize: clamp(12, 30, cw * 0.07) }}>
{it.title}
</div>
</div>
{it.tag && (
<div className="absolute right-0 translate-y-full tracking-[0.12em] text-white/55 uppercase" style={{ bottom: -cw * 0.02, fontSize: Math.max(8, cw * 0.026) }}>
{it.tag}
</div>
)}
<a href={it.href ?? "#"} className="sr-only" onClick={(e) => !it.href && e.preventDefault()}>
{it.title}
</a>
</div>
))}
{/* how far along you are */}
<div className="pointer-events-none absolute bottom-5 left-5 h-px w-[90px] bg-white/15">
<div ref={barRef} className="h-full w-full origin-left bg-white/70" />
</div>
</div>
);
}
export default BulgeGallery;
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
4 propsitems{ title: string; label?: string; tag?: string; image: string; href?: string }[]The projects.heightnumberHeight, px.default 460default 460backgroundstringBackground colour.default "#141414"default "#141414"classNamestringExtra classes.