1-D and 2-D Perlin Noise, used to generate random yet smooth terrain for a map generator.
Fundamentally, the goal of Perlin Noise is to turn random input into a smooth (random) output.
Consider a sequence of real values between 0 and below 1. Let be this random sequence and .
Applying piecewise linear interpolation lets us look up any value within the discrete interval between two values:
(where is the integer part of , and is the fractional part of )
At this point we can already see the shape taking form, but it isn't very smooth yet, so we replace with a function.
We can extend the noise function beyond the interval with:
We have an unit grid. For each unit , we generate a random point .
From this we derive the corner points , , , , where:
Given a continuous function , its derivative gives the slope of the tangent line at the point .
Instead of thinking of as a two-parameter function, we can picture the value as the height of a point in 2D space. If is smooth, every point on that terrain can be related to a tangent plane.
The "slope" of the tangent plane passing through such a point is determined by the partial derivatives and .
The vector is the vector, on that plane, pointing in the direction of steepest ascent of . This vector changes at every point, depending on . It's called the gradient of , denoted .
, , , are the random gradient vectors at each corner.
For each , we find the vectors from the corners to that point :
, , ,