Since we’re about midway between Retrochallenges, I thought for a change of pace I’d post something about non-retro computing. I’ve been working on a small OpenGL graphics engine – nothing too complicated, just a platform to experiment with different algorithms and shaders and stuff. I’ve been dusting off some old models and code, playing with terrain generation, and fun stuff like that.
The video above shows off my attempts at creating a fabric simulation. I wanted to have hanging banners in some scenes I’m working on, and animate them so it looks like they’re fluttering in the wind. Rather than do a static animation, I decided to try to come up with a simulation, and since I’m doing this for fun, I decided to just jump in instead of doing the research to find out how these things are supposed to work.
I had some code sitting around that I thought would make a good starting point – it’s a spring system that was based on an example from an older edition of the OpenGL Superbible by Richard Wright, Jr. The example in the book was incomplete, but it gave me the general pattern of using transform feedback buffers and array buffers to do all the simulation computation on the GPU. The result is blazingly fast, even when I’m running 16 iterations of the simulation for each frame of graphics at 60 fps.
My favorite part of working on this is that when my code failed, it failed spectacularly. There were lots of polygons dropping through the floor and flying off into space before I got the results I wanted. I captured some good examples in the video, so I encourage you to take a look.