Ray tracing made possible on 42-year-old ZX Spectrum: 'reasonably fast, if you consider 17 hours per frame to be reasonably fast'

The ZX Spectrum with a colourful background.
(Image credit: Future)

Ray tracing has been around a surprisingly long time in computer graphics. It was used to generate images in the 1960s, and by the '80s new algorithms had been created including path tracing. Yet the "holy grail of rendering" remained a distant dream for early home machines like the ZX Spectrum. You need only look how long this machine takes to render a single ray-traced frame in order to get an idea of how far ray tracing acceleration has come in the past half-century.

It takes around 17 hours for the ZX Spectrum to render a single ray-traced frame. That's one frame every 61,200 seconds, or 0.000016 fps.

But what a gorgeous frame it is. This is the output from a fun project by Gabriel Gambetta, author of Computer Graphics from Scratch and senior software engineer at Google Zürich, and brought to my attention by Hackaday. As a long-time fan of the ZX Spectrum, Gambetta decided one day to see if the plucky machine from Sir Clive Sinclair born in the early '80s could cope with ray tracing. The surprising result is that, yes, it sort of can.

As detailed in his blog post on the project, Gambetta ported the basic ray tracing code from his book into BASIC—the programming language that powers the ZX Spectrum. Without too much tweaking, he found that this code produced a basic image even on the ZX Spectrum's limited hardware—a 3.5MHz Z80A chip with often as little as 16KB of RAM. 

The image is just four blobs of colour: yellow, red, green, and blue. This process took nearly 15 minutes. On a modern PC, the same scene would take a fraction of a second.

"From the beginning I knew implementing some sort of raytracer was possible because the theory and the math are relatively straightforward," Gambetta tells me. "But I didn't know if it would run in a sensible amount of time, because this thing was slow for modern standards (...and even for the standards of the time!)"

Ray tracing is computationally expensive. It's the process of casting a ray out from the camera through a grid of pixels until it interacts with an object in the scene. Casting further rays from that point can generate lighting effects, such as shadows, reflection and refraction. To produce a high resolution image with realistic lighting using even just a single ray per pixel demands millions of rays per frame. It takes clever algorithms, bounding boxes, and heaps of acceleration to do this in real-time for today's ray-traced games.

Whereas the ZX Spectrum is capable of producing only a handful of colours—fifteen in total, including two brightness levels and black—and has a total resolution of 256 x 192 pixels. It's unable to display any colour in any pixel at any one time, either. It uses blocks, 8 x 8 pixels in size, in which it's able to store information of just two colours at once. This was done to minimise memory use; overall a great decision as it hugely brought down costs at a time when computers were not known for being affordable, but a bit of a nightmare for displaying much more than text.

The ZX Spectrum with a colourful background.

The ZX Spectrum in its usual garb. There were many variations, including those with more RAM, in its lifetime. (Image credit: Future)

This thing was slow for modern standards.

"The first version of the ZX Spectrum had a grand total of 16 KB of RAM, so memory efficiency was absolutely critical (I had the considerably more luxurious 48 KB model)," Gambetta said in the blog post. "To help save memory, video RAM was split in two blocks: a bitmap block, using one bit per pixel, and an attributes block, using one byte per 8 x 8 block of pixels. The attributes block would assign two colors to that block, called INK (foreground) and PAPER (background)."

The first image produced by Gambetta is effectively an image that's been coloured in by information from rays cast into the scene, and it's more or less a match for these 8 x 8 pixel blocks at only 32 x 22 pixels in size—each distinct colour displayed across an entire 8 x 8 block.

The downside of the ZX Spectrum's memory-savvy block-based solution is what's called attribute clash. This is essentially the inability to display any more than two colours within an 8 x 8 pixel block.

Gambetta's next step was to up the resolution to near-maximum at 256 x 176, effectively drawing individual pixels, but this means bumping into attribute clash.

"Increasing the resolution is easy. Dealing with attribute clash, not so much."

