I'm technically a program.

What's your name?
Name: Bear

Oh? Well fuck you, Bear.

Woof is set to: 1528
Bow is set to: 200
Added together they equal: 1728

I have used 140 bytes for variables.

With code like this I’ll be a millionaire in no time.

Fun with Blocks II

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

I’ve been experimenting with a new project to find out what exactly goes into creating a voxel-based procedurally generated world, such as Dwarf Fortress or Minecraft. I figured that even if I don’t really turn it into much, creating a game completely from scratch would help me learn generic skills that could be easily applied to other games or applications. A procedural sandbox world would alleviate me of the need for plot or characters, allowing me to focus on basics.

Using some Perlin Noise to generate a heightmap, the results have been fairly pleasant, mixed with the occasional failure.

A basic perlin noise function with a low frequency generates some unnaturally smooth hills, though by decreasing their size significantly (to half at the very tallest), they can serve as rolling hills for grassland.

Increasing the octave to make it more detailed (and adjusting the fog and grass block material)…

Gives us fairly realistically shaped mountains!

However, while restructuring the code I accidentally removed the call to generateLight and wondered why my terrain had suddenly turned black and ominous. It took me an hour to fix. Small victories.