Download Stochastic Fractals

Document related concepts
no text concepts found
Transcript
Simulation and Animation
Fractals
computer graphics & visualization
Fractals and fractal landscapes
Fractals:
• „Die fraktale Geometrie der Natur“, B. Mandelbrot, Birkhäuser
• „The Science of Fractal Images“, H.-O. Peitgen, D.Saupe, Springer Verlag
Fractal landscapes:
• „Texturing and Modeling, A Procedural Approach“ ,
D. Ebert et al.
AP Professional, Cambridge – available in our library
• www.wizardnet.com/musgrave/
• www.javaworld.com/javaworld/jw-08-1998/jw-08-step.html
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals and fractal landscapes
Fractal shapes in nature:
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
How to generate fractal landscapes
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Midpoint Displacement
• Random Midpoint Displacement
– Interpolation and displacement
– Decreasing random displacements in each iteration
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Midpoint Displacement
• Random displacements Di (i: subdivision level)
– Di has normal distribution  E[Di]=0
– Di = N(0,i2) = i N(0,1)
– Standard deviation i
– Variance(Di) = i2 = (i-1 1/2H)2
 Xi+1(t) and 1/2H Xi(2t) are statistically self-similar
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Midpoint Displacement
• Terrain generation
– Interpolate new values from adjacent values
– Add random displacement
Old points
New points
– Values are influenced by adjacent squares
– Creases are introduced by early iterations
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Midpoint Displacement
• Terrain generation – the Diamond Square algorithm
http://62.65.146.182/java/fractal/fract.htm
http://users.bestweb.net/~hogdog/fractal.htm
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Midpoint Displacement
Successive refinements in 2D
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals
• What is a fractal
– Well, many different fractals exist
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals
• Fractal = abbreviation for „Fractional Dimension“
– Any curve or surface that is independent of scale –
it looks the same over all ranges of scale
• If blown up in scale, any part appears identical to the whole
– „Exact“ Self-Similarity (Deterministic Fractals)
• Iterations of a scaling process
SierpinskiTriangle
KochCurve
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals
Fractals
– „Statistical“ Self-Similarity (Stochastic Fractals)
• If blown up in scale, any part appears statistically similar to the
whole
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals
• Fractional dimension
– Measure for the „roughness“ of a curve/surface
• E.g. a rough curve may cover the surface it is defined on
– Somewhere between dimension N and N+1
• Characterizes the increase of measured length between given points as scale
decreases
log( L)
D
log( 1 / s)
• L: number of self-similar pieces
• s: length of the pieces (in units)
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractals
• Fractional dimension
– Example: The Koch-Curve
log( 4)
D
 1.26
log( 3)
– It fills more space than a line (D=1) but less space
than a Euclidean area of the plane (D=2)
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
1. Pick a starting point (x0,y0).
2. Choose an index i with a given probability p
3. Compute the next point as follows:
xn+1= aixn+ biyn+ ei
yn+1= cixn+ diyn+ fi
4. Plot the new point and goto step 2
i
0
1
2
3
a
0.0
0.2
-0.15
0.75
b
0.0
-0.26
0.28
0.04
c
0.0
0.23
0.26
-0.04
d
0.16
0.22
0.24
0.85
e
0.0
0.0
0.0
0.0
f
0.0
1.6
0.44
1.60
p
0.10
0.08
0.08
0.74
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
• Iterated Function Systems
• Repeated transformation of simple patterns on smaller and smaller scales
(by means of affine transformations)
a b
xi 1  Axi  
c d
x
e  
 y 
f  
1 
• Select transformation (from set of possible transformations)
randomly with certain probablity
Example: Fern
i
0
1
2
3
a
0.0
0.2
-0.15
0.75
b
0.0
-0.26
0.28
0.04
c
0.0
0.23
0.26
-0.04
d
0.16
0.22
0.24
0.85
e
0.0
0.0
0.0
0.0
f
0.0
1.6
0.44
1.60
p
0.10
0.08
0.08
0.74
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
• Mandelbrot Set
• Evaluate recursively for inital points c in complex plane
zi 1  zi2  c
with z0  0
• Color points in the plane corresponding to rate of divergence
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
• Julia Sets
• For fixed c, points zi on the
complex plane for which does
not tend to infinity
zi 1  zi2  c
• Or more general:
– zn+1 = f(zn)
– E.g.:
zn+1 = c sin(zn)
zn+1 = c exp(zn)
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
Stochastic Fractals
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fractal generation processes
• Stochastic Fractals
– Simulation of Fractal Brownian motion (FBm)
• Probability as a tool for modelling
– Modelling of (dynamic) natural phenomena
• Terrains, clouds, water etc.
– Modelling and rendering of solid textures
• Marble, wood etc.
• Procedural shaders
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian Motion
– Discovered 1827 by botanist R. Brown
• Behavior of pollen in water
– Describes the movement of small particles of solid
matter in liquid
– Mathematical examination by Einstein and Wiener
• Dynamics of molecular collisions
• Pollen particles being hit by water molecules
– Used by Mandelbrot for the modelling of natural
phenomena
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian Motion - a little statistics
– Continuous random variable X
– Probability distribution function F(x) = P(Xx)
– Probability density function f(x)  0

 f (t )dt  1
