DEV Community

Pratyush Shivam
Pratyush Shivam

Posted on Originally published at pratyushshivam.com on

The entire observable universe in a browser tab, true to scale, in 2.95 MB

Earth to 46.1 billion light-years in one continuous shot: 16,301 asteroids, 109,400 real stars and 156,940 real galaxies, every one where it actually is. 60 fps on a laptop.

The hard part was the engineering

  • Precision. A GPU has 32-bit floats, about 7 digits. Earth to the edge of the universe is 20 orders of magnitude. So every object stores its position relative to its parent in float64, the camera has no world position at all, and values are narrowed to float32 only at the last step. A naive renderer loses a full kilometre at Earth's orbit; this keeps it to a micrometre.
  • Depth. No depth buffer spans 1,000 km to 10²⁶ m. Stars and galaxies skip it entirely; each planet gets its own range fitted around its sphere. Zero flicker.
  • Compression. 8 bytes per star: octahedral direction in 32 bits, log distance in 16, brightness and colour in 8 each. 109,400 stars in 875 kB, sorted brightest first so phones get the familiar sky early.
  • Memory. Catalogues stream in and out by scale, textures step up from 512 to 4,096 px and are released when a planet shrinks. Heap stays at 15–29 MB the whole way. 1 to 4 textures and 3 to 15 draw calls per frame.
  • Zero frames drawn when nothing moves.
  • Tested against the real sky: the 2020 Jupiter–Saturn conjunction and the 2024 solar eclipse.

Fly it: pratyushshivam.github.io/lookback/

Source: github.com/pratyushshivam/lookback

I'm Pratyush Shivam, CTO of Konfidio. More of what I build and write is at pratyushshivam.com.

Top comments (0)