Images as Shaders
Each picture is one WGSL shader that paints an ordered list of soft ellipses. Press "Paint it in", drag the slider, or zoom in.
About these images
Each picture below is one WGSL fragment shader. The shader holds an ordered list of 1,024 soft, rotated ellipses packed into an integer array; its minified source is about 11 KB gzipped. The page draws each ellipse as its own small quad and lets the GPU blend them in order, so a frame costs about as much as the ink on screen. The list was trained so that its first 16, 32, 64 and so on ellipses already make a coarser picture. Press "Paint it in" to watch the shader add them, or drag the splats slider to stop at a power of two. As compression it loses: on these six Kodak test photos, AVIF at the same size scores 3.9 to 6.8 dB higher in PSNR. The buttons under the picture show the original and the AVIF and WebP files of the same size.
Bytes are the gzip size of the minified shader, measured at each power-of-two prefix; PSNR is against the Kodak original at 768×512, or against your image at the size it was fitted. The AVIF, WebP and JPEG comparisons are the best encodes at or under the full shader's size, allowing downscaling before encoding. Method and numbers: image-to-wgsl.
How encoding and focus work
Your image stays in this browser. It is scaled down (512 px on a phone, 768 px otherwise, on its longer side), then fitted on your GPU by WebGPU compute shaders in which each splat only touches the 16×16-pixel tiles it reaches; the picture above updates while it trains. The splat menu lists what this device can train, with a time estimate from a few timed training steps on your image. It offers up to 8,192 splats, which took about a minute on an iPhone and 4 seconds on an M5 Max laptop. The HTML download opens on the finished picture, with a button to paint it in and a slider over the measured splat counts.
Focus spends the splats where you choose: on a spot you tap, on faces (MediaPipe's face detector, about 13 MB the first time), or on everything at the distance of a spot you tap (the Depth Anything V2 small depth model, about 27 MB plus its runtime the first time). The picture shows the focus map until you encode, bright where the error counts most. Pixels outside the focus still count at a twentieth of the weight. The scores then add the PSNR inside the focus, weighted by the same map.
Zoom
Scroll, pinch or use + and − to zoom in, and drag to look around; double-click or Fit to go back. The shader redraws its splats at every zoom, so edges stay smooth at any magnification, but a list fitted at 768×512 has no finer detail to show. The original and the JPEG, WebP and AVIF files zoom with it and show their pixels.
For your own image, zooming adds that detail. The splats are fitted at 512 or 768 pixels, but the page also keeps your image at up to 4,096 pixels on its longer side. When the screen shows more pixels than the fit has, the page fits small extra splat lists to 256-pixel tiles of that larger copy, for the part in view, each painting what the coarser picture misses. They train on your GPU in the background, and the picture sharpens tile by tile; the line beside the checkbox counts them. A phone screen already has more pixels than a 512-pixel fit, so on a phone this starts without zooming; untick the box to stop it. The detail stays in this page: the downloads hold the fitted splats only. The gallery's Kodak photos are 768×512, so only your own images gain detail.
Sizes and comparisons
<iframe src="https://austegard.com/experiments/image-to-wgsl/web/view.html?src=URL-OF-YOUR-FILE"></iframe>