One problem with the previous voxel terrain is that it is strictly by height. It generates nice looking mountains, but the implementation prevents anything like overhangs, caves, cliffs, land bridges, or any other similar terrain because the elevation simply rises and falls. My solution this go around is to expand the perlin noise function I’ve been using to include a third dimension, giving me 3D noise.

It has the terrain features I want (including FLOATING ISLANDS), but unfortunately it has no concept of up, down, left, or right, as you can see by its adherence to the world’s northern wall. This is because, by itself, perlin noise creates an infinite cloud of smoothed data, and has no rhythm or pattern to it. I need to add one. A simple gradient blended into the data values that gradually weights the values higher up toward 1 (Air blocks) and the lower values toward -1 (Dirt and Stone) might help me do the trick. The perlin noise library (libnoise) I’ve been using has several different noise generators, combiners, selectors, and modifiers that allow me to manipulate the noise, it’s just a matter of finding the right tool for the job.

Unfortunately, that tool seemed to not be in the toolbox. Try as I might, I seemed unable to get the noise generator to return a smooth gradient to be blended into the process. I wasted the entire day Googling, scouring documentation, and awkwardly plugging modules together in the hope of getting what I want, but no dice. So instead, I went ahead and wrote my own function.

Because I know I draw all my data from between 0 and 1 and scale it by the world’s size to get my world’s base noise data, I know what inputs I’m working with, which helps me write a quick and dirty, if utterly untransferable, function that finds the distance from 1 the input is, doubles that difference, and subtracts it from one (scaling the 1 and 0 bounding box to the 1 and -1 value range).

After a while of struggling with the module’s oddities…

I have never been so fucking happy to see such a simple graphic. Now I apply it to the terrain generator and…

That’s not what I wanted. During some experimentation, I figured out that the noise function and my world use different coordinates for up. In my world, the Y axis is up and down. For the noise, it is Z. I fixed how the axis mapped to each other and switched to the blend style, rather than select (which was giving me what you see above except with a flat wall at one point. Now, with the gradient moderating the air and sky and the noise function disturbing the border, we get this…

Much, much better. While the same could have been done easier with a heightmap, the fact this is using 3D noise instead of 2D will give me many more options in the future, including the creation of much more alien and surreal terrain like floating islands or partially hollowed mountains.

Fun with Blocks II

Leave a Reply

Your email address will not be published. Required fields are marked *