Planet Generation#

Earlier last year I created a marching cubes algorithm within Unity to attempt at creating planets procedurally after being inspired by one of Sebastian Lague’s videos where he achieved my aim through similar means.

Marching Cubes#

Marching cubes is a very simple algorithm where essentially it will take in a 3D grid of elements that most would call voxels to create a 3D object. This could be anything from planets, human heads, props, etc.

Upon inputting this grid of voxels through a marching cubes algorithm it will attempt to reconstruct as a mesh which would allow for the creation of smooth terrain in my case. Rather than something that is just made of cubes such as Minecraft.

Initially, I created this script in C# to create a functional algorithm due to easier debugging. I did succeed at creating anything but it was incredibly slow with larger objects such as a planet.

This caused me to have to rewrite the algorithm within a compute shader which essentially allows me to run code on the GPU instead which is far faster at processing data such as this as it has very little branching which is ideal for any compute shader.

I was successful in creating the marching cubes algorithm as shown above after a couple of weeks of working on it. The issues with the planet generator came with the input I was feeding it.

Alike the Terraria clone I used a similar process to create the input which was through the use of Perlin noise. While this did give interesting results as well as managing to keep the generally spherical shape that we know planets to have. I did have an issue with creating interesting terrain such as there being no hills or mountains or even natural-looking caves. When looking within the planet to see the structure of the caves they were very noticeably blob looking which is far from ideal though helped test the marching cubes algorithm.

I could not think of a solution without needing to rewrite the entire input system for creating a planet which is when I chose to leave the project be. Even though a planet was not made in the end I still have a functional marching cubes algorithm which I could use in a future project if I wish to create another procedural world.