Title: CSE 681 Perlin Noise Turbulence Functions
1CSE 681Perlin Noise (Turbulence) Functions
2Noise
- Nature has a random or fractal look
- Level of detail property
- Mountain range
- Coastline
Ken Musgrave
Gunther Berkus via Mojoworld
3Level Of Detail
- Level of detail defines fractional dimensions
- Detail at all levels of magnification
4Perlin Noise
- Ken Perlin (1985) defined Perlin noise that could
be used to define natural looking textures
Ken Musgrave
Ken Perlin, 1985
5Perlin Noise
- Goal Textures that look natural
- Tools (fractal properties)
- Randomness
- Level of detail (scale)
6Noise Function
- Random values 0 1 defined on an integer
(discrete) lattice - Use a random number generator
7Resolution
- Take examples on a 2D integer lattice
- What resolution (or scale) do we use?
- Remember, we want to evaluate at any (s, t, r)
10 x 10
64 x 64
256 x 256
8Noise Function Interpolation
9
10
11
12
13
14
9Level of Detail Magnification
- What if we zoom into the noise texture?
10Level of Detail Minification
- What if we zoom out of the noise texture?
Sample too sparsely - no continuity
11Turbulence
- Idea Construct a noise function by adding
together noise functions sampled at different
scales - Scale sample resolution frequency
- Function values (random) amplitude
12Turbulence
131D Turbulence Sin Wave Examplesin(x)
141D Turbulence Example sin(x), 1/2 sin(2x)
Half amplitude Double Frequency
151D Turbulence Example sin(x), 1/2 sin(2x),
1/4 sin(4x)
161D Turbulence Example Add sin(x) 1/2 sin(2x)
171D Turbulence Example Add sin(x) 1/2
sin(2x) 1/4 sin(4x)
181D Turbulence Example Add sin(x) 1/2
sin(2x) 1/4 sin(4x) 1/8 sin(8x)
191D Turbulence Noise Example
202D Turbulence Example
21Building a 1D Turbulence Function
- Define noise functions on the interval 0 1
with increasing resolutions - Lets assume power of two resolutions
0
1
20
21
- Evaluate at a location x Î 0 1
- Interpolate on each scale
- Evaluate at any location
22
23
22Building a 1D Turbulence Function
- Pre-compute noise functions into textures
- Sample and interpolate on the textures
- Large storage cost
- One 3D texture per resolution
- Compute on-the-fly
23Building a 1D Turbulence Function
- double turbulence(double x)
-
- double value 0
- double f
- for (f MINFREQ f lt MAXFREQ f 2)
- value noise(x f) / f
- return(value)
Frequency a power of two
- Random number generator
- Can add smoothing here
Amplitude
24The Noise Function
- double noise(double x)
-
- int int_x (int)x
- double fract_x x int_x
-
- double r1 random(int_x)
- double r2 random(int_x 1)
- return interpolate(r1, r2, fract_x)
-
- Noise depends on the location x
- Each integer lattice location must be assigned
only one random value - An integer lattice value may be used many times
for texture sampling - How do we define random to ensure this?
25Random Number Invariance
- We want to ensure that the random numbers
generated at each scale and integer lattice
location does not change at each function
evaluation - Use a seeded random number generator
- Use a prime number generator (one per scale)
- Pre-compute random numbers
26Random Number Invariance
- Assume our highest texture resolution is 256
- Construct a table of random numbers
- NoiseTable256 random values 0, 1
- Construct a table of index values
- Index256 Random permutations of values 0,
255 - random(i) NoiseTableIndexi, where i is an
integer lattice location
27Building a 3D Turbulence Function
Use a 256 x 256 x 256 Array
Deposit random values at integer grid points
28Random Number Generation
- Construct 1D tables
- NoiseTable256 random values 0, 1
- Index256 Random permutations of values 0,
255 - Random number depends upon integer lattice
location - define PERM(v) Indexv 255
- define INDEX(ix, iy, iz) PERM(ix PERM(iy
PERM(iz))) - double random(i, j, k)
- return NoiseTableINDEX(i, j, k)
293D Volume Interpolation
d110
303D Turbulence Function
- double turbulence(double x, double y, double z)
-
- double value 0
- double f
- for (f MINFREQ f lt MAXFREQ f 2)
- value noise(x f, y f, z f) / f
- return(value)
-
- noise(x, y, z)
- Get integer (ix, iy, iz) and fractional parts
(fx, fy, fz) - Get cell lattice noise values
- d000,d001,d010,d011, d100,d101,d110,d111
- Do the trilinear interpolation by fx, fy, fz
31Smoothing
- Smooth out the sharp function slopes between the
lattice values - Why ? - Theres a discontinuity in the
derivatives between neighboring lattice element
values - Alternative is to use higher order interpolation
- Cubics, cosine interpolation, hermite splines
can be expensive!
before
after
32Wood and Marble Textures
- Marble
- texture cos( x turbulence(x, y, z))
- Weight this on two colors (black and white here)
- Wood
- g turbulence (x, y, z) 20, grain g -
int(g) - Use this with our concentric rings
33More Marble
- double marble(x, y, z)
- return undulate(sin(2pz Aturbulence(x, y,
z))) - undulate(double x)
- if (x lt -0.4)
- return 0.15 2.857 SQR(x 0.75)
- else if ((x lt 0.4)
- return 0.95 2.8125 SQR(x)
- else
- return 0.26 2.66 SQR(x - 0.7)
-
- define SQR(x) x x
34More Marble
- double marble(x, y, z)
- return (1 sin(pz turbulence( 3p/ 2 x, 3p/2
y, 3p/2 z))) / 1.25 / 2 -
- Given a base color compute a texture color as
- white (1, 1, 1)
- t marble(x, y, z)
- baseColor (1 - t) white t