A black hole you can fly around, rendered in real time in your browser, on your laptop or your phone.
astra.zeruic.me
Black holes have fascinated me for as long as I've known they exist. Interstellar threw an enormous amount of compute at its pictures of Gargantua, and I kept wondering whether we could get close to that level of visual fidelity, something genuinely stunning, and have it run in real time in a browser on whatever device you have.
That's how Astra started. It's an experiment in how far modern AI coding agents and modern hardware, phone and laptop alike, can carry a project like this: how far mobile graphics can be stretched, and how well the agents can optimize for it. I know very little graphics programming; most of the code here was written by AI agents.
Every pixel is a ray of light traced backwards through the curved spacetime around a spinning, charged (Kerr–Newman) black hole. The glowing disk is integrated along that bent path, so the lensing, the brighter side that's rushing towards you and the reddening near the horizon aren't painted on. They come out of the physics.
Switch on the maximal extension and the rays that fall in don't stop at the horizon. They carry on through the inner horizon, past the ring singularity and out into another universe, all the way to the antiverse.
Around that there's a field of rocks tumbling through the smoke, and a star field that stays sharp while it's being lensed.
It's built to look right rather than to be a simulation: the disk is procedural with approximate thermal emission, and the interior is the idealised eternal solution, which a real collapsing star wouldn't produce.
Open astra.zeruic.me in a browser with WebGPU (recent Chrome, Edge or Safari).
Drag to orbit, Shift-drag (or two fingers) to look around, scroll or pinch to zoom, double-click to reset. The presets and every other knob live in the panel, and the camera button saves photos and video clips of what's on screen.
The comments in this code explain why it is the way it is, often with the measurements that decided it. If a technique here is useful to you, point your own agent at the files and take whatever helps. A few highlights:
- Tracing only a fraction of the pixels. One pixel in eight is traced
each frame (one in 32 when the view is still). The rest reuse last
frame's result by working out where on screen their bit of disk used to
be (
src/engine/wgsl/material-reproject.ts). - Fixing what reuse gets wrong, in the same frame. Pixels whose history
can't be trusted go into a GPU queue and are traced exactly before the
frame is shown (
src/engine/repair-queue.ts,ordered-repairs.ts). - Through the horizons without coordinate trouble. Captured rays switch
to a Carter-separated integrator in Mino time, which never steps through
a singular chart (
src/engine/wgsl/extension.ts). - Stars that don't shimmer under lensing. Star directions stay
consistent from frame to frame and are drawn at native resolution, and
the light of the stars too small to see is integrated over each pixel's
lensed footprint (
src/engine/stable-star-field.ts,star-catalog.ts). - Solid rocks inside a glowing fog. Rocks are drawn into three depth
layers and blended with the medium in front of each
(
src/engine/wgsl/debris*.ts,src/engine/debris-depth.ts). - Noise baked in the log domain, with mipmaps that don't darken it when
filtered (
src/engine/wgsl/noise-bake.ts). - A resolution governor that predicts instead of searching. A
two-term cost model fitted from the GPU timings picks the render scale in
one step, separately for a still view and a moving one
(
src/engine/auto-quality.ts). - Bit-exact regression tests for a real-time renderer
(
scripts/regress/).
| File | What's in it |
|---|---|
src/engine/renderer.ts |
Device setup, pipelines, and frame(), which is the whole frame graph. Start here. |
src/engine/tuning.ts |
Every fixed tuning number, named and explained. |
src/engine/wgsl/geodesic.ts, inline-volume.ts |
The ray tracer, and the march through the disk along each ray. |
src/engine/wgsl/disk-medium.ts |
The disk itself. |
src/engine/wgsl/extension.ts |
The journey through the interior. |
src/engine/wgsl/material-reproject.ts, src/engine/temporal-material.ts |
Reusing last frame, and deciding which pixels must be traced again. |
src/engine/repair-queue.ts, ordered-repairs.ts |
The queue of pixels to trace exactly. |
src/engine/wgsl/debris*.ts, src/engine/debris-depth.ts |
The rocks. |
src/engine/stable-star-field.ts, star-catalog.ts, wgsl/post.ts |
Stars, temporal antialiasing, bloom and the final image. |
src/engine/auto-quality.ts, gpu-profiler.ts |
The resolution governor and the GPU timings it reads. |
src/engine/observer.ts, physics.ts |
Coordinates, units, the camera's frame, and the analytic Kerr–Newman quantities. |
scripts/regress/README.md |
The regression, timing and quality tools. |
Some comments mention files under docs/. Those are the development log
and design notes from the private working repository, and aren't part of
this release.
npm install
npm run dev # http://localhost:5199
npm run build # type check and build into dist/You'll need a WebGPU browser and a secure context (https://, or
http://localhost on the same machine). To try it on a phone on your
network, npm run dev:https sets up a local certificate authority and
prints the addresses to open; read what it prints before trusting it. The
hosted copy is dist/ served as static files on Cloudflare
(wrangler.jsonc).
The look of the disk is adapted from NPGS
by baopinshui, which is licensed under the GPL, so Astra as a whole is
GPL-3.0 (LICENSE). The adapted code lives in two files,
marked at the top: src/engine/wgsl/disk-medium.ts and
src/engine/wgsl/noise-bake.ts. NPGS was also the inspiration for the list
of things the maximal extension shows.
Everything else is also available under the MIT licence
(LICENSE-MIT), so you can lift any other file on its own.
Smaller pieces: the h13/h33 hashes are Dave Hoskins' "Hash without
Sine" (MIT), the blackbody colour fit follows Tanner Helland, and the tone
curve is Krzysztof Narkowicz's ACES fit. Clips are encoded with
Mediabunny (MPL-2.0). The interface uses React,
Zustand, Radix, Phosphor icons and Tailwind (MIT), and the Inter typeface
from Google Fonts.
