eventhorizon.

All projects

Public repository

A black hole in real time

A real-time WebGPU ray tracer of a Schwarzschild black hole: bent light, the photon ring and an accretion disk with Doppler beaming and gravitational redshift, plus toggles that show what each effect contributes.

An orbit around the black hole, then Doppler beaming and lensing switched off and on with the split slider.

Without WebGPU the demo renders more slowly on the CPU in Web Workers. The demo interface is in English. Recording from the repository, no sound.

Why I built it.

At my day job I work on software that generates single-line diagrams of high-voltage electrical substations: Angular and diagram rendering on the front end, Java 21 and Quarkus on the back end. This project is a deliberate change of scale from that: one scene, one equation and a result I can verify against a textbook.

It is also a self-contained test of three things I wanted to do end to end: numerical integration, GPU programming and color science. Every pixel has to agree with general relativity, which makes the output easy to check and hard to fake. That is why the project has a float64 reference integrator shared by the tests, the parity runs and the fallback renderer.

Try it in the demo.

The demo is the black hole with a panel beside it, with the tabs Controls and Physics.

Orbit
Drag on the picture to orbit and tilt the camera. The wheel changes the distance and Home resets the view.
What each effect contributes
In the Physics effects group switch off Gravitational lensing, Doppler beaming, Gravitational redshift or Higher-order images.
Compare with the full model
Switch on Compare with the full model and move the Divider position: your switches on the left, the full model on the right.
Overlays
In the Overlays group switch on Photon sphere, Innermost stable orbit and Shadow edge. The legend names every line.
Disk and image
The sliders Peak temperature, Outer radius, Exposure and Bloom change the disk and the picture.
Link and physics
The URL contains the entire state of the view, so a link brings back the same picture. The Physics tab lists every equation with a link to its derivation.

eventhorizon.adrianturbinski.pl

Three hard parts.

Each decision has its ADR in the repository, with the alternatives that lost.

  • One equation, one integrator, a float64 reference.

    The tracer integrates the vector geodesic equation with RK4 and a step that scales with the radius. The variant I chose keeps the shadow edge more than three orders of magnitude inside the 1e-4 target at about 108 steps per ray. The float32 shader is validated against both the float64 reference and a Math.fround twin on the CPU, so the remaining error is rounding, not a porting mistake.

    The price: rays within 0.02 of the critical impact parameter spiral around the hole and end in a direction set by the last digits, so float32 cannot match float64 there. The parity set leaves them out.

    Lost: the Binet form, a Hamiltonian form (singular at the horizon and the poles) and a symplectic integrator (RK4 achieves the same accuracy with simpler code).

    ADR 0002 on GitHub
  • One sign decides which side of the disk is bright.

    The tracer runs backwards from the camera. An incorrect sign of the angular momentum swaps the bright and dim sides but still looks plausible. The sign has hand-derived unit tests and a physical test: the side moving towards the camera must come out brighter and bluer. One factor g covers redshift, Doppler shift and time dilation, and the two switches multiply it by different parts.

    The cost: “Doppler beaming” removes the beaming and the transverse time dilation together, and the help text says so.

    What lost: a single “relativistic shift” switch and an angular momentum from the forward photon direction with no sign flip.

    ADR 0007 on GitHub
  • Stars under strong lensing.

    Stars baked into a cubemap blur when lensing magnifies them. Instead, stars are evaluated per ray at the final direction, and a star near the ring becomes an arc. I also found a bug along the way: hardware cube filtering returned half the value next to a face edge and drew faint dark hairlines in the preview video.

    The cost: a star lookup is nine cell hashes for every ray that reaches the sky.

    Lost: stars baked into the cubemap (blur instead of arcs) and a 1024² mipmapped cubemap (quadruple the memory for no improvement on a smooth nebula).

    ADR 0012 on GitHub

Numbers.

Only what the scripts in the repository measured.

12.1 ms
GPU time per frame at 1920 by 1080 on an RTX 3070 Ti Laptop (Chrome 154, Windows), median of 120 orbit frames: 66 frames per second. Intel Iris Xe: 136.6 ms, and 17.7 ms (62 frames per second) with dynamic resolution scaling at 0.35. The goals are 60 frames per second on a mid-range discrete GPU and 30 on an integrated one.
4096
Each of the 4096 rays in the parity set ends identically on the GPU and in the float64 reference, on the RTX 3070 Ti, the Iris Xe and the SwiftShader software adapter.
3.7e-8
Error of the critical impact parameter found by bisection, for an observer at distance 10, against a limit of 1e-6.
0.017
Maximum mean difference across nine scenarios, comparing the CPU and GPU images on the software adapter. The scale is 0 to 255 and the tolerance is 0.25.
2.6 s
A full 512 by 512 image rendered without WebGPU across eight workers (median of five loads), compared to 13.0 s on a single worker. The machine was under load.
797
Unit tests in the app and 97 for the scripts, plus 89 Playwright specs, with 98.8% line coverage. Lighthouse scores for accessibility, best practices and SEO are all 100. Performance scores range from 75 to 88 on the software adapter and 90 to 96 on the CPU path, on a busy machine.

Collected on 2026-10-10 on a single laptop: an Intel Core i7-12700H on WSL2, with Chromium 153 for the CPU and SwiftShader runs, and Chrome 154 on Windows for the GPUs, an NVIDIA GeForce RTX 3070 Ti Laptop and an Intel Iris Xe.

The result files in bench/results

What is not built.

Of the optional extras I built only the deflection check with elliptic integrals.

Kerr and a free-falling observer
Both were optional. Each one requires its own set of equations, parity run and ADR, and a half-checked mode would weaken the claim that every pixel agrees with the theory.
A simple disk
Thin, opaque and isotropic, ignoring limb darkening. It does not include the Page and Thorne correction or any returning light. Thick disks and jets are out of scope.
ACES tone mapping
ACES pushes very hot regions toward white. AgX would do better, but its reference has no license.
A picture without WebGPU
Fixed at 512 by 512, one ray per pixel, no accumulation, and the photon sphere and ISCO overlays are disabled.
One laptop
The hardware numbers are from one laptop with a powerful GPU, while the goal of 60 frames is for a mid-range card. SwiftShader provided the visual baselines. I have not tested it on other GPUs, Firefox or Safari.

What comes next.

First Kerr, as a separate mode, with a CPU reference before the shader. Then the visual baselines on a hardware GPU in CI, and a new demo recording on other adapters.

ADR 0017: the extras left out

Tech

  • Angular
  • TypeScript
  • WebGPU
  • WGSL
  • NgRx
  • SignalStore
  • Signals
  • Web Workers
  • Playwright
  • GitHub Actions
  • Keyboard support

Let's talk about the role.

contact@adrianturbinski.pl

Tell me about the team, the product and the stack.

Got a project to build? There's a client edition too.