This, perhaps surprisingly, is a subject that I now know far too much about. As part of a side project to recreate an old rendering of a beach scene I wanted a heightmap of some typical sand ripples - you know the ones you always see on every beach and desert. They look mostly like period waves but have interesting joins and branches kind of like magnetic domains.

Anyway, even the power of Google couldn’t find anything at all. There are lots of photos of the ripples though, so I thought maybe I could reverse engineer a photo by correcting the perspective and then finding a Photoshop filter that could reverse engineer a heightmap from the shading of a low sun. Again I could find nothing! This seemed strange given that it’s kind of the inverse of an emboss filter that attempts to take a height-map and show it as though illuminated from the side. I thought maybe I could implement an image processing filter to do this but luckily found a richer seam.

*Figure1: Simulated ripples in sand*

It turns out simulation of this ripple patterns is a topic that has kept various researchers busy over the years and I found a great paper with a Matlab algorithm here: www.math.hmc.edu/~hosoi/M164/sanddunes.doc.

Very interesting stuff. I managed to convert most of the code into Java. After a bit of fiddling around understanding some of the Matlab syntax I managed to get it to work. You can download the source here. There are quite a few parameters to tweak and you can create some bizarre patterns when the algorithm isn’t quite right as I learned along the way! One interesting consequence of the algorithm is that the generated patterns are perfectly tileable due to the wraparound pacman style space that Peter would probably call a toroidal non-euclidean geometry.

Here is an example of the kind of thing I want to create with the sand heightmap:

*Figure2: Scene ray-traced using heightmap*