# Creating Perlin Noise

This topic is 2569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, so I've been having difficulties on how to implement 2D perlin noise in my game. The problem that the articles I've read such as this and this really don't explain the concept very well. The best article I've found is this, however I still think it doesn't go into enough detail, plus there different methods.

I want to turn a texture into perlin nose. From what I understand (please correct me if I'm wrong and keep in mind I'm discussing 2D noise) you need a function that takes in a x and y grid point and returns a value with which you can then use for the gray-scale of that point or pixel in the texture. So I would loop through every pixel in my texture and assign it a gray-scale value using the function. Generating this color value is the hard part though. Again correct me if I'm wrong but I'm pretty sure you use the grid points and make a random number out of it between 0 and 1. Let's just use (2, 4) as an example. First I need a number to give the generator, how about the average of the two points? So I put in 3 and it gives me something like 0.634. After this I get completely confused because I need to check the neighboring values and have that effect my value 0.634 right? If I don't It will look completely random and not have "patches" of a color somewhere. Nothing explains how to do this well and I need help badly!!!

Could someone please explain this concept to me in a little bit better detail?

Thanks!

##### Share on other sites
What you need to generate is called a hash. You put two numbers (your x and y) into the hash function, which does some mathematical magic and spits out a number based on its two inputs. Hash functions come from cryptography, so unless you have some advanced math degree, understanding the exact details of exactly what makes a hash function a good hash function is something that probably won't happen. I have no idea why the MD5 and SHA-1 hash functions work as well as they do, but I'm not about to study cryptography to understand it. Perlin noise can get away without using military strength cryptographic hashes, so a simple hash function will work. The hash function you described is a little too simple though. You can either google for some good 2D perlin noise hash functions, or I believe alvaro's function from this thread works pretty well (look at his second post, not his first).

Don't use the MD5 or SHA-1 hash functions, I was just referencing them because they're popular cryptographic hash functions, and the general principle behind them hashing a value and the hash function you seek is the same.

##### Share on other sites
That's pure noise though, I want smooth coherent noise such as:

Sorry probably should have made that more apparent.

##### Share on other sites

That's pure noise though, I want smooth coherent noise such as:

Sorry probably should have made that more apparent.

That's what having multiple octaves are for. It sounds to me like you're only doing one octave. You should be doing multiple octaves, and then sum each octave up (but each successive octave has a higher frequency and a lower amplitude). Are you getting stuck on how to combine the octaves/making each successive octave have a higher frequency and lower amplitude?

On second thought, is it the interpolation method you're struggling with? Because you need to interpolate between the octaves as well. I know there can be a lot of new terms when it comes to making perlin noise (octaves, amplitude, frequency, interpolation, etc.), but I'm not sure which one of them it is you're struggling with so I'm not sure exactly what more to say.

##### Share on other sites

[quote name='MrSplosion' timestamp='1322881586' post='4890014']
That's pure noise though, I want smooth coherent noise such as:

Sorry probably should have made that more apparent.

That's what having multiple octaves are for. It sounds to me like you're only doing one octave. You should be doing multiple octaves, and then sum each octave up (but each successive octave has a higher frequency and a lower amplitude). Are you getting stuck on how to combine the octaves/making each successive octave have a higher frequency and lower amplitude?

On second thought, is it the interpolation method you're struggling with? Because you need to interpolate between the octaves as well. I know there can be a lot of new terms when it comes to making perlin noise (octaves, amplitude, frequency, interpolation, etc.), but I'm not sure which one of them it is you're struggling with so I'm not sure exactly what more to say.
[/quote]

Ah! I see what you're saying quick question though: In the link you provided why is all that necessary? I bet if you just simply looped though each pixel and randomly picked if it was black or white it would look the exact same. Or is there more to it? Does each pixel have a certain color to it or is it just binary black or white?

##### Share on other sites

Ah! I see what you're saying quick question though: In the link you provided why is all that necessary? I bet if you just simply looped though each pixel and randomly picked if it was black or white it would look the exact same. Or is there more to it? Does each pixel have a certain color to it or is it just binary black or white?

There's a little more to it. The thing about a hash function is that it's deterministic. That is, if you put the same thing in, you'll get the same thing out. If you start going about randomly picking values, you lose the important deterministic property of the hash function. Usually, these deterministic hash functions provide better looking results.

It is possible to have a random, non-deterministic hash function and to make perlin noise with it, but you have to be a little more careful in how you program it and realize the implications of throwing away the deterministic data. It can work well, you just have to be aware of what it is you're doing. But then again, it's hardly perlin noise if you're using random, non-deterministic hash functions, as when Ken Perlin invented Perlin noise the behavior of the hash function was deterministic.

##### Share on other sites
I see, thanks for the help! I will use this to make multiple octaves then try to combine them together. Chances are I'll ask another question but interpolating doesn't too difficult.

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013555
×