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.

shader
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

Export the shader (.wgsl)Export a page that shows it (.html)Export the splat list (.bin)The .bin is the packed list of soft ellipses with no shader around it. To look at one, choose it in the viewer or drop it on that page. To show one in your own page, host the file anywhere that allows cross-origin reads (GitHub Pages does) and embed <iframe src="https://austegard.com/experiments/image-to-wgsl/web/view.html?src=URL-OF-YOUR-FILE"></iframe>
Shader source (minified)