Specialization - 
Marching Cube World Generation


What?

For my specialization I decided to create an infinite world using the marching cube algorithm in our custom game engine - GhastLight. 


This world is fully customizable and includes features like trees, oceans, lakes, cliffs, mountains and beaches.

Why?

My favorite game of all time is Minecraft and something I've always been facinated by is how Minecraft could create infinte and interesting worlds from seemingly nothing? And that each world is unique but predictable in some way. 


This piqued my interest in world generation, but I didn't want to create Minecraft 2.0 so I changed the look of the world by using the marching cube algorithm that effectively smooths out the terrain and gives it a more unique look.

How?

Perlin noise

Now for the interesting bit!


Like in many world generation techniques, I am using perlin noise in different ways to generate a random but nice terrain that could pass for "realistic". 


Perlin noise is an algorithm that calculates a pseudo-random number based on any number of inputs. In other words it's a controlled form of randomness. 


In the picture above you can see a seemingly random graph. This is a 1-dimensional perlin noise with one input (x). As you can see, x-values close to each other result in similar values. This is what makes perlin noise so useful in generating terrains!


This creates the hills and valleys of the world generation but keeping the randomness unlike for example a sine curve. 

Modifying the perlin noise

Perlin noise by itself is not very useful for realisitic world generation because, by default it's too basic for it to be interesting 


The easiest way to start changing this is by modifying the frequency of the noise. This is done by multiplying the input values by a number. 


Lower numbers results in a "zoomed in" noise and higher numbers results in a "zoomed out" noise (see gif).


This is one of many techniques I'm using to get the perlin noise looking the way I want it to. For a more in depth guide on how perlin noise work and how to manipulate it you can read about it on:

https://www.redblobgames.com/maps/terrain-from-noise/

Using what I've learnt

My world generation uses 2 main perlin noises to determin if any block in a chunk should be solid/water or air.


I have a 2D height map that determines the overall look of the landscape by making sure nothing is generated above it. And I have a 3D "caves" map that cuts into the landscape creating caves and overhangs.


I also have a second 2D map used for tree placement, as you can see. Besides trees being placed randomly on the landscape they are also not all over it. This is because trees are only generated if the sampled point on the tree map is heigher than a certain value. This is to ensure varity and a more unique landscape.


The Journey

13. Feb 2024

Implemented basic perlin noise library into our custom game engine GhastLight, and used it to make a simple voxel world generation using cubes.

14. Feb 2024

Implemented 3D noise and used it to generate a voxel world.

18. Feb 2024

Implemented functionality for using a marching cubes look up table to calculate the appropriate mesh configuration per chunk. Looking kinda funky though...

19. Feb 2024

Got the marching cubes looking like they should!!

20. Feb 2024

Tested out new more extreme generation with a mix of 3D and 2D noise, as well as water.

27. Feb 2024

Implemented a thread pool and using it for faster chunk loading/un-loading. A little rough around the edges but it worked.


Also tried creating trees but my system was flawed and it was hard to implement (definitely not foreshadowing....)

21. Mar 2024

- Big Jump -

A lot of under the hood clean up and optimizations as well as failed tests...


Implemented new structure for easier manipulating "block" generation, which meant changing pretty much everything. And a new way to calculate the marching cube configuration to support the new system.


Started using "world generation passes" that modified the terrain before the marching cubes mesh was calculated. Therefore water, trees, grass, dirt, stone etc. were so much easier to implement and control through different passes in a more logical manner than before.

29. Mar 2024

Implemented proper tree generation with the new system and some more bug fixing and thread work.


Also made everything in the world generation deterministic. Simply put, if I use the same seed again everything in the world will look exactly the same, down to the tree location and height which is controlled by a separate random generation than everything else.

3. Apr 2024

Some small tweaks and fixes later, and my specialization was now complete!


Editor Tool

During development I realised it was not feasible to keep restarting the editor every time I wanted to tweak the world generation values. So I decided to invest some time in creating a tool that let me do that in-editor instead. This tool - as you can see in the video, lets me change all the world generation values that I used for the world generation. It also shows a texture of how those values would affect the perlin noise. This made it a lot easier for me to understand exactly how each value changed the world and resulted in the world generation I have now which I'm very happy about!


Disclaimer: I am part of The Game Assembly’s internship program. As per the agreement between the Games Industry and The Game Assembly, neither student nor company may be in contact with one another regarding internships before April 23rd.