There's no solution to attribute clash. It's an inherent and idiosyncratic part of the ZX Spectrum. In the end, Gambetta's higher-resolution image is near enough perfect—he used a simple algorithm to try and minimise the effects of attribute clash as much as possible—just don't look too closely at some of the points where three colours meet.

The strain of going from a 32 x 22 image to a 256 x 176 one is evident in how much longer this secondary image took to render. From 879.75 seconds (nearly 15 minutes) to 61,529.88 seconds (over 17 hours). Luckily, some optimisations and time-saving tweaks meant this could be brought down to 8,089.52, or near-ish two and a half hours. 

A ray-traced image on the ZX Spectrum showing attribute clash with optimisations to improve performance.

(Image credit: Gabriel Gambetta)

And we haven't even got to the really cool bit yet! As I mentioned before, ray tracing can be used to generate the pixel colour, but it can also be used to produce various effects. Think of Alan Wake 2 and how vibrant and realistic some of the lighting is in that game. The ZX Spectrum could never get close—it only has a handful of colours to work with—so instead Gambetta simulates how light interacts with a scene through the use of dithering.

The result is genuinely awesome for a lil' machine like this. A ray-traced 3D-like image that works somehow despite all the limitations on colours and how they're used.

A ray-traced image on the ZX Spectrum showing dithering to created shaded colour.

(Image credit: Gabriel Gambetta)

"I ran this iteration, and honestly, I stared at it in disbelief for a good minute," Gambetta said.

What's more, he uses a further tweak to his ray tracer code to implement shadows in the scene. Using a ray to trace any intersections between a sphere and the directional light source, he was able to produce the final image in this experiment, which is genuinely incredibly impressive. Sure, even with optimisations, it takes around 17 hours to render a single frame, but hey, I'm wholly impressed.

The end result exceeded the expectations I had at the beginning!

Reflections are basically impossible with the limitations on colour blending, and perhaps there's more to be done to increase performance, but ultimately this is not something I would have previously thought at all possible on a ZX Spectrum's measly 3.5MHz processor.

"The interesting part of the project was figuring out how to work around all these limitations to make something that ran reasonably fast, if you consider 17 hours per frame to be reasonably fast, and looked reasonably good," Gambetta tells me.

"In that sense, the end result exceeded the expectations I had at the beginning!"

Why the ZX Spectrum?

Later versions of the ZX Spectrum improved upon the base specification, including this ZX Spectrum +3 with a floppy disk drive. Drool worthy stuff! (Image credit: Future)

The ZX Spectrum was a massively popular computer in the early '80s. Affordable, entertaining, surprisingly good-looking, and even quite educational. Part of its popularity came down to how it was possible to code your own games using its programming language, BASIC. But one had to get around the limitations of the hardware first.

"To make it so cheap its designer, Sir Clive Sinclair, cut all sorts of corners," Gambetta tells me. "It was a limited computer even for its time."

"I grew up with one of these at home (in Uruguay of all places). It had some apps but also tons of videogames, so it was a gateway drug into programming for an entire generation of people like me; you got it for the games, but it was very very easy to accidentally slide into programming it yourself, because it "booted" not into a command line, not into an user interface, but into what we would call an IDE (or development environment) nowadays."

Learn a bit of BASIC and you could make something on the ZX Spectrum. Not fast, nor with too many colours, but something.

"You could have some kind of visual thing moving around the screen in something like 5 lines of code, which is unthinkable these days."

Gambetta tells me he doesn't believe there's anything quite so simple to dip your toes into the world of graphics programming these days—even the most basic programs take more lines of code than anything the ZX Spectrum ever did. Yet he does plug the PICO-8 for retro gaming fans looking to mess around with getting coding themselves, and of course his own book (available for free on his website or for money on Amazon), Computer Graphics from Scratch.

"That requires nothing but a browser and a text editor, which pretty much any computer comes with out of the box. But even that takes more steps than what we had in the '80s."

Jacob Ridley
Managing Editor, Hardware

