Components62 / 118
Drift Field
Fly through a field of your work. Image tiles float in deep space around a clear centre; the camera drifts forward, so each tile appears small in the distance, grows as it comes closer, slides out toward the edges and streaks with motion blur as it passes, endlessly. Scrolling pushes the flight faster (scroll back and it reverses), the cursor steers the view and the tile under it lifts.
Fly-throughFly-throughThree.jsThree.jsMotion blurMotion blurScroll pushScroll pushHeroHeroGSAPGSAP
Steer with the cursorScroll to fly faster
Tweak
LIVELIVEFlight
1.6
1.0
Look
1.00
Usage
Follows your tweaks.
usage.tsx
import { DriftField } from "@/components/inreact/drift-field";
const tiles = [
{ src: "/work/01.jpg" },
{ src: "/work/02.jpg", aspect: 1.6 },
// ...10-30 images; or { draw: (ctx, w, h) => { ... }, aspect } to paint one
];
export function Hero() {
return (
<DriftField tiles={tiles} className="h-[85vh] bg-black">
{/* optional: anything here sits in the clear centre */}
</DriftField>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/drift-field.jsonOr copy the source
Install the dependencies, then save this as components/inreact/drift-field.tsx.
terminal
npm install gsap threecomponents/inreact/drift-field.tsx
"use client";
import { gsap } from "gsap";
import * as THREE from "three";
import { useEffect, useRef, type ReactNode } from "react";
/**
* Drift Field: fly through a field of your work.
*
* Image tiles float in deep space around a clear centre. The camera drifts
* forward through them: each tile appears small in the distance, grows as it
* comes closer, slides out toward the edges and streaks with motion blur as it
* passes. Scrolling the page speeds the flight up (scroll back and it
* reverses), the cursor steers the view, and the tile under it lifts. Tiles
* recycle endlessly. Three.js + GSAP.
*
* <DriftField tiles={[{ src: "/work/01.jpg" }, { src: "/work/02.jpg", aspect: 1.6 }, ...]} className="h-[80vh]">
* <h1>Your work, made to move</h1> // optional, sits in the clear centre
* </DriftField>
*/
export interface DriftTile {
src?: string;
/** Or paint the face yourself (canvas is 512 px wide, height from aspect). */
draw?: (ctx: CanvasRenderingContext2D, w: number, h: number) => void;
/** Width / height. Defaults to the image's own, or 0.8 for drawn tiles. */
aspect?: number;
alt?: string;
}
export interface DriftFieldProps {
tiles: DriftTile[];
/** Cruising speed (world units per second). */
speed?: number;
/** How strongly page scrolling pushes the flight. */
scrollBoost?: number;
/** Motion blur on fast, close tiles (0 = off). */
blur?: number;
/** Optional content in the clear centre (a headline). */
children?: ReactNode;
onSelect?: (tile: DriftTile, index: number) => void;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const smooth = (a: number, b: number, x: number) => {
const t = Math.min(1, Math.max(0, (x - a) / (b - a)));
return t * t * (3 - 2 * t);
};
const VERT = /* glsl */ `
varying vec2 vUv;
void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }
`;
// the tile, with a soft radial streak when it rushes past, and rounded corners
const FRAG = /* glsl */ `
precision highp float;
uniform sampler2D uMap;
uniform sampler2D uRound;
uniform float uOpacity;
uniform float uBlur; // streak length, in uv
uniform vec2 uDir; // streak direction (screen-radial), in uv
uniform float uLift;
varying vec2 vUv;
void main() {
vec3 c = vec3(0.0);
float wsum = 0.0;
for (int i = 0; i < 7; i++) {
float t = float(i) / 6.0 - 0.5;
float w = 1.0 - abs(t) * 1.2;
c += texture2D(uMap, clamp(vUv + uDir * t * uBlur, 0.0, 1.0)).rgb * w;
wsum += w;
}
c /= wsum;
c *= 1.0 + uLift * 0.12;
float a = texture2D(uRound, vUv).r * uOpacity;
gl_FragColor = vec4(c, a);
#include <colorspace_fragment>
}
`;
function roundTex(w: number, h: number, r: number) {
const c = document.createElement("canvas");
c.width = w;
c.height = h;
const g = c.getContext("2d")!;
g.fillStyle = "#000";
g.fillRect(0, 0, w, h);
g.fillStyle = "#fff";
g.beginPath();
g.roundRect(1, 1, w - 2, h - 2, r);
g.fill();
const t = new THREE.CanvasTexture(c);
t.colorSpace = THREE.NoColorSpace;
return t;
}
export function DriftField({ tiles, speed = 1.6, scrollBoost = 1, blur = 1, children, onSelect, className }: DriftFieldProps) {
const rootRef = useRef<HTMLDivElement>(null);
const hostRef = useRef<HTMLDivElement>(null);
const cb = useRef(onSelect);
cb.current = onSelect;
const n = tiles.length;
const key = tiles.map((t, i) => t.src ?? `draw${i}`).join(",");
useEffect(() => {
const root = rootRef.current, host = hostRef.current;
if (!root || !host || n === 0) return;
const still = reduced();
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;";
host.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
} catch {
canvas.remove();
return;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(55, 1, 0.1, 60);
camera.position.set(0, 0, 5);
const aniso = renderer.capabilities.getMaxAnisotropy();
// the field: depth from FAR (appears) to NEAR (passes the camera)
const FAR = -9, NEAR = 4.6, SPAN = NEAR - FAR;
const round = roundTex(256, 256, 18);
const geo = new THREE.PlaneGeometry(1, 1);
type T = { mesh: THREE.Mesh; mat: THREE.ShaderMaterial; tex: THREE.Texture; idx: number; aspect: number; size: number; x: number; y: number; z: number; rx: number; ry: number; lift: number };
// how many tiles fly at once (repeating the set if it's small)
const COUNT = Math.max(30, n);
const rand = (a: number, b: number) => a + Math.random() * (b - a);
// somewhere around the centre, leaving the middle clear
const placeXY = (t: T) => {
for (let k = 0; k < 20; k++) {
const x = rand(-5.6, 5.6), y = rand(-3.3, 3.3);
if (Math.abs(x) < 1.6 && Math.abs(y) < 0.75) continue;
t.x = x;
t.y = y;
return;
}
t.x = 3;
t.y = 2;
};
const textures: { tex: THREE.Texture; aspect: number }[] = tiles.map((tile) => {
if (tile.draw) {
const aspect = tile.aspect ?? 0.8;
const c = document.createElement("canvas");
c.width = 512;
c.height = Math.round(512 / aspect);
tile.draw(c.getContext("2d")!, c.width, c.height);
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
tex.anisotropy = aniso;
return { tex, aspect };
}
const entry = { tex: new THREE.Texture(), aspect: tile.aspect ?? 1 };
new THREE.TextureLoader().load(tile.src!, (t) => {
t.colorSpace = THREE.SRGBColorSpace;
t.anisotropy = aniso;
const img = t.image as { width: number; height: number };
if (!tile.aspect) entry.aspect = img.width / img.height;
entry.tex = t;
for (const f of field) if (f.idx % n === tiles.indexOf(tile)) {
f.mat.uniforms.uMap.value = t;
f.aspect = entry.aspect;
}
});
return entry;
});
const field: T[] = [];
for (let i = 0; i < COUNT; i++) {
const src = textures[i % n];
const mat = new THREE.ShaderMaterial({
vertexShader: VERT,
fragmentShader: FRAG,
transparent: true,
depthWrite: false,
uniforms: {
uMap: { value: src.tex },
uRound: { value: round },
uOpacity: { value: 0 },
uBlur: { value: 0 },
uDir: { value: new THREE.Vector2(1, 0) },
uLift: { value: 0 },
},
});
const mesh = new THREE.Mesh(geo, mat);
const t: T = { mesh, mat, tex: src.tex, idx: i, aspect: src.aspect, size: rand(1.0, 1.85), x: 0, y: 0, z: FAR + (i / COUNT) * SPAN, rx: rand(-0.25, 0.25), ry: rand(-0.35, 0.35), lift: 0 };
placeXY(t);
scene.add(mesh);
field.push(t);
}
const resize = () => {
const r = host.getBoundingClientRect();
renderer.setSize(Math.max(1, r.width), Math.max(1, r.height), false);
camera.aspect = Math.max(1, r.width) / Math.max(1, r.height);
// narrow boxes: widen the view so the field still surrounds the centre
camera.fov = camera.aspect < 1 ? 70 : 55;
camera.updateProjectionMatrix();
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(host);
// speed: cruising, plus a push from page scrolling that decays with inertia
const st = { v: still ? 0 : speed, push: 0 };
let lastY = window.scrollY;
const onScroll = () => {
const dy = window.scrollY - lastY;
lastY = window.scrollY;
if (!still) st.push = Math.max(-14, Math.min(14, st.push + dy * 0.02 * scrollBoost));
};
window.addEventListener("scroll", onScroll, { passive: true });
// a wheel over the field pushes it too (without stopping the page from scrolling)
const onWheel = (e: WheelEvent) => {
if (!still) st.push = Math.max(-14, Math.min(14, st.push + e.deltaY * 0.012 * scrollBoost));
};
root.addEventListener("wheel", onWheel, { passive: true });
// the cursor steers the view; the tile under it lifts
const look = { x: 0, y: 0 };
const lx = gsap.quickTo(look, "x", { duration: 1.2, ease: "power3.out" });
const ly = gsap.quickTo(look, "y", { duration: 1.2, ease: "power3.out" });
const ndc = new THREE.Vector2(9, 9);
const ray = new THREE.Raycaster();
let hovered: T | null = null;
const onMove = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
ndc.set(((e.clientX - r.left) / r.width) * 2 - 1, -(((e.clientY - r.top) / r.height) * 2 - 1));
if (!still) {
lx(ndc.x);
ly(ndc.y);
}
};
const onLeave = () => {
ndc.set(9, 9);
lx(0);
ly(0);
};
const onClick = () => {
if (hovered) cb.current?.(tiles[hovered.idx % n], hovered.idx % n);
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("click", onClick);
let visible = true;
const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting));
io.observe(root);
const proj = new THREE.Vector3();
const tick = (_t: number, dms: number) => {
const dt = Math.min(0.05, dms / 1000);
if (!visible) return;
st.push *= Math.exp(-dt * 1.6);
const v = (still ? 0 : speed) + st.push;
camera.position.x = look.x * 0.6;
camera.position.y = look.y * 0.35;
camera.lookAt(look.x * 0.25, look.y * 0.15, -10);
hovered = null;
if (ndc.x < 2) {
ray.setFromCamera(ndc, camera);
const hit = ray.intersectObjects(field.map((f) => f.mesh), false)[0];
if (hit) hovered = field.find((f) => f.mesh === hit.object) ?? null;
}
for (const t of field) {
t.z += v * dt;
// recycle: out past the camera -> back into the distance (and the other way when reversing)
if (t.z > NEAR) {
t.z -= SPAN;
placeXY(t);
} else if (t.z < FAR) {
t.z += SPAN;
placeXY(t);
}
const near = 1 - smooth(NEAR - 1.4, NEAR, t.z);
const far = smooth(FAR, FAR + 3, t.z);
t.lift += ((t === hovered ? 1 : 0) - t.lift) * Math.min(1, dt * 8);
const s = t.size * (1 + t.lift * 0.06);
t.mesh.position.set(t.x, t.y, t.z);
t.mesh.scale.set(s * Math.sqrt(t.aspect), s / Math.sqrt(t.aspect), 1);
t.mesh.rotation.set(t.rx * 0.4, t.ry * 0.4, 0);
const u = t.mat.uniforms;
u.uOpacity.value = near * far;
u.uLift.value = t.lift;
// motion blur: radial on screen, stronger when fast and close
proj.set(t.x, t.y, t.z).project(camera);
const len = Math.hypot(proj.x, proj.y) || 1;
u.uDir.value.set(proj.x / len, proj.y / len);
const closeness = smooth(-4, NEAR, t.z);
u.uBlur.value = still ? 0 : Math.min(0.09, Math.abs(v) * 0.012 * closeness * closeness * blur);
t.mesh.renderOrder = Math.round((t.z - FAR) * 100);
}
renderer.render(scene, camera);
root.style.cursor = hovered && cb.current ? "pointer" : "";
};
gsap.ticker.add(tick);
return () => {
gsap.ticker.remove(tick);
window.removeEventListener("scroll", onScroll);
root.removeEventListener("wheel", onWheel);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("click", onClick);
io.disconnect();
ro.disconnect();
field.forEach((t) => t.mat.dispose());
textures.forEach((t) => t.tex.dispose());
round.dispose();
geo.dispose();
renderer.dispose();
canvas.remove();
};
// tiles are read once per set; rebuild when they change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key, speed, scrollBoost, blur]);
return (
<div ref={rootRef} role="img" aria-label="A field of images drifting toward you" className={["relative h-full w-full overflow-hidden", className].filter(Boolean).join(" ")}>
<div ref={hostRef} className="absolute inset-0" />
{children && <div className="pointer-events-none absolute inset-0 grid place-items-center">{children}</div>}
</div>
);
}
export default DriftField;
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
7 propstiles{ src?; draw?; aspect?; alt? }[]The tiles: images (any shape), or draw(ctx, w, h) to paint one.speednumberCruising speed.default 1.6default 1.6scrollBoostnumberHow strongly page scrolling pushes the flight.default 1default 1blurnumberMotion blur on fast, close tiles (0 = off).default 1default 1childrenReactNodeOptional content in the clear centre (a headline).onSelect(tile, index) => voidCalled when a tile is clicked.classNamestringGive it a height.