x
F ( x) 

 f (t )dt


– Expectation E[X]:
 x  f ( x)dx

– Variance Var[X] = E[(X-E[X])2]
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian motion – a little statistics
– Example: Gaussian Distribution N(,2)
f ( x) 
1
e
 2
1  x 
 

2  
2
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian motion – „Random Walk Process“
– Brownian motion is a stochastic (random) process
– Describes the movement of a particle over time t
X(t+t) = X(t) + v · t · N(0,1)
• X: particle position
• v: speed of particle
• N(0,1): normal distributed random variable
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian motion – properties
– The increments X(t2)-X(t1) have Gaussian
distribution
 E[X(t2) – X(t1)] = 0
– Var[X(t2) – X(t1)]  |t2-t1|
• Continuous but nowhere differentiable
– Increments X(t+h)-X(t) are independent of t
• Brownian motion is stationary
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian motion
– If X(t0)=0  X(t) and X(rt)/r0.5 are statistically
equivalent
– Brownian motion –
more than noise!
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• White noise (1/f0-noise)
– Completely uncorrelated from sample to sample
• Independent of the past
– Flat spectrum – all frequencies with the same amount of energy
– Simulated by the pseudo-random generator
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• 1/f-noise
– It is correlated from sample to sample
– Lower frequencies contribute most
– Often found in nature (clouds, water, growth processes)
• E.g. Kolmogorovs spectrum
– Complex generation process
• See next chapter
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Brownian motion
– It is the integration of white noise – also called 1/f2-noise
– More correlated than white noise and 1/f-noise
– Correlated (constraint) random walk
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Fractal Brownian motion (FBm)
– Extension of Brownian motion
•
•
•
•
Var[X(t2) – X(t1)]  |t2-t1|2H
H: Hurst exponent
X(t), 1/rH X(rt) are statistically self-similar with respect to H
0  H  1 determines the roughness of the structure
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Fractal Brownian motion (FBm)
H = 0.5: increments are not correlated
 Brownian motion
H > 0.5: increments have positive correlation
 Increasingly smoother curves
H < 0.5: increments have negative correlation
 Increasingly rougher curves
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Fractal Brownian motion - 1/f-noise
– Fractal dimension D = d+1-H = d + (3-)/2
– d: topological dimension
– Curves:
– Surfaces:
– Volumes:
d=1: D = 2-H =(5-)/2
d=2: D = 3-H =(7-)/2
d=3: D = 4-H =(9-)/2
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• FBm
=1
D=2
 = 1.5
D = 1.75
 = 2 (Bm)
D = 1.5
 = 2.5
D = 1.25
=3
D=1
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Stochastic fractals
• Generation processes for (multi-dimensional) FBm
– Midpoint displacement
• „Sum of sawtooth waves of successively doubled and scaled
frequencies“
– Rescale-and-Add
• „Sum of band-limited random basis functions with scaled
frequencies“
– Fourier domain synthesis
• „Sum of sine-waves with random phase and scaled
frequencies“
Citations from K. Musgraves PhD thesis
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
• Noise synthesis by point evaluation
– Summation of scaled and dilated noise functions
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
Add weighted noise octaves to simulate 1/f-noise
weights 1/20
1/21
1/22
1/23
1/24
1/25

