Spring cleaning

August 19, 2009

I'm a weak-willed person, and I've strayed far from my goal of writing the great American video game. Here are a couple things I've been working on instead.

GPU-based voxel rendering

I'm a big fan of the pixel art of the 16-bit era, and I thought it'd be a fun experiment popping that style into the third dimension. To that end, I've written a simple low-resolution voxel renderer and modeler.

The renderer draws a cube-shaped shell geometry around the voxmap's bounding cube, drawing the surface with a fragment shader that casts a ray through the body of the cube looking for an opaque voxel. A traditional voxel raycaster would sample the voxmap at a constant interval along the ray, perhaps doing trilinear filtering around each sample point to eliminate aliasing. Since I was intentionally going for a blocky look, I instead just sample the rays at every voxel boundary. Once the shader code was done, wrapping it in a nice, Mac-friendly editor program with Cocoa and Objective-C was easy. You can pull the code with:
git clone https://duriansoftware.com/code/Trixel.git.

High-level OpenGL API wrapper for Factor

OpenGL was a great API when graphics accelerators were expensive novelties with a few fixed features, but as GPUs have become more common and more capable, its years of drinking and flirting with different extensions and steering committees haven't been kind to it. Even with the tummy tucks and chest lifts of OpenGL 3, its warts and wrinkles still seep through. But despite its age, OpenGL still does its job, and it's the only graphics API choice for anything that might run on anything other than a PC or XBox. It should be possible to give OpenGL an object-oriented veneer to hide the state-machine monster underneath. And in a high-level language implementation like SBCL or Factor with expressive metaprogramming and compiler optimizations, we should even be able to minimize the run-time cost of using that veneer. I've written such a library for Factor, which is available in the Factor distribution as the gpu set of libraries, complete with docs and demos.

To put my library through its paces, I knocked out a couple demos. First, a port of the Stanford Bunny demo:

Second, a take on the classic Amiga raytracer demo, but in real time using GPU acceleration:

Check out the code for gpu.demos.bunny and gpu.demos.raytrace from the Factor git repo. The library makes it easy to load and interactively update shaders, define binary formats for GPU vertex buffers, and feed parameters to shader code using Factor objects. Along with Factor's game framework libraries, you can knock out non-trivial graphics demos with only a few hundred lines of new Factor code.

Real work

I've been lackadaisically working on BattleMints too. Here's how it looks these days: