Marching Cubes on GPU using Compute Shaders

This is an implementation of the Marching Cubes isosurface extraction algorithm, which allows creating a surface mesh from a density voxel field.

What’s special about it is that it runs in a Compute Shader, i.e. the bulk of the work is done on the GPU. This allows to very quickly re-create the mesh for a given chunk on the GPU, so with a bit of work real-time editing of a terrain (including cave systems) should be possible.

This implementation only covers the basics, things like vertex normal smoothing (for smooth lighting), texturing and smarter updating of chunks is not included.

There is probably also some room for performance improvement, but it’s more than fast enough for my purposes, so I will probably not optimize it much more.

This is based on the “embers” sample by @rdb , specifically the vertex-pulling is strongly inspired by that work. Cheers!

5 Likes

Thanks for making this. Panda has excellent support for custom shaders for those willing to learn how to leverage the various systems and write some shader code.

1 Like