Work · 2026

Photoreal embroidery, rendered from scratch

A Python renderer that simulates embroidered lettering stitch by stitch, thread by thread, and composites it onto real garment photos.

Side project · 2 min read · event #000034

  • Python
  • Cloudflare R2
  • Coolify
  • Hetzner

Live site ↗

The problem

I run a small clothing shop with slogan designs embroidered onto hoodies and sweatshirts. Customers need to see what a design will look like before it is stitched, and a flat text overlay on a photo looks nothing like thread. I wanted images that look like real embroidery, for product galleries and for a live preview in the shop’s customiser.

How it works

Stitch builds the picture the way a machine would sew it.

Layout. The phrase is set in the brand font. Hairline strokes are thickened first, because thread cannot reproduce a stroke thinner than the stitch itself.

Satin stitches. Each letter stroke is filled with satin stitching. The renderer casts rays across the stroke from its outline, giving rows about 0.38mm apart that follow the shape of the letter and fan out around curves, as they do on a real machine.

Lofted thread. Every stitch is rasterised as a piece of thread with thickness: raised in the middle, tapering down into the needle hole at each end. These are drawn into a height buffer in sewing order, so later stitches sit on top of earlier ones.

Lighting. From the height buffer I shade with an anisotropic Kajiya-Kay model, the kind used for hair. Thread is a bundle of fibres, so its sheen depends on the stitch direction and the light angle. That is why adjacent letter strokes catch the light differently, which is the thing most obviously missing from fake embroidery.

The fabric. The surface underneath is a procedural single-jersey knit, with puckering around the stitching, contact shadows where thread meets fabric, and cast shadows from the raised thread.

Compositing. The result is placed onto real garment photos with calibrated placement. The same engine produces flat lays and depth views.

In production

A signed shop API lets the store request renders, and outputs are stored in R2. It generated the gallery images for more than 35 live products, and it drives the live preview in the shop’s customiser.

What I’d do next

Add more stitch types than satin, such as fill stitches for larger shapes, and compare the output against photographs of finished samples more systematically so that lighting and thread-tension settings are tuned against evidence rather than by eye.

← Back to work