Building A Raycaster Within Bash

Wolfenstein 3D was a paradigm-shifting piece of software, using raycasting techniques to create a game with pseudo-3D graphics. Now, [izabera] has done something very similar, creating a raycasting display engine that runs entirely within bash.

The work was developed with an eye cast over an existing raycasting tutorial online. As you might imagine, implementing these graphical techniques in a text console proved difficult. The biggest problem [izabera] encountered was that bash is slow. It’s not supposed to display full frames of moving content at 25+ fps. It’s supposed to display text. Making it display graphics by using tons of colorful characters is really pushing the limits. Bash also doesn’t have any ability to work with floating points, so all the calculations are done with massive integers. Other problems involved the limited ways to read the keyboard in bash, and keeping track of the display as a whole.

It’s neat reading about how this was pulled off—specifically because it was hard. It might not be the kind of project you’d ever implement for serious work, but there are learnings to be had here that you won’t get anywhere else. Code is on Github, while there’s a visual storytelling of how it came together on imgur.

We’ve seen similar work before—with magical 3D graphics generated in Microsoft Excel. Will wonders never cease? We hope not, because we always like to see new ones on the tipsline. Keep us busy!

4 thoughts on “Building A Raycaster Within Bash

    1. author here. sorry, that’s not the finished result, i’m very much still working on it 😅
      i don’t even have much of a plan, for now i’m still experimenting to see what can be done. i’ve just added some basic animations, i’ll probably attempt to add sprites soon

  1. Amazing, I have built a couple of raycasting engines but I wouldn’t have imagined it to be possible in bash.

    Thoroughly enjoying the comments in the code even if I don’t understand the level of black magic f’kery going on;

    “# this code is horrible because this function is more performance-intensive than it looks like,

    and it takes a ridiculous % of the time if you write it in a less atrocious way”

    Shoutout to lodev.org for being an amazing resource for raycasting engines by the way!

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.