conv.

All stories
TechActive · 32h

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

Peak 2 pieces in one half hour at Yesterday, 5 AM; 8 pieces over 33 hours (1 article · 4 posts · 3 comments) Yesterday, 5:27 AM — quietYesterday, 5:57 AM — 2 pieces · 1 article · 1 post — Hacker News 1, Newswires 1Yesterday, 6:27 AM — quietYesterday, 6:57 AM — 1 piece · 1 post — Reddit 1Yesterday, 7:27 AM — quietYesterday, 7:57 AM — quietYesterday, 8:27 AM — quietYesterday, 8:57 AM — quietYesterday, 9:27 AM — quietYesterday, 9:57 AM — quietYesterday, 10:27 AM — quietYesterday, 10:57 AM — quietYesterday, 11:27 AM — quietYesterday, 11:57 AM — quietYesterday, 12:27 PM — quietYesterday, 12:57 PM — quietYesterday, 1:27 PM — quietYesterday, 1:57 PM — quietYesterday, 2:27 PM — quietYesterday, 2:57 PM — quietYesterday, 3:27 PM — quietYesterday, 3:57 PM — quietYesterday, 4:27 PM — quietYesterday, 4:57 PM — quietYesterday, 5:27 PM — quietYesterday, 5:57 PM — 1 piece · 1 post — Mastodon 1Yesterday, 6:27 PM — quietYesterday, 6:57 PM — quietYesterday, 7:27 PM — quietYesterday, 7:57 PM — quietYesterday, 8:27 PM — 1 piece · 1 comment — Reddit 1Yesterday, 8:57 PM — quietYesterday, 9:27 PM — quietYesterday, 9:57 PM — quietYesterday, 10:27 PM — quietYesterday, 10:57 PM — quietYesterday, 11:27 PM — 1 piece · 1 comment — Reddit 1Yesterday, 11:57 PM — 1 piece · 1 post — Mastodon 1Today, 12:27 AM — quietToday, 12:57 AM — quietToday, 1:27 AM — quietToday, 1:57 AM — quietToday, 2:27 AM — quietToday, 2:57 AM — quietToday, 3:27 AM — quietToday, 3:57 AM — quietToday, 4:27 AM — quietToday, 4:57 AM — 1 piece · 1 comment — Reddit 1Today, 5:27 AM — quietToday, 5:57 AM — quietToday, 6:27 AM — quietToday, 6:57 AM — quietToday, 7:27 AM — quietToday, 7:57 AM — quietToday, 8:27 AM — quietToday, 8:57 AM — quietToday, 9:27 AM — quietToday, 9:57 AM — quietToday, 10:27 AM — quietToday, 10:57 AM — quietToday, 11:27 AM — quietToday, 11:57 AM — quietToday, 12:27 PM — quietToday, 12:57 PM — quietToday, 1:27 PM — quietToday, 1:57 PM — quiet 12
8 AM4 PMtoday8 AMnow · 2:27 PM ET
  1. 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…

      epestrr/programming17h agoview on r/programming ↗
    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.

      epestrr/programming14h agoview on r/programming ↗
    • It still misses an explicit join like primitive. I think that's the more useful part

      epestrr/programming9h agoview on r/programming ↗
    all of them →
  2. 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
  3. 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.

What people are saying 0 voices from 0 sites · best of 3 · verbatim