View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Perlin noise and procedural generation

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1TheCreeperLawyer  Members

Posted 19 January 2012 - 03:34 AM

I've recently been working on a 2d RPG adventure game in Java. I have world loading among other things and I want to use procedural generation for the landscape of the game world.

I have had no previous experience with procedural generation so this was quite a learning curve for me and I feel I have done fairly well. I finally managed to make a Perlin noise demo with help from this article here and I'm fairly happy of the result (that demo uses a persistence of 1 and 8 octaves).

Here is the code for my Perlin noise. It's very fast to generate compared to some of the other algorithms I've tried. Im using a linear interpolate method because I don't notice the difference between a cos one except for the fact that linear is MUCH quicker...

double[][] genWhiteNoise(){
Random random = new Random(seed);
double[][] noise = new double[width][height];

for(int x  = 0; x < width; x++){
for(int y = 0; y < height; y++){
noise[x][y] = random.nextDouble() % 1;
}
}

return noise;
}

double[][] generateSmoothNoise(double[][] baseNoise, int octave){
double[][] smoothNoise = new double[width][height];

int samplePeriod = 1 << octave;
double sampleFrequency = 1.0f / samplePeriod;

for(int x  = 0; x <  width; x++){
int sample_x0 = (x / samplePeriod) * samplePeriod;
int sample_x1 = (sample_x0 + samplePeriod) % width;
double horizontal_blend = (x  - sample_x0) * sampleFrequency;

for(int y = 0; y < height; y++){
int sample_y0 = (y / samplePeriod) * samplePeriod;
int sample_y1 = (sample_y0 + samplePeriod) % height;
double vertical_blend = (y - sample_y0) * sampleFrequency;

double top = interpolate(baseNoise[sample_x0][sample_y0], baseNoise[sample_x1][sample_y0], horizontal_blend);

double bottom = interpolate(baseNoise[sample_x0][sample_y1], baseNoise[sample_x1][sample_y1], horizontal_blend);

smoothNoise[x][y] = interpolate(top, bottom, vertical_blend);
}
}

return smoothNoise;
}

double[][] perlinNoise(double[][] baseNoise, int octaveCount){
double[][][] smoothNoise = new double[octaveCount][][];

for(int i = 0; i < octaveCount; i++){
smoothNoise[i] = generateSmoothNoise(baseNoise, i);
}

double[][] perlinNoise = new double[width][height];
double amplitude = 1.0;
double totalAmplitude = 0.0d;

for(int octave = octaveCount - 1; octave >= 0; octave--){
amplitude *= persistance;
totalAmplitude += amplitude;

for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
perlinNoise[x][y] += smoothNoise[octave][x][y] * amplitude;
}
}
}

for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
perlinNoise[x][y] /= totalAmplitude;
}
}

return perlinNoise;
}


First off, can someone please tell me if the noise I have generated if suitable for random world generation or if it's not, can they give me some tips and/or links to good examples.

and second, can someone please tell me a good place to start for turning that Perlin noise into a game world. I am using a tile based system and i plan on having mountains, sand dunes, forests and cities (they wont be randomly generated but they will have a random location in the world based on some placement parameters).

Any help would be very much appreciated.

### #2Telios  Members

Posted 19 January 2012 - 05:28 AM

I'm not sure it uses perlin noise specifically, but is this similar to what you're after?

http://members.gamedev.net/vertexnormal/tutorial_randlev1.html

You could quantise the noise values into discrete bands, and assign each band a tileset - grass, rock, snow, lava. You could also need edge tiles, depending on the look you're going for.

Can you show an image of the noise you're generating?

### #3TheCreeperLawyer  Members

Posted 20 January 2012 - 01:23 AM

Thanks, I'll have a look at that website when I'm back home.

I did put a link to my perlin demo in the post but here's the image anyway:

Thanks

### #4arc4nis  Members

Posted 20 January 2012 - 09:50 AM

Procedural terrain generation is an interesting topic, I'm working on a 2D MMORTS and I used the Square-Diamond Algorithm for terrain creation, I am quite happy with the result. This is a screenshot of the terrain generated for my game.

This is a great tutorial to understand the algorithm wich is easy to implement once you understand how it works
http://gameprogrammer.com/fractal.html

### #5Net Gnome  Members

Posted 20 January 2012 - 10:26 AM

<personally removed due to accidental duplicate post, check history if curious>

### #6Net Gnome  Members

Posted 20 January 2012 - 11:10 AM

i used perlin noise and ridged multi-fractal noise in mine to build biome, temp, wind, and rainfall maps. The library i used was Libnoise http://libnoise.sourceforge.net

Here is an early prototype:

### #7JTippetts  Moderators

Posted 20 January 2012 - 06:44 PM

How you translate your noise functions to a game world depends on a great many factors. Does a cell or unit in the noise map translate to a single tile in the world, or does it translate to a sub-map or region? What sorts of characteristics can a tile or region have? Typically, you're going to use more than just a single layer of noise. As an example, in this journal post, I use several layers of noise and turbulence denoting the shape of an island, elevation and roughness of terrain, aridity, etc... and translate units into tiles in a simple tile map:

Translated into tiles:

This is a very simple example. You can get more complex depending on your needs. All sorts of information can be simulated using noise maps: elevation, placement of regions, density of vegetation, etc... Add a few simulated modeling processes (erosion, weather patterns) and you can come up with some pretty complex worlds.

### #8japro  Members

Posted 20 January 2012 - 07:36 PM

Oooh, me too me too me too Island Applet. it's essentially a 2d noise heightmap that gets modulated with another noise function to create regions of different "steepness".

Just get a noise function/generator some way to output images based on it and start playing. I starts getting intuitive pretty quick.

### #9AllEightUp  Moderators

Posted 22 January 2012 - 08:22 PM

I'd also suggest looking into Ken's followup version: "Simplex Noise" as it runs considerably faster, fixes a couple of visible pattern issues in the original and is much easier overall. From there, another source of information would be the book from the masters themselves: http://www.amazon.com/Texturing-Modeling-Third-Procedural-Approach/dp/1558608486/ref=sr_1_1?ie=UTF8&qid=1327285046&sr=8-1 It's an older book but given Perlin, Musgrave and Worley talk about how they use noise and variations, some of the helper functions listed in Worley's section I believe (bias/gain being two of my favorites) are excellent starting points for getting a better understanding of how to fiddle with the output of noise functions.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.