Facemorph: the maths of cutting a face

We live in an era where a convincing face on a screen proves almost nothing. A boardroom call features an executive who looks remarkably like the real thing until they ask for an urgent wire transfer; a political clip circulates fast enough to outrun a fact-check; a polished profile photo belongs to someone—or something—that has never breathed oxygen. Legitimacy used to borrow trust from a face. Now a face often borrows trust from a model.

Portrait of a serious man in a black suit and tie against a tiled gray background

That made a contrarian premise irresistible for a weekend build: instead of asking a model to invent a plausible face, take a real one, slice it into shifting rectangles, and make it earn its way back together when everything goes still.

Three years ago, I tried coding this exact mechanic and interface by hand—and got nowhere. This time, with 2 AIs and 3 agents, I built the whole thing in under 8 hours with 4 variations.

I wanted a portrait that comes apart when you move, and comes back together when you stop.

The reference was a TouchDesigner piece: a face broken into uneven rectangles. The pieces shift. Each one keeps the bit of the picture it started with, so a cell that grows does not reveal a new part of the face. It stretches its own. More movement, more abstraction. Stillness, and the face returns. I watched it the way you watch a mechanism, not a filter. The question was never “what model makes this look.” It was “what numbers keep a face a face.”

Facemorph is that mechanism, in a browser, on my own portrait. Four versions of the cut are still in the panel, because each one taught me where the last one had lied—mostly by dressing up bad geometry as avant-garde art.

https://facemorph.uk/facemorph

What I was actually directing

I work across UX, build, and the call on what ships. On this one those jobs collapsed into a single habit: sit with the picture and say what is wrong, specifically enough that the maths can change.

A liquid warp was the first attempt. Glass, ripple, a bit of chromatic fringe. It was pleasant and it was the wrong product. The reference does not melt the photograph. It partitions it. So the warp went on the shelf, and the work became a grid.

From there the direction was a series of refusals—mostly keeping the face from turning into cubist soup with a LinkedIn bio:

  • Rectangles that fly off on their own are not a portrait. They are a ransom note made of eyebrows.
  • A huge block with slivers only at the edge is not a cut through the face.
  • A grid that only subdivides the right cheek is a bug, even if the left side looks calm.
  • A flat grey slab is not the suit. The suit is black. If a rectangle has forgotten the person, the rectangle is wrong.

An assistant can write the implementation. It cannot sit in front of the poster and decide that the cheek has disappeared—or that the wall is quietly impersonating a lapel. That judgment was the project.

The stack, kept small on purpose

The page is a Vite app: React, TypeScript, a single route at /facemorph. The picture is one full-screen quad in Three.js. There is no particle system and no distortion shader doing the clever part.

The clever part is ordinary arithmetic on the CPU, once a frame.

A rectangle remembers two boxes. The home box is where it was when the grid was set. That box is converted into texture coordinates, so the cell owns a fixed slice of the photograph. The live box is where the cell is drawn now. WebGL stretches the home slice into the live box. That stretch is the whole effect. If the live box is wider than the home box, the eye widens. The cell cannot go and fetch a different part of the face, because its coordinates were locked at the start.

Video and the webcam add a second signal. A small downscaled read of the frame measures how much the picture itself is moving, and that energy is poured into the cuts underneath it. A still portrait has nothing to measure, so only the pointer, and a little designed drift, move the grid. The footer bars are those cuts. Each bar is one split. It fills as that split leaves home, and it sinks when the split springs back.

Everything else, the poster, the hairlines, the seed, is there so I can see the mechanism while I tune it.

One rule the four versions share

The rectangles tile the portrait. Their widths, or their split ratios, always sum to one. Nothing overlaps and nothing falls through to the background. When a cell grows, its neighbour gives up the space. The face stays one picture.

That rule is normalising a set of weights, or placing two children so they exactly fill their parent. It sounds like accounting for pixels. It is the difference between a portrait and a pile of stickers.

Cell Shift

Cell Shift is a table. A seed picks a set of column weights and a set of row weights. They are uneven on purpose: some bands are thin, some are generous, and then they are scaled so each set sums to 1. The slider runs from a 5×7 grid up to 10×14. The default sits around seventy cells.

The lines do not get recomputed from scratch every frame. That was an early version and it felt like the face was being re-dealt, not moved. The topology stays. Only the weights move.

