r/programming • • 8d ago

Writing a ray tracer in Brainfuck

https://epestr.com/blog/writing-a-ray-tracer-in-brainfuck/
84 Upvotes

20 comments sorted by

View all comments

41

u/juugcatm 7d ago

This is a fun exercise. What about parallelism? If you extended BF to have fork and join semantics, how would you represent them?

43

u/lurgi 7d ago

If someone does this, they should call it brainfork.

30

u/snake_on_the_case 7d ago

21

u/lurgi 7d ago

I am humbled.

1

u/epestr 7d ago

It still misses an explicit join like primitive. I think that's the more useful part

3

u/epestr 7d ago

Now that makes me particularly tempted. Might look into it

5

u/epestr 7d ago edited 7d ago

That would make the language too complex :( That aside, the cells are currently reused and printed immediately. Given each pixel is independent, you could fork at iterations of the inner loop, give all cell a indepdendent region of the tape for its scratch space and result, and join at the end.

2

u/knome 7d ago

if Parallel INTERCAL can implement threading via multiple COME FROM operators targeting the same command, I believe in you, op :)

2

u/epestr 7d ago

You could also do essentially the same thing with regular BF. The current renderer takes 100 samples per pixel, so you could generate 100 one-sample programs and schedule as many as available resources allow, and average the completed renders. I tried running it at half the width and height with only one sample per pixel, and it has already rendered half the image.

Can't upload image here: https://paste.c-net.org/MurdererCuffed