Jacob earned his first byline writing for his own tech blog. From there, he graduated to professionally breaking things as hardware writer at PCGamesN, and would go on to run the team as hardware editor. He joined PC Gamer's top staff as senior hardware editor before becoming managing editor of the hardware team, and you'll now find him reporting on the latest developments in the technology and gaming industries and testing the newest PC components.

Read more
Doomslayer pointing a gun at demons while giants fight in the background
Ray tracing is quickly becoming inescapable and I think it's time we bit the bullet and embraced it
A screenshot taken from the 2025 Nvidia tech demo Zorah
Nvidia RTX 50-series and dev kit show that rasterization is old news and we're now firmly in the era of AI rendering
Nvidia RTX 5090 Founders Edition rendered on a green background.
It's time for me to admit that AI-accelerated frame generation might actually be the way of the future and that's a good thing
A close-up photo of a monitor displaying the Windows 11 start icon, with the screen's pixels clearly visible
You don't need an RTX 5090 or a 4K monitor for gaming when you can play Snake on your monitor's subpixels. But you will need a microscope or a good macro lens
Collage of images to represent Nvidia's RTX AI PCs
I'll say it: The best thing I saw from Nvidia at CES wasn't its sweet new GPUs, but some tasty AI every RTX gamer can enjoy
Jensen Huang, co-founder and chief executive officer of Nvidia Corp., speaks while holding the company's new GeForce RTX 50 series graphics cards and a Thor Blackwell robotics processor during the 2025 CES event in Las Vegas, Nevada, US, on Monday, Jan. 6, 2025. Huang announced a raft of new chips, software and services, aiming to stay at the forefront of artificial intelligence computing. Photographer: Bridget Bennett/Bloomberg via Getty Images
AI may move at the speed of light but Nvidia's machine learning model for frame generation took 6 years to develop
Latest in Hardware
Pipboy holds up an open padlock.
A BIOS update could be all that's stopping you or someone else from jailbreaking your old AMD CPU
Asus's new ultrawide sucks as hard as it blows
Asus' new monitors purify 90% of airborne dust from your desktop and I've definitely seen some gnarly gaming setups that would benefit
A screenshot from Sony's PlayStation 5 Pro announcement video, showing a stylized processor against a dark background with glowing lines streaming from its edges
The AMD x Sony collab gave us FSR4 and a version will appear in PlayStation next year, too, having 'already started to implement the new neural network on PS5 Pro'
Nvidia RTX 5080 Founders Edition graphics card from different angles
Nvidia says it really has sorted RTX 50-series black screen issues this time around as yet another driver fix finds its way to release
A collection of upturned CDs, DVDs and Blu-Rays on a carpeted floor
Warner Bros says it will replace certain DVDs damaged by 'disc rot', but you might not get the same movie you sent in for replacement
Skytech Shadow gaming PC on a blue background
Screw waiting for GPU restocks, with an AMD RX 9070 gaming PC going for as cheap as this I'd hop on the pre-built bandwagon
Latest in Features
OneXPlayer 2 pro on a table
I never thought a handheld PC bloated with Windows could replace my Steam Deck, but after gaming on an old OneXPlayer 2 Pro I can see now I judged it too harshly
A screenshot from the original Assassin's Creed game
Assassin's Creed: Shadows is just around the corner, so come and see the last 17 years of the series' PC graphics at max 4K settings
Beyond the Ice Palace 2 screenshots
I’m not sure what’s weirder: that someone made a sequel to a completely forgettable 37-year-old game I played as a kid, or that it was actually worth the wait
Screenshot of Children of Clay showing a mysterious clay model
Five new Steam games you probably missed (March 10, 2025)
A goalkeeper in a plague mask wields an axe
Silent Hill gets a soccer league in FEAR FA 98, and you can play the demo now
The Sims 4 - stacks of laundry machines in a small laundromat small business next to chairs with laundry
The best part of The Sims 4 Businesses & Hobbies expansion is just coming up with fun small business ideas