But as a game software engineer, my ultimate goal was to extract the best out this hardware.
When you look at the specs, it's like being back to the old-school days:
- limited color depth ( very limited to 1 bit :) )
- limited memory (24k per program - almost)
- limited CPU power and features
- limited input system
- C based programming
Perfect set up to challenge myself :)
Step 1 : Tesseract
First idea was to do something that nobody did before: Real-time 3D.
After a couple of hours of coding, I got my wireframe rotating tesseract ( 4D cube projected in 3D then projected on the 2D screen ) running at 30 fps on my watch:
This was certainly fun to do but this was lacking the most important part. Pushing the hardware to its limit and see what could be achieved by doing so.
Step 2: Real-time Ray tracing
The old-school aspect of this task reminded me of the Amiga times and the checker sphere.
Then the idea of making a real-time ray-tracer came to me.
I started simple with a sphere and a light and slowly added a plane, then reflections and shadows ( note that you can see the reflection of the sphere shadow in the sphere reflection :) )
One major piece of the code was the dithering to accommodate the 1 bit deep display.
After adding the ability to change the texture of the ground plane and ability to rotate the camera around the sphere it looked like this:
I started simple with a sphere and a light and slowly added a plane, then reflections and shadows ( note that you can see the reflection of the sphere shadow in the sphere reflection :) )
One major piece of the code was the dithering to accommodate the 1 bit deep display.
After adding the ability to change the texture of the ground plane and ability to rotate the camera around the sphere it looked like this:
This is where i started reaching some limits of the Pebble.
The math heavy ray-tracing code was fast enough to display a picture after few seconds, but that was far from real-time.
The first optimization step was to optimize the code to take advantage of some specifics of the scene.
The obvious one was to convert the rather general ray-plane intersection to a more optimized ray-horizontalPlane version.
Then i used a directional only light to save some cycles too.
Once this was done the speed wasn't yet enough to call it real-time.
I started using using faster math tricks: Fixed point math, fast sqrt for example.
As this was not yet enough, I spent quite a lot of time trying to optimize the code that generates the initial ray from the camera to pre-compute as much stuff as possible and keep the x and y inner loops operation as fast as possible.
The code was now running nicely but not yet fast enough... I had to think at something else.
I was fill-rate bound. the cost of computation was directly linked to the number of pixels to render. The final solution was quite simple.
By rendering a quarter of the pixels per frame so that all pixels get updated over four frames, the performance was good enough to rotate around the sphere in an close to real-time fashion.
This also produced a nice trailing/ghost effect that added to the coolness of the achievement.
The resulting program ending up being about a thousand line of C code including comments and blank lines.
The app is on the Pebble app store if you want to try it for yourself:
https://apps.getpebble.com/applications/52f8987720ab1e67030001a9
This was good experience to learn and also build some solid code library that I could use for other performance demanding application.
I'm now looking to see how I will be able to port this to the new Pebble color.
Step 3: Game
After the ray-tracer, i wanted to go back to my roots: a game.I started a tunnel avoidance type of game but quickly wanted something cooler.
I was a big fan of the old-school dungeon crawlers (Dungeon master, Ultima Underworld ...).
This was enough for me to get enough motivation to write one.
The game is still in development for both version of the Pebble. It has been so far the most challenging app i've develop for this device.
I'm going to dedicate several posts to talk about its development in details. So stay tuned.
In the meantime, here's a video of it at a earlier stage:
No comments:
Post a Comment