A few weeks ago I was thinking about the easiest way to make levels for a game project. I'd recently studied an article in GPU Gems 3 ( http://http.developer.nvidia.com/GPUGem ... _ch01.html), which describes using the marching cubes algorithm to trace the contours of a 3D density function. I immediately took a fancy to the technique, and became keen to find an excuse to try out something similar. Eventually my thoughts landed upon a useful application: the ability to draw a 2D level (mask) image, have it traced, and turn the outline into Edge Shapes -- essentially turning Paint into a level editor.
To skip most of a long story, I managed to implement the 2D analogue of the marching cubes algorithm: marching squares; and it works a treat. One particularly nice thing is that it deals with anti-aliasing (AA) very nicely: AA in the source image == AA in the contour. Also, scaling is independant of the source image resolution, meaning the resolution instead determines the complexity of the generated outline polygon, i.e., shrinking the image (with AA) reduces the level's detail. As an alternative, I also implemented a vertex-culling algorithm, which simply removes vertices that form shallow angles -- it's very crude, and could do with re-writing or replacing with something more advanced (perhaps utilising cubic splines or something).

After describing marching cubes, the GPU Gems article goes on to discuss methods for procedurally generating density functions, i.e., random terrains. I originally thought this would translate poorly into 2D, and put-off giving it a go. But once I had the tracing algorithm working, I figured it might be interesting to try it. The results are better than I'd originally predicted, but I think practical use of a random terrain generator might be hard in 2D games. It's still kind of cool though, and there are lots of ways to tweak the structure of the terrain via noise sample frequencies etc (see the GPU Gems article for cool examples, which admitedly look way more awesome in 3D). I'm sure there are some interesting games waiting out there in the undiscovered void that make use of something like this.

Taking the idea beyond what I've done so far, I also thought you could draw friction and restitution values into separate colour channels and have them read and assigned on a per vertex basis. Another idea would be to use the system for destructable or deformable terrain, modifying and re-tracing the source image as necessary. The tracing algorithm is very fast, and although I haven't done any quantitative tests, I reckon it could handle real-time use.
A final use that came to mind was for rendering particle-based fluid simulations. Here, particles could be rendered to a source texture as meta-balls, and then the surface contours traced and turned into polygon meshes. However, this would be much better suited to implementation on the GPU.
I've implemented everything as a Test-Bed demo for simplicity, and attached a patch for quickly getting the code. You can also download the win32 exe here: http://users.bigpond.net.au/barsdell/TestBed_TerrainTracer.zip. The code's a little old-school in parts, lacks a bit of consistency, and may contain a memory access bug somewhere in the vertex-culling routine, but apart from that it's perfect 😀.
I hope this turns out to be useful for some people, and I look forward to hearing thoughts about it!
EDIT: I've now also attached a zip containing just the source code.
To skip most of a long story, I managed to implement the 2D analogue of the marching cubes algorithm: marching squares; and it works a treat. One particularly nice thing is that it deals with anti-aliasing (AA) very nicely: AA in the source image == AA in the contour. Also, scaling is independant of the source image resolution, meaning the resolution instead determines the complexity of the generated outline polygon, i.e., shrinking the image (with AA) reduces the level's detail. As an alternative, I also implemented a vertex-culling algorithm, which simply removes vertices that form shallow angles -- it's very crude, and could do with re-writing or replacing with something more advanced (perhaps utilising cubic splines or something).

After describing marching cubes, the GPU Gems article goes on to discuss methods for procedurally generating density functions, i.e., random terrains. I originally thought this would translate poorly into 2D, and put-off giving it a go. But once I had the tracing algorithm working, I figured it might be interesting to try it. The results are better than I'd originally predicted, but I think practical use of a random terrain generator might be hard in 2D games. It's still kind of cool though, and there are lots of ways to tweak the structure of the terrain via noise sample frequencies etc (see the GPU Gems article for cool examples, which admitedly look way more awesome in 3D). I'm sure there are some interesting games waiting out there in the undiscovered void that make use of something like this.

Taking the idea beyond what I've done so far, I also thought you could draw friction and restitution values into separate colour channels and have them read and assigned on a per vertex basis. Another idea would be to use the system for destructable or deformable terrain, modifying and re-tracing the source image as necessary. The tracing algorithm is very fast, and although I haven't done any quantitative tests, I reckon it could handle real-time use.
A final use that came to mind was for rendering particle-based fluid simulations. Here, particles could be rendered to a source texture as meta-balls, and then the surface contours traced and turned into polygon meshes. However, this would be much better suited to implementation on the GPU.
I've implemented everything as a Test-Bed demo for simplicity, and attached a patch for quickly getting the code. You can also download the win32 exe here: http://users.bigpond.net.au/barsdell/TestBed_TerrainTracer.zip. The code's a little old-school in parts, lacks a bit of consistency, and may contain a memory access bug somewhere in the vertex-culling routine, but apart from that it's perfect 😀.
I hope this turns out to be useful for some people, and I look forward to hearing thoughts about it!
EDIT: I've now also attached a zip containing just the source code.