Log In  


Cart #rezerododa-0 | 2019-09-25 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
6

An experiment to see if I could get a raytracer running in PICO-8. It's not very speedy, but it's as optimised as I could be bothered to do. If you find further optimisations I'd love to hear about them!

6


wow!!

optimization hints in no order:

  • try shl() to replace any power of 2 multiply
  • inline functions as much as possible
  • favor k,v in pairs(array) instead of for i=1,#array when ordering is not important
  • switch to 64x64 resolution (see pokes from wiki) and use pset instead of rectfill(x/x+1)

over and out :)


Outstanding ! Reminds me of some of the early demos for Commodore Amiga. Starred.


I was just thinking of earlier QBasic code doing this. One thing that made it run fast was that SIN and COS calculations were copied to an array and then the raytracer used that.

There is no need to calculate every SIN and COS each machine cycle for a rotating image, right ?


Yeah, but that’s not the slow part :-). The ray tracing isn’t using any sin/cos stuff. I tried the suggestions from Freds and they didn’t make a significant difference. The best speed up I’ve found so far is to switch both uses of sqrt to x^0.5 but even that didn’t make a huge difference. Thanks for the suggestions so far folks!


You are using 25 pico cpu!!
There is indeed very litle code optimization that would matter :/


It was over 30 before I optimised 😀


Then again we COULD just have ZEP release all the stops in PICO-8 and actually use up the computer's CPU, I would definitely not be against that - and all programs would still run smoothly with _DRAW(), FLIP(), and YIELD().

Running this I see this Firefox tab uses 3% of my CPU. Heaven knows how fast it could be bumped up to and to run even faster in immediate mode or compiled.


For fun I ported the code to javascript and increased the res to 256x256 and the number of bounces to 3 : http://www.matthewcraven.co.uk/raytrace/



[Please log in to post a comment]