Understanding 2D Perlin noise

I am not sure, if anybody, except me, is interested in it, but I will report here, what I learned going through the file.
Any comments, either confirmation or disapproval, are appreciated, because I am just going with what I am seeing and I never learned Java, so I might have missed things.

In general the code works as follows:

An array of random 4096 random numbers is created.
If you call your noise function with the values x, y, z, these are taken and their integer value separated from the decimal values.
The integer values are used to create a number, which acts as index number for the random number array.
It is calculated with x + 16 * y + 256 * z.
This way the 4096 random numbers are distributed over cube of 16x16x16 coordinates.
The calculated index is then used to get 8 numbers around the coordinate and interpolate with a cosine between them using the decimal values of x, y, z as input to create the return value.

Pattern repetition:
For 2D noise the same equation is used, that means that only an area of 16x16 creates unique values, everything else is a repetition. For x,y =10,10 or 26,9, 42,8 the same index number of 170 is calculated. That explains the repetition after x+16 and y-1. The repetition after 256 * y and 256 * 16 * x is simply due to reaching the maximum of the random number array. You can expand your 16x16 by scaling down, e.g. by x * 0.05 but that just gives you a cosine interpolation as noise, not real noise. It would be nice, if there would be a different case, that when z is not assigned a value, x + 64 * y is used to get at least a 64x64 area before the noise values are repeated.

In general, this type of noise is value noise (random number lattice with cosine interpolation) and not Perlin Noise(which is a gradient noise). So it does not follow the Perlin implementation as mentioned in the reference.

I would also say, that the octave implementation is not ideal. With every octave the coordinates are doubled. I think it would be better to half them with every octave. This way they would create more detail in the short-range as they should. And it would be nice to be able to set this frequency.

On a side note: The modulo in the cosine function is not necessary. i * PI is always smaller PI and therefore the modulo always returns the i * PI value.

4 Likes