Skip to content
motionprompts motionprompts

Grid Deformation Effect

WebGL animation component · Published 2026-07-21 · by vanguardia.dev

Open live demo ↗ Download source

What it does

A fullscreen hero photograph is rendered as a Three.js texture on a shader plane; moving the pointer injects velocity into a 25-cell grid DataTexture that displaces the UVs with RGB chromatic aberration, and the distortion relaxes back smoothly (0.925/frame) when the cursor stops. Styled as the landing page of Moiré, a dance and digital-image festival: the photo is monochrome, so the aberration is the only color on the page.

How it's built

Category3d-webgl
Techthree
Complexitysection
Performance costheavy
Mobile-safedesktop-first

three-js webgl shader video mouse distortion grid chromatic-aberration hover

How it works

A full-screen photograph that behaves like a soft material. Sweep the cursor across it and the image is dragged along with the gesture, block by block, pixels smearing in the direction of the swipe with a faint red and blue fringe along the edges of the push. Stop, and the picture slowly springs back until it is perfectly still and undistorted again.

It is built with Three.js alone. There is no animation library: the motion is a small physics step that runs on every frame.

A deformation field with memory

The key idea is that the distortion is not computed from the cursor directly. It is stored. Behind the image sits a tiny texture, a coarse grid of cells covering the screen, where each cell holds a horizontal and a vertical push. Think of it as a map of how far each part of the picture has been shoved.

Every frame two things happen to that map. First, every cell loses a fraction of its push, which is the relaxation that makes the image return to rest. Then the cursor writes into it: all the cells within a soft brush around the pointer receive the pointer's current velocity, strongest at the centre of the brush and fading towards its edge. A slow movement writes almost nothing; a fast flick writes a strong push that lingers and fades over a fraction of a second. The velocity itself also decays between mouse events, so a flick finishes cleanly instead of stopping dead.

What the shader does

The fragment shader reads the field at each pixel and shifts where it samples the photograph by that amount, so the image is dragged locally. The field texture is read without smoothing, which is what keeps the cells as visible blocks rather than a liquid blur. To add the chromatic fringe, the red, green and blue channels are sampled at slightly different offsets along the same push, so colour separates exactly where the image moves and nowhere else.

Where it gets hard

The feel comes from balancing two decays against the brush: how fast the field relaxes and how fast the input velocity fades. Too slow and the image turns to mush; too fast and it looks like a glitch rather than a material. The field must also be rebuilt when the viewport changes shape, so the cells stay square and the brush keeps the same size relative to the screen.

Performance and mobile

The GPU work is light: one quad and three texture reads per pixel. The CPU work is a loop over a small grid every frame, which is negligible. The effect is pointer-driven, so on touch screens the photo simply sits still and sharp, which is a reasonable fallback. A photograph with strong edges and detail shows the drag and the fringing best; flat images hide it.

Rebuild it with AI

This component's prompt is part of the paid library. Below you can read how it starts; the full prompt, the exact structure, timing and easing an AI agent needs to rebuild the effect, unlocks with any paid plan, yearly or lifetime.

# Grid Deformation Hover Effect (WebGL mouse-velocity image distortion)
## Goal
Build a full-screen hero that shows a single background image, but the image is not a plain
`<img>` — it is rendered onto a **Three.js shader plane**. Moving the pointer over the hero injects
**velocity** into a coarse grid of cells stored in a `DataTexture`; each cell's accumulated push
**displaces the image UVs** locally, dragging the pixels in the direction of the swipe, with a
subtle **RGB chromatic-aberration split** along the displacement. When the cursor stops, the whole
field **relaxes back to rest smoothly** (a per-cell decay of `0.925`/frame), so the image un-warps
on its own. The star of this piece is the grid-based UV displacement shader + the mouse-velocity
physics — there is no DOM animation and nothing scrolls.
## Tech
- Vanilla HTML / CSS / JS with ES module imports, bundled by Vite.
…

Premium prompt

Unlock this prompt, and every other one

From $99/year, or $139 once for lifetime access. Commercial license included.

See pricing Or start with the free set Already bought? Sign in

New components in your inbox

One email a week, only when new components ship, each with its live demo and prompt.