Much of my master’s work is about using GPUs in creative ways. Since I can’t talk about most of that work because it is pending publication, I can talk about a fun project I did a few months ago. I got the idea from looking at the work of Jonathan McCabe. It seems he develops quite beautiful patterns based on folding an rectangular array of input points. The site didn’t really give enough information to reproduce the images exactly, and most of the descriptions I’ve read by McCabe seem designed to obfuscate the process. It sounds basically like tie-die, where you fold up your cloth, then based on where a point ends up when it is folded, you chose a color for that point and then unfold the thing and voila! McCabe seems to be doing something a little extra where he interpolates the colors generated at previous folds, but no matter…
I thought that maybe instead of computing the color based on where a point ends up after being folded up, perhaps we can choose a color based on the final orientation of a point. In other words if the input array of points were a set of vectors all pointing the same direction and then we randomly fold the sheet of paper 32 consecutive times, what is the terminal orientation of each vector? We then render each point according to a simple lighting model where white is when the vector points toward the light (an angle of 0 degrees), dark gray is where the vector points away from the light (an angle of 180 degrees), and any other angle of the vector is just an interpolation between these color values. The idea is that this is roughly what a piece of paper would look like if you could fold it 32 times where you choose a random position and orientation for each fold every time.
When I say “fold” a sheet of paper, I mean this:
- draw a random line in the plane in which the paper lies
- ensure the line intersects the sheet of paper
- the line divides the plane in half so choose a random side of the line
- reflect all the points on the side you don’t choose across the line
The nice thing about this is that it translates to the GPU quite readily because the folding process is independent for each pixel. Also, nearly all the operations involved are 2D vector operations which reduce to a single cycle in the GPU. To make it all work, I store the fold information in a texture as input data for a fragment shader program. Then, the fragment program reads the folding information, performs the folds, and selects the color. One instance of the program looks like this:

Neat! What’s even cooler is that my GPU can render the image in less than a second. This means we can animate the folds. If we pick a fold and slowly rotate it, you can get some pretty neat animation. Check it out here. Cool, eh?
October 20, 2007 at 12:53 am |
Stephen, this was beautiful. Good job.
November 2, 2007 at 10:21 pm |
Nice work- like those animations