Live ray tracer

This scene is ray traced on the server while you watch, in plain JavaScript without any dependencies.

Glossy and mirror spheres rest on a soft rubber sheet, each sinking into it by its weight. A low sun throws long shadows across the bent checkerboard, its light bounces between the spheres and the sheet, and a lens flare with ghosts and streaks completes the view.

The image is traced in 60×60 pixel tiles, spiralling outwards from the center, by a pool of worker threads on the server: one per CPU core, shared by all requests, so the main thread stays free. Every finished tile is encoded as a PNG with nothing but node:zlib, and an async function* component streams it right away as an <img> with a data URL. CSS grid puts each tile in place, no matter in which order it arrives. Apart from a tiny inline script that keeps your scroll position when you change the view, no JavaScript runs in your browser.

Switch to Web Workers to move the work into your browser: the server only sends an empty canvas, and a pool of workers (one per CPU core) runs the very same tracer.js. Each worker traces one tile at a time and posts its pixels back, so the main thread stays free while all cores compute in parallel.

Resolution
960×540
Rays per pixel
16
Tiles
144
Rendered in
tracing…8122 ms · 4 threads