Under the pointer, the column and the row you are in receive a kick. The target weight for that band becomes its home weight times one-plus-the-kick. Then the row is normalised again, and the live weights ease toward the target. The easing is the elasticity control. Take your hand away and the kick decays, the targets fall back to the home weights, and the face reassembles—no diffusion weights required, just honest arithmetic settling back home.

Because neighbours share edges, a growing cell pushes the line. It does not float free. That was the first time the picture behaved like the reference.

Extreme Shift

Extreme Shift uses the same table. I tried the other idea first: rectangles with independent positions, free to become slivers or blocks and to travel. It was louder. It also stopped being a face. I put the shared edges back.

What changed is the mix of weights at the start, and a small amount of sine on top of them. Thin slices sit beside fatter blocks. The grid breathes even before you touch it. The amplitude is capped, and the weights are still forced to sum to 1, so the breath cannot open a hole.

Same portrait. Looser cut. I kept it as its own mode because the restraint is the point. Extreme, here, means uneven. It does not mean broken.

Double Extreme Shift

A table always cuts the whole width and the whole height. The reference also has blocks that stop, and bands that only exist inside one region. That is a tree, not a spreadsheet. Binary space partition is the dry name. You cut a rectangle in two, then you may cut either piece again. A split is a single number: how far along that rectangle the cut sits.

Double Extreme is that tree, held to a shallow depth. The first cuts are not random. They are aimed through the face, roughly the middle of the portrait, so the lines cross the eyes and the mouth instead of decorating the margin. Deeper cuts are freer. Large regions are discouraged from becoming a single hero. An early pass left one cell covering most of the picture and a fringe of slivers. It looked designed and it did nothing to the face. I capped that. A block that large is just the original poster with a border—and a bit of unearned confidence.

Motion is the split number leaving its home value. Energy on the left of a cut and energy on the right pull in opposite directions. A spring brings the cut back: acceleration toward the target, damping on the velocity, a slower spring near the root so the big lines feel heavy and the small ones feel tight. The home coordinates stay locked. The live rectangle changes. The slice of the photograph stretches.

Triple Extreme Shift

Double Extreme still had a bias. The tree walked the left child first, spent its budget, and left the right side as one large remainder. From the chair it read as “the left stays big, the right is doing all the work.” I wanted the cuts spread across the whole head, and I wanted them to keep changing even when my hand was still.

Triple Extreme keeps the tree and changes the budget. The slider is no longer a depth of 4, 5 or 6. Depth in that range can only make a handful of leaves, which is why the control looked as if the cell count had collapsed. The slider now asks for a number of rectangles, about 150 at the default, up to 220. That budget is halved at every cut and given to both children, so one side cannot spend the grid before the other side is visited.

The idle motion is a sine added to each split, a different phase per cut, so the portrait never quite freezes. The size of that wander is small, and it is clamped around the home split. This was the last real argument with the maths. Let a split run from almost nothing to almost everything and a thin strip of the studio background, the grey beside the head, gets stretched across the cheek. The rectangle is “correct” and the picture is wrong. I would rather the cells keep moving a little than watch the backdrop eat the suit.

The footer on that mode is the same idea made visible. Thirty-odd bars, one per cut, filling as the split leaves home.

Computer monitor displaying code and a geometric split-grid portrait of a woman in black and white

What I would tell another maker

Pick the reference and stay ruder than the first impressive result. Three years ago, writing every line by hand, I barely got past the plumbing before running out of road. This weekend, 2 AIs and 3 agents got me to working prototypes in minutes—which mostly meant I had to say “no” much faster. The warp was impressive. The flying rectangles were impressive. The giant hero block was impressive. None of them were the piece.

Write down the invariant before the variation. Here it was: one portrait, shared edges, each cell owns its slice, movement abstracts, stillness restores. Every mode is a different way to honour that sentence. When a build broke the sentence, I could feel it before I could name the line of code—whether I wrote that line myself or an agent spun it up in thirty seconds. The grey block. The quiet left side. The face that had become a texture sample of empty background.

Let the agents chew through the boilerplate and explore four variations before Sunday evening. Keep the decision where the picture is. Facemorph is not a generated look. It is a small machine I can reset with the space bar, hide with H, and argue with until the person is still in it.

Youtube: https://youtube.com/shorts/pqfVw0Smtpo

App: https://facemorph.uk/facemorph