Minecraftian Voxel Engine: 2, The voxel part


Introduction

In the first post Terrain Height Generation I presented how to get the height of the minecraftian terrain map. I already mentioned that the difference of Minecraft to many other open world games is that the world is not only a map but consists of so called voxels (or cells of an array). Technically, not only a 2D map with scalar height values but a full 3D array with equidistant cells.

The advantage of such voxels is that the information of the in- and outside of the terrain is implicitly defined by the type of each voxel. So, if I remove or add some of the voxels of the terrain I do not have to consider the surrounding mesh. Each voxels stands for its own.

Unfortunately, if we want to increase the number of voxels to decrease the block like  visualization effect we get very fast to the point where the renderer gets too slow. This is because without optimization the engine/ graphics card has to project every voxel onto the screen. If you want to halve the size of the voxel for instance you end up with 2*2*2 the amount of voxels (*2 for every axis).

The pillar of voxels

To think about something or to explain it, it is often wise to cut it down into pieces. So, we choose only one pillar on the 2D height map and consider it. All other pillars are the same except the other x and z coordinates on the map. And here we choose x and z as coordinate axis' laying on the map and y as height. This correlates to z as depth and x from left to right.

So, having the height value now for our current pillar we first check whether the terrain is ocean on our biome map (the thing with humidity or temperature and humidity).
If so, we fill up the pillar with water from our height value to a predefined water height level. This predefined water level has to be higher than the height of the terrain in the biome map, of course.
If not, we check whether the terrain would like to have some dirt under it. Think about grass for instance. If so, we fill with some dirt blocks and set the grass on the height value of the pillar. If not, we simply set the terrain at the height value.
Then below we fill up with rock.

Caves and tunnels

Now we have the pillar ready. But something is missing. Where are the caves and tunnels for exploration?

This is where the 3D noise map comes in. We have to check for every voxel if it is there or not. In my case I use two 3D noise maps for each cave and tunnels and apply another spline to the cave map too.
Then, in reference 1 of the first post Henrik Kniberg talks about something which is called "squash value". This is used to define up to which height we can have wholes. I try to explain:

From the first post we have (with adapted x and y):

[x, z] -> 2D noise map combination -> height (y)

With our 3D noise map we get:

[x, y, z] -> 3D noise map combination -> density value

The density value decides whether the cell is air or terrain. The squash factor is a linear factor which depends on the height and is multiplied on to the density value before the "air or terrain" check is done.

Water

Now, that we have wholes which also can be below our freshly generated ocean we have to process these type of cells. The water should fill up the empty space below or even besides it.

Leave a comment

Log in with itch.io to leave a comment.