Introduction To Noise Functions
![]() |
![]() |
Definitions
![]() | Sin Wave |
![]() | Noise Wave |
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Persistence
frequency = 2i amplitude = persistencei
Frequency | 1 | 2 | 4 | 8 | 16 | 32 | ||||||||
Persistence = 1/4 | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | = | ![]() | |
Amplitude: | 1 | 1/4 | 1/16 | 1/64 | 1/256 | 1/1024 | result | |||||||
Persistence = 1/2 | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | = | ![]() | |
Amplitude: | 1 | 1/2 | 1/4 | 1/8 | 1/16 | 1/32 | result | |||||||
Persistence = 1 / root2 | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | = | ![]() | |
Amplitude: | 1 | 1/1.414 | 1/2 | 1/2.828 | 1/4 | 1/5.656 | result | |||||||
Persistence = 1 | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | + | ![]() | = | ![]() | |
Amplitude: | 1 | 1 | 1 | 1 | 1 | 1 | result |
Octaves
Making your noise functions
function IntNoise(32-bit integer: x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end IntNoise function |
Interpolation
Linear Interpolation: |
function Linear_Interpolate(a, b, x) return a*(1-x) + b*x end of function |
Cosine Interpolation:
function Cosine_Interpolate(a, b, x) ft = x * 3.1415927f = (1 - cos(ft)) * .5 return a*(1-f) + b*f end of function |
Cubic Interpolation:
function Cubic_Interpolate(v0, v1, v2, v3,x) P = (v3 - v2) - (v0 - v1) Q = (v0 - v1) - PR = v2 - v0S = v1 return Px3 + Qx2 + Rx + S end of function |
Smoothed Noise
![]() ![]() ![]() |
function Noise(x) .. end function function SmoothNoise_1D(x) return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4 end function |
2-dimensional Smooth Noise
function Noise(x, y) .. end function function SmoothNoise_2D(x>, y) corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8center = Noise(x, y) / 4 return corners + sides + center end function |
Putting it all together
1-dimensional Perlin Noise Pseudo code
function Noise1(integer x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end function function SmoothedNoise_1(float x) return Noise(x)/2 + Noise(x-1)/4 + Noise(x+1)/4 end function function InterpolatedNoise_1(float x) integer_X = int(x) fractional_X = x - integer_Xv1 = SmoothedNoise1(integer_X) v2 = SmoothedNoise1(integer_X + 1) return Interpolate(v1 , v2 , fractional_X) end function function PerlinNoise_1D(float x) total = 0p = persistencen = Number_Of_Octaves - 1 loop i from 0 to nfrequency = 2iamplitude = pitotal = total + InterpolatedNoisei(x * frequency) * amplitude end of i loop return total end function |
2-dimensional Perlin Noise Pseudocode
function Noise1(integer x, integer y) n = x + y * 57n = (n<<13) ^ n; return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0); end function function SmoothNoise_1(float x, float y) corners = ( Noise(x-1, y-1)+Noise(x+1, y-1)+Noise(x-1, y+1)+Noise(x+1, y+1) ) / 16sides = ( Noise(x-1, y) +Noise(x+1, y) +Noise(x, y-1) +Noise(x, y+1) ) / 8center = Noise(x, y) / 4 return corners + sides + center end function function InterpolatedNoise_1(float x, float y) integer_X = int(x) fractional_X = x - integer_Xinteger_Y = int(y) fractional_Y = y - integer_Yv1 = SmoothedNoise1(integer_X, integer_Y) v2 = SmoothedNoise1(integer_X + 1, integer_Y) v3 = SmoothedNoise1(integer_X, integer_Y + 1) v4 = SmoothedNoise1(integer_X + 1, integer_Y + 1) i1 = Interpolate(v1 , v2 , fractional_X) i2 = Interpolate(v3 , v4 , fractional_X) return Interpolate(i1 , i2 , fractional_Y) end function function PerlinNoise_2D(float x, float y) total = 0p = persistencen = Number_Of_Octaves - 1 loop i from 0 to nfrequency = 2iamplitude = pitotal = total + InterpolatedNoisei(x * frequency, y * frequency) * amplitude end of i loop return total end function |
Applications of Perlin Noise
1 dimensional
Controlling virtual beings: | |
Drawing sketched lines: | ![]() |
2 dimensional
Landscapes: | |
Clouds: | |
Generating Textures: |
3 dimensional
3D Clouds: | |
Animated Clouds: | |
Solid Textures: |
4 dimensional
Animated 3D Textures and Clouds: |
![]() Copyright Matt Fairclough 1998 | The land, clouds and water in this picture were all mathematically generated with Perlin Noise, and rendered with Terragen. |
![]() | The clouds in this demo are animated with 3D perlin Noise. The algorithm had to be modified slightly to be able to produce Perlin Noise in real time. See the Clouds Article for more info on how this was done. |
Generating Textures with Perlin Noise
The following textures were made with 3D Perlin Noise
![]() | |
![]() | |
![]() | |
![]() | |
![]() |