Developer writes a working ray tracer in Brainfuck, then speeds up its interpreter
A programmer built a 3D ray tracer using only Brainfuck's eight instructions, then optimized the JIT interpreter needed to run it in reasonable time.
What to know
- Brainfuck has only 8 operations and one data structure (a byte tape), with no native floating-point, multi-cell, or multiplication instructions.
- The ray tracer represents doubles using a custom signed Q16.16 fixed-point format to get the range and precision needed (e.g., a ground sphere with r=1000).
- The project began as a counter-example to a CMake tutorial aside noting ray tracers have been written in CMake's own build language.
- The author has since optimized the JIT interpreter used to run the program, cutting an estimated ~100-day render to under a day at reduced settings.
epestr Author of the Brainfuck ray tracerTSoding Author of the JIT compiler epestr's interpreter is based on
How it unfolded 2 developments, newest first · click a bar or a number to jump articlespostscomments
-
2
epestr reports speeding up the BF JIT interpreter and produces a render
Responding in the comments, the author said the render could be made a reasonable benchmark by dropping to one sample per pixel at a quarter resolution, cutting the workload roughly 1600x from an estimated ~100 days to under one day, and reported having sped up the JIT interpreter, based on TSoding's JIT compiler, producing an actual rendered image described as 'slightly artsy/funny looking' in an update to the post.
“I've also been working on the JIT interpretor I used and managed to speed it up a lot and got a render out of it.”
— epestr -
I must sleep soon, missed the additional. If you want it to be a reasonable benchmark, you could change the source `ray_ssa.c` to 1 sample per pixel and a quarter of both the width and height. That should reduce the work by 1600x (from ~100ish days to <1) I've also been working on the JIT interpretor I used and managed to speed it up a lot and got…
2 more of the top 3 · 3 posts in this stretch
-
I've been tring to optimize expressions too. My implementation is based on TSoding's JIT compiler. I've just added a license instead of repackaging it.
-
It still misses an explicit join like primitive. I think that's the more useful part
-
-
1
Post reaches Hacker News front page and spreads to Reddit, Mastodon
The write-up was submitted to Hacker News (front page, 8 points at time of RSS capture), cross-posted to Reddit, and picked up by Mastodon bot accounts tracking HN, spreading the project beyond the original blog.
“So I picked the simplest language I knew, BF, because a simple language obviously results in a very simple codebase.”
— epestr, Author · source -
background
epestr publishes a ray tracer written in Brainfuck — The blog post details building a full ray tracer in BF, an esoteric language with only eight operations and one data structure, using a signed Q16.16 fixed-point format to represent doubles since BF has no native floating-point or multi-cell arithmetic. The goal was to reproduce the exact image from the Metal section of Ray Tracing in a Weekend.