thecodingidiot.com

c04-the-infinite

The Infinite

SIX BYTES

September 20, 1984. David Braben[1] and Ian Bell[2] — both undergraduates at Jesus College, Cambridge, ages 20 and 21 — shipped Elite[3] on the BBC Micro.[4]

Elite original box cover art
The BBC Micro version of Elite, showing the player approaching a Coriolis space station
Enhanced graphics in the Archimedes version of Elite, showing Viper-class police ships in formation
Elite — 1985 ZX Spectrum port by Firebird Software

The BBC Micro had 32 KB of total RAM, shared with video memory. Elite generated 2048 star systems — eight galaxies, 256 systems each. None of it was stored. Every system name, economy type, government, technology level, and star distance was computed on the fly from a seed: three 16-bit numbers, six bytes. A Tribonacci[5][6] recurrence twisted them forward: each step produced the next system; 256 steps produced the next galaxy. Infinite variety from almost nothing.

The game shipped with a 64-page novella — The Dark Wheel by Robert Holdstock[7] — set in that same procedurally-generated[8] universe.

Elite: The Dark Wheel novella by Robert Holdstock, included with the original game

That pattern has a mathematical name. The Mandelbrot set[9] generates infinite visual complexity from a two-line iteration. Every coastline of it, every spiral arm, every miniature copy of the whole set buried in its boundary — all of it falls out of the same formula, applied to every pixel.

Your version has to render all of it. Not a screenshot, not a pre-computed image — a live computation. For every pixel on screen, evaluate the formula. Map the result to a colour. Write it to a buffer. Upload the buffer to the GPU and display it.

The GPU

That last sentence introduces something new. The GPU.[10] The inner loop of a fractal renderer — compute a colour for every pixel — is structurally identical to what GPUs do for real-time 3D graphics. Game developers in the mid-1990s needed to shade millions of pixels per frame, faster than any CPU could manage. The answer was dedicated silicon with thousands of small parallel processors, each running the same per-pixel computation independently.

3dfx Interactive[11] shipped the Voodoo in 1996. NVIDIA named its GeForce 256 "the world's first GPU" in 1999. NVIDIA acquired 3dfx's intellectual property in December 2000; the company filed for bankruptcy in October 2002. Programmable per-pixel shaders became the baseline that year.

You are about to write the CPU version of the algorithm that hardware was designed to run in parallel. Zoom deep into the set. Feel it slow. That latency is the argument that built the GPU. The r-tier will return to this — when the renderer moves to hardware-accelerated targets, the pixel loop you write here is the one the GPU was designed to accelerate.

The implementation pages build the renderer one layer at a time: the SDL2 event loop and pixel buffer, the Mandelbrot escape-time function, viewport mathematics, colour schemes, and finally the Julia set and the Burning Ship. Start at Setup.

Implementation

Setup

Begin Implementation
  1. 0Setup
  2. 1The Loop
  3. 2The Set
  4. 3The View
  5. 4Bits
  6. 5Colour
  7. 6The Julia
  8. 7Play It

Footnotes

  1. David Braben - Wikipedia

  2. Ian Bell (programmer) - Wikipedia

  3. Elite (video game) - Wikipedia

  4. BBC Micro - Wikipedia

  5. Galaxy and system seeds - Elite on the 6502

  6. Generalizations of Fibonacci numbers - Wikipedia

  7. Robert Holdstock - Wikipedia

  8. Procedural generation - Wikipedia

  9. Mandelbrot set - Wikipedia

  10. Graphics processing unit - Wikipedia

  11. 3dfx - Wikipedia

  12. Burning Ship fractal - Wikipedia