=
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
Another method to simulate 1/f-noise
Generate noisy copies on-the-fly from a base random field
1/24
1/23
1/22
=
•••
1/21
1/20
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
• Noise synthesis by point evaluation
– Summation of scaled and dilated noise functions
i
VH ( x, y )  
k 0
1
r
(i k ) H
S (r
 k x
x, r
 k y
y)
• S: noise function
– N(0,1) distributed random numbers given on „integer lattice“
– Band-limited, smooth, continuous
• r: lacunarity: average size of gaps (typically r=2)
– Adding noise octaves at decreasing frequency but increasing
amplitude
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
• Implementation of the Noise() function
• Lattice noise
– N(0,1) variables at grid points (lattice noise)
– Multi-dimensional interpolation (value noise)
» bi/tri-linearly
» Spline-interpolation
• Gradient noise
– Compute pseudorandom gradients at grid points
» Uniformly distributed over the unit circle (sphere in 3D)
– For point p and each adjacent grid point compute
» fraction = p – int[p]
» gradient[int[p]] · fraction (is a scalar product)
– Linearly interpolate results at p
» Interpolation weights are 1- fraction
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Gradient Noise
1.
2.
3.
+
+
Given an input point
For each of its neighboring grid points:
•
Pick a "pseudo-random" gradient
vector
•
Compute linear function (dot product)
Take weighted sum, using thease curves
+
=
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
• Implementation of Noise() function
– Memory optimization
• Storing values at each grid point too expensive
– Use hash table or permutation array
• PermTab[N] = 5,1,28,43,11,... // permutation of first N-1
integers
• NoiseTab[N] = 0.1, 0.7, ... // N N(0,1) random values
• 2D example:
Noise((int)x, (int)y) = NoiseTab[PermTab[(x+PermTab[y]) % N]]
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rescale-and-Add
• Local parameter variation
– Fractal dimension D = d+1-H
log( r kH ) kH log( r ) H
H 


k i
log( r ) k i log( r )  i
'
i
– Anisotropic fractal dimension in space
and time
– Often called multifractals (heterogeneous fractals)
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Application of noise
• Random surface texture
– Color = white * noise(point)
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Application of noise
• Colored noise
– Color = Colormap (noise(k*point))
– k controls the feature size - the larger k is, the
smaller the feature
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Application of noise
• Classical Turbulence function
(note similarity to Rescale-and-Add method)
function turbulence(p)
t = 0
scale = 1
while (scale > pixelsize)
t += abs(Noise(p/scale)*scale)
scale /= 2
return t
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Application of noise
Simulating marble effects
function marble(p)
x = p[1] + rurbulence(p)
return marble_color(sin(x))
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Application of noise
Using turbulence to modulate sphere radius
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
• Fourier transform
– Two different approaches to describe a function
• Spatial domain vs. frequency domain
– Every reasonable function f can be represented as a superposition of
harmonic (sin/cos) functions

F (t ) 

f ( x)e  2itxdx,


f ( x) 
2itx
F
(
t
)
e
dt


• Output is an imaginary number S(t)=R(t)+iI(t)=S(t)ei(t)
– S(t) : amplitude
– (t) : phase angle
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
• Fourier transform
– Superposition of harmonic functions
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
• The discrete Fourier transform of images
– The sampled Fourier transform contains
frequencies needed to represent the domain
1
F (u, v)  2
N
1
I ( x, y )  2
N
N 1 N 1
 I ( x, y)e
 2i (
ux vy
 )
N N
x 0 y 0
N 1 N 1
 F (u, v)e
2i (
ux vy
 )
N N
u 0 v 0
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
Example of image and transformed image
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
• Frequency synthesis – general idea:
– Generate appropriate spectrum
– Apply inverse Fourier-Transform
• Frequency synthesis of fractal (1/f-spectrum) landscapes:
1) Generate 2D lattice noise signal
2) Transform 2D signal into the frequency domain
3) Muliply complex numbers with appropriate 1/f-filter
4) Inverse transform
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
Basic algorithm
Random noise
Noise spectrum
Frequency filter
Result after
inverse FFT
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Fourier Domain Synthesis
• Properties
– Global technique
• Does no allow for local changes of parameters
• Adaptive selection of frequencies (size of details) not
possible
• High-memory consumption
– Efficient
• Modification and scaling in frequency space
• Inverse FFT
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
What we have learned
• What is a fractal
• Statistical properties of stochastic fractals
– Can model certain objects/structures/movements
realistically
• Generation techniques for stochastic fractals
– Global techniques
• Midpoint displacement
• Fourier domain synthesis
– Local/functional approach
• Rescale-and-add
• Generalization of Perlins turbulence function
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rendering Fractal Landscapes
• Alternative methods:
– Polygon rendering using graphics hardware
• Tesselate the height field
• Draw each triangle separately or
• Perform adaptive level-of-detail rendering
– Ray-tracing
• A) Tesselate the height field and trace the triangle mesh
• B) Directly trace the fractal (QEAB)
Check out http://www.vterrain.org/
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rendering Fractal Landscapes
• Polygon rendering
– Tesselation is given implicitely or can be generated
 A height field over a rectangular domain, values are given at discrete
sample points
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Rendering Fractal Landscapes
• Rendering lit and textured triangles
– Vertices, colors, texture coords, normals
Textured only
Textured and shaded
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization
Quality
Check out http://www.planetside.co.uk/gallery/f/tg2
Simulation and Animation – SS 07
Jens Krüger – Computer Graphics and Visualization Group
computer graphics & visualization