Hack Excel for 3D Rendering

[C Bel] teaches Excel and he has a problem. Most of us — especially us Hackaday types — immediately write a VBA (Visual Basic for Applications) macro to do tough things in Excel. Not only is this difficult for non-technical users, but it also isn’t as efficient, according to [C Bel]. To demonstrate that VBA macros are not always needed, he wrote a 3D game engine using nothing but Excel formulae. He did have to resort to VBA to get user input and in a very few cases to improve the performance of large algorithms. You can see his result in the video below or download it and try it yourself.

The game is somewhat Doom-like. Somewhat. As you might expect it isn’t blindingly fast, and the enemy is a big red blob, but as the old Russian proverb goes, “The marvel is not that the bear dances well, but that the bear dances at all.” (And thanks to [Sean Boyce] for recalling that quote.)

You can download the spreadsheet with or without VBA if you want to try it or dig into the internals. It is really pretty impressive, including:

  • An infinite procedurally-generated maze map
  • Real-time ray tracing
  • Occlusion calculation
  • Basic illumination rendering
  • Illumination and compute shader
  • Natural displacement engine

Do we agree this is better than macros? We aren’t sure, but we were impressed you could pull all this off with formula manipulation.

Not that we haven’t abused spreadsheets ourselves (look at CARDIAC in a spreadsheet and — although not ours — Little Man). We’ve even used them for circuit analysis.

23 thoughts on “Hack Excel for 3D Rendering

  1. Does anybody have any suggestions on how to better render 100+ photos in an Excel sheet? Excel has to save every photo in the file, which is fine but it does a horrible job of rendering them or allowing you to even view a worksheet with more than a few dozen shown at a time. It just cannot really keep up and is not even close to optimized for that. Even trying to use VBA tricks doesn’t really get you anywhere unless you use VBA to hide the photos not on screen or do other tricks that are also not much better.

    Obligatory Excel roller coaster.

  2. Ok, I see this as an interesting exercise, but the approach is flat out wrong.
    The top reasons to use vba are
    1) it is much much easier to get right first time than compared to complex cell formulae
    2) if it isn’t right, it’s much easier and faster to find and fix vba
    3) If you go back and change your own spreadsheet, it’s much easy to find and modify the right bit of vba code
    4) If another person is trying to do things to it, vba is far easier to follow.

    I have seen (more than one) companies go close to bankrupt due to complex excel spreadsheets with interlinked formulas..

    Just about anything complex (ie requiring more than 3 or 4 nested commands) should be done with vba.

    And finally, vba is easy to learn and use – I have taught 6yo and board members simple vba, and it greatly enhances their productivity..

    1. Aside from personally feeling that VBA is satanic spawn, too many people default to it out of lazy inclination vs getting a more elegant solution running. I’ve worked on tracking 6 points of activity for 12 macro-like sets of data and correlated this to fiscal year quarters for over 400 people. The file is under 1 MB. My predecessor has been trying to replicate the work with VBA and without a years worth of data, has a file 4x larger that doesn’t work.

      Even when done correctly, you’ll have to jump between two different editors to work with VBA vs just one without it.

      1. An elegant solution would probably require a few statements in R. No one cares how big the file is. But then too many default to Excel out of a lazy inclination.

        By-the-by what are “macro-like sets of data?” Even Google doesn’t seem to know that one.

        1. A better description is actually the reverse: 12 sets of data per individual and 6 parts of metadata per each set.

          Essentially doing small database work in Excel. I knew this was a job suited for a database, but my peers have a hard enough time knowing how to enter a formatted date, let alone using Access of a SQL variant.

          1. I think some of these responses miss the point – yes, you don’t want to build a large scale database system with excel if you have multiple users updating the same data etc etc..
            But if you have some data sitting somewhere, excel is quite good at getting it out and presenting results to people, and can have very fast turn around times…
            It’s also good on small amounts of data, or when data is only be updated from one source..

            I often use vba to access mysql, or even to access large transaction files through a C addon I wrote over 20 years ago (that still works with the current version of excel!) that directly load results into vba. The user can then do quite a lot with the results WITHOUT going back to the original data..

            Of course, sometimes I just do it all in php and on a web site. And other times I do it all in C++ as god intended. However excel/vba is great for certain jobs, where just excel (without vba) would be more than an order of magnitude more limited…

  3. Looks like Berserk: 3D. Put a smiley face on the blob. Back in the 80’s I told many people that a 3D version of Berserk would be cool. The response from them all? “That would be stupid.”. Forward a few years and John Carmack and friends produced Catacomb Abyss, followed by two sequels, the founding of Id Software and the release of Castle Wolfenstein.

  4. I find it amazing that after 19 comments thus far, no one has complimented this guy on his fine work.

    Kudos to [C Bel] for thinking all that out; researching, creating, implementing, testing, debugging, re-testing, debugging, …. Wow! How much time was spent on all that??

    Peace and blessings.

  5. Hi! OK it’s a good test for Excel spreadsheet formulas. Excellent work really. But I disagree that VBA is less fast/powerful (even if used by novice like me). Here is my own game made entirely in VBA Excel:
    3D Engine (written in early 2016): https://youtu.be/7GJ5t-yELHI
    Game “Dave vs Ziggy” (1st level playthrough): https://youtu.be/eU4KNLtWme0
    Game “Dave vs Ziggy” (2st level playthrough – shootout with the boss): https://youtu.be/jaZL-1EEeM0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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