Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions regarding Perlin noise (how it works)

I'm currently trying to learn Perlin noise, specifically 2D noise for terrain generation. I've been reading articles online over the past few days, but they don't all seem to agree on how Perlin noise works, and the ones that do seem authoritative are very complex to understand.

So I have some questions that I'm hoping someone here can help clarify.

  • Some articles talk about starting with a grid of random numbers (a 2D grid for 2D noise), which makes sense. However, other articles talk about filling the grid with gradient vectors. Which is actually used for Perlin noise?

  • I don't know what a "gradient" vector is, but if it's an actual vector, that means filling each point on the grid with two numbers, right? Is it just a way to get two random numbers per grid point, or is there a reason to treat it like a directional vector? The articles talk about calculating distances between the vectors, but I thought that was what the interpolation step was for...

  • Many articles on Perlin noise talk about combining multiple levels of noise into octaves with varying frequency and amplitude, to get the nice organic results that I'm looking for. However, other articles say that Perlin noise is just a single octave, and the act of combining multiple levels of noise into multiple octaves is actually "Fractional Brownian Noise". Which is actually correct? Is Perlin noise itself just a form of white noise, not the combined noise that everyone uses it for?

  • Some articles fill out the grid with an initial set of random values to work with, and some articles just write their noise function so that it isn't entirely random, but spits out the same value for a given input. Which makes sense so the result (especially in 2D) doesn't look chaotic. But what about when you start combining multiple octaves of noise (FBN)? Does each octave need to come from the same set of values? Or can you seed a separate grid (or generator function) for each octave? I'd like to avoid repetition (seeing the same pattern repeat over the resulting image), but I don't know what the logic behind it is.

  • As far as the grid of random values (or gradient vectors...) you start with, does the size of that grid have anything to do with the final size of the image you are creating? Or is is purely a function of the frequency? As you increase the sample resolution for each octave, are you using larger and larger grids, or just resampling the same initial grid at a finer resolution?

Any clarification would be very helpful. Thanks.

like image 580
Nairou Avatar asked Aug 29 '13 13:08

Nairou


1 Answers

I don't know what a "gradient" vector is, but if it's an actual vector, that means filling each point on the grid with two numbers, right? Is it just a way to get two random numbers per grid point, or is there a reason to treat it like a directional vector? The articles talk about calculating distances between the vectors, but I thought that was what the interpolation step was for

At each co-ordinate there is only a single number, however between grid points the actual value is interpolated. As such there is a gradient between (integer*) grid points. This can be seen here in Ken Perlins original source. An input of 1,2 or 3 floats (co-ordinates in 1D,2D or 3D space) returns a single float.

*Note that the input co-ordinates may be scaled such that integer grid points aren't at integer input co-ordinates.

Many articles on Perlin noise talk about combining multiple levels of noise into octaves with varying frequency and amplitude, to get the nice organic results that I'm looking for. However, other articles say that Perlin noise is just a single octave, and the act of combining multiple levels of noise into multiple octaves is actually "Fractional Brownian Noise". Which is actually correct? Is Perlin noise itself just a form of white noise, not the combined noise that everyone uses it for?

Perlin noise technically is the single octave, but isn't very useful like that. People therefore often combine many octave to create fractal noise (other base noise functions than Perlin can be used to create fractal noise). Often people just call fractal noise based on Perlin noise Perlin noise, this is wrong but common enough that you must make allowances for it.

Some articles fill out the grid with an initial set of random values to work with, and some articles just write their noise function so that it isn't entirely random, but spits out the same value for a given input. Which makes sense so the result (especially in 2D) doesn't look chaotic. But what about when you start combining multiple octaves of noise (FBN)? Does each octave need to come from the same set of values? Or can you seed a separate grid (or generator function) for each octave? I'd like to avoid repetition (seeing the same pattern repeat over the resulting image), but I don't know what the logic behind it is.

For the same input (co-ordinates & seed) the Perlin noise function should always spit out the same output. Whether you use this to prefill a grid or just get values as you go is entirely up to you. Each octave should have a different seed. This is a defined property of Perlin noise:

  • apparent randomness, it should look random to the human eye*
  • reproducable, meaning with the same input it will always give the
    same output*
  • smooth transition between values, meaning no sharp edges*

*ref http://www.angelcode.com/dev/perlin/perlin.html

As far as the grid of random values (or gradient vectors...) you start with, does the size of that grid have anything to do with the final size of the image you are creating? Or is is purely a function of the frequency? As you increase the sample resolution for each octave, are you using larger and larger grids, or just resampling the same initial grid at a finer resolution?

The inputted co-ordinates (and things like frequency that you set the function up with) should be what determines the properties of the noise. Assuming the range of entered co-ordinates remains the same the size of the grid should only effect the resolution with which you see the noise.

Different octaves of noise should have different seeds, but they are also on different scales; you are not just resampling the same grid at finer resolution for different octaves, you are scaling your co-ordinates.

like image 129
Richard Tingle Avatar answered Sep 28 '22 23:09

Richard Tingle