# Marching cubes terrain

Somehow you always come back to some standard terrain engine. Load a height map create a soup of triangles, optimize it, create more triangles, put a texture on it and… yes you have your terrain. Height map based. Kinda limited to a height map. Not something I wanted! So I want to have over hanging cliffs and tunnels. Have almost possible shape I can think of.

In the past I did some stuff that didn’t worked out as well as I hoped. I used a height map and offset the X, Y and Z via the R, G and B color channels. This way you can have over hanging cliffs, but still no tunnels (or well, you can use the right colors so that the edges of the cliffs meet in the middle…). But not really what I wanted.

So… I did some research on terrain and tried the marching cubes. From Wikipedia: Marching cubes is a computer graphics algorithm, published in the 1987 SIGGRAPH proceedings by Lorensen and Cline, for extracting a polygonal mesh of an isosurface from a three-dimensional scalar field (sometimes called voxels). An equivalent two-dimensional method is called the marching squares algorithm.

Sort: Creating a 3D polygon model from an “3D object”. In my case that’s what I need. However I don’t have a “3D object”. So I generate one! Define you “3D object” (in my case terrain) as a bunch of cubes. Say an array of 32x32x16. All cubes that have some neighbors, have some polygons as there is something at that location. (For more information I suggest Wikipedia or google).

Anyway, I use a height map (YES I DID!) to define the basics of my terrain shape. Next I start to add cubes randomly on locations where they could fit to generate a non-height map look and have some stuff “hanging over” (hangover…?). It still looks very polygonized, but when applied some textures it looked much better. I’m thinking of  adding some kind of tessellation to smooth it all out. Screenshot or it didn’t happen, so here you go:

## 3 thoughts on “Marching cubes terrain”

1. Would love ideas on using polygonized mesh graphics for longboard top deck. We are trying to use laser scans from organic parts i nour lab but would love other ideas. Our seem to be a bit too “flat”.