Implementation of Perlin Noise on GPU
An Independent study
The aim of my independent study was to implement Perlin noise on GPU
using Cg and compare old method of producing Perlin Noise with the new
Noise is an important building
block for adding natural looking variety to procedural textures. In the
real world, nothing is perfectly uniform, and noise provides a
controlled way of adding this randomness to our shaders. Perlin noise
is one way of generating an effecient random noise.
Perlin's noise has following characteristics.
Old Perlin Noise algorithm is as follows
- It produces a repeatable pseudorandom value for each input value.
- It has known range.
- It doesn't show obvious repeating patterns.
- Its spatial frequency is invariant under translation.
- It has band-limited spatial frequency.
1. Given an input point
2. For each of its neighboring grid points:
Pick a "pseudo-random" direction vector
Compute linear function (dot product)
3. Linearly combine with a weighted sum, using a cubic ease curve in each dimension, such as 3t2-2t3,
as the interpolant. so the fade function in the below implementation returns " t*t*(3.0-2.0*t)"
4)To compute the pseudo-random gradient, we can first precompute a table of permutations P[n], and a
table of gradients G[n].
New Perlin Noise algorithm is as follows
This algorithm has two main stages.
1) The first stage generates a repeatable
pseudorandom value for every integer (x,y,z) position in 3D space.
Improved Perlin noise algorithm uses a hash function. The hash function
is based on a permutation table that contains the
integers from 0 to 255 in random order.First table is indexed based on
the x-coordinate of the position. Then the y coordinate is added to the
value at this position in the table, and the result is used to look up
in the table again. After this
process is repeated for the z cordinate, the result is a pseudorandom
integer for every possible (x, y, z) position.
2) In the second stage, this pseudorandom integer is
used to index into a table of 3D gradient vectors. In the improved
algorithm, only eight different gradients are used. A scalar value is
calculated by taking the dot product
between the gradient and the functional position
within the noise space. The final value is obtained by interpolating
between the noise values for each of the neighboring eight points in
So the fade function in the below implementation returns "t*t*t*(t*(t*6.0-15.0)+10.0)".
Tools used for implementation: Cg for implementing shaders, opengl and glut for GUI and window management respectively.
Below snap shots show noise generated using both old and new(improved) Perlin noise method.
Link for the Code: Simple_Perlin_Noise_Code
|Old Perlin Noise
||Improved Perlin Noise
Below snap shot shows marble texture generated using Improved Perlin noise algorithm.
Link for the Code: Marble_Texture_Code
|Marble Texture using Improved Perlin Noise
Below snap shot shows wood texture using improved Perlin noise algorithm.
Link for the Code: Wood_Texture_Code
|Wood texture using Improved Perlin Noise
Below snap shot shows cloud texture using improved Perlin noise algorithm.
Link for the Code: Cloud_Texture_Code
|Cloud texture using Improved Perlin Noise
Below snap shot shows fur texture using improved Perlin noise algorithm.
Link for the Code: Fur_Texture_Code
|Fur texture using Improved Perlin Noise
Following are some of the mixed color textures generated using Improved Perlin Noise.
1) Chapter 26 titled as "Implementing Improved Perlin Noise" of the GPU Gems 2 Book by Tim Sweeney , Epic Games