Marching Cubes
I have always been interested in runtime generated procedural terrain. In the time I had while waiting for art assets for my next Play Store game, I thought I’d delve into the Marching Cubes algorithm. Simply put, marching cubes is an algorithm that allows for polygonizing of an isosurface from a scalar field. The algorithm works by sampling the value of a scalar function at periodic intervals in space to generate a cubical grid of points. Each tiny cube (voxel) in the grid has 8 vertices, all of which can be either above or below the surface level leading to a total of 256 possible cases (Although, due to symmetry there are really only 15 unique cases, the rest are simply transformations of those). This allows for rendering of not only 3 dimensional mathematical functions, but also complex and intricate 3 dimensional terrain generated from overlaying several layers of noise at different frequencies and amplitudes. The images in this article are from a randomly generated terrain obtained by layering 7 layers of Perlin noise.
My main learning source was the amazing and incredibly informative article by Paul Bourke (http://paulbourke.net/geometry/polygonise/). A simple lookup table allows for fairly fast computation of the mesh vertices and triangles in each voxel.
I learnt a lot from this project. First was, of course, the marching cubes algorithm, its functioning, implementation, limitations, and methods of improving performance. Additionally, I wrote compute shaders in Unity for the first time, allowing for bulk processing jobs to be offloaded to the GPU. Alongside this, I understood the single threaded approach to game design, it’s limitations, and how to schedule interactions between the CPU and GPU so as to not stall the main thread and cause severe frame-rate drops.
Now, I’m keen to learn about naive surface nets, a modification of the marching cubes algorithm that generates vertices inside each voxel instead of on the edges. This allows for better approximation of the isosurface with fewer polygons. Additionally, I also want to learn about multihreading using Unity’s Job System and Burst compiler, which can offer significant CPU performance improvements and provide an alternative to compute shaders, which have significant overhead in transferring data between the CPU and GPU.
My project is available on GitHub, at https://github.com/AayushSabharwal/UnityMarchingCubes1
Bro speaking frankly I don't understand your project completely. But it looks great and is so real and unique. Your hard work can be easily seen.