## Monday, April 6, 2009

### The Base Landmass

The continent begins life as this shape right here:

It is a cross-section of a sphere at the center. The sphere begins at 0 (black) at the outside surface, and gradually fades to 1 (white) at the center. It's a pretty boring shape, though, and not at all realistic; in order to give it shape, I apply an effect known in the graphics world as turbulence. In effect, turbulence is a means of distorting the inputs to a function, by adding some randomized offset to the inputs before the function is evaluated.

Consider the above image of our sphere. It represents a function with 2 inputs: an X coordinate and a Y coordinate. The output of the function for a given XY pair is the pixel at that location in the image. Now, if we were to copy the image to another image, only this time we add/subtract some sort of offset to the input coordinates each time, we would get a distorted version of the image.

pixel(x,y) = pixel(x+randomvalue1, y+randomvalue2)

The nature of the distortion depends on the nature of the random numbers we use to distort the inputs. In the case of Archipelago's island/continent generator, I use something called continuous noise. This is a generalized case of what is commonly called Perlin noise. Perlin noise is a function composed of several octaves, or layers, of a given noise function. The noise function creates a pattern that is randomized and chaotic-appearing, and yet continuous: ie, the function varies by very small amounts at small intervals, but varies by very random (possibly large, possibly small) amounts at large intervals.

The continuous nature of Perlin noise is what is crucial here. If we were to use simple random numbers to distort the inputs, the output would be a very random, noisy, and chaotic image like this:

Now, that is certainly randomized, but it looks nothing at all like a continent. That is because the noise applied was simple white noise (ie, fully chaotic random numbers in the range [-1,1]). We need continuous noise in order to distort the shape of the sphere out of round, but still retain some measure of cohesiveness or form.

In my personal library I have access to a large number of continuous noise types, many based on the noise fractals pioneered by Perlin. Two examples of these, which constitute the continuous noise functions we need, are fBm (standing for Fractional Brownian Motion, a fancy name for what can be thought of as 'standard' Perlin noise) and Ridged Multifractal noise. Here is an image of a section of fBm noise:

and here is an image of a section of Ridged Multifractal noise:

As you can see, both types of noise are fairly continuous, yet they differ greatly in character. By using these different functions to distort the inputs to our sphere function, we can achieve two different types of landmass results. Here is the sphere distorted by fBm:

and here is the sphere distorted by Ridged Multifractal noise:

You can see the difference in the shape, or outline, of the continent that would result from using either of these functions. I implemented the ability to select the type of turbulence function the world is generated from. Here are minimaps of continents generated using first fBm and second Ridged Multifractal noise:

The fBm one tends to produce smoother coastlines and fewer jagged areas and islands because the noise function itself is smoother and less jagged. I have several other options available to me besides these two in the game as well. By selecting the right noise function for distortion, I can radically alter the appearance and character of the generated island.