CGT 581 G Procedural Methods Fractals Bedrich Benes, Ph.D. Purdue University Department of Computer Graphics Technology Procedural Techniques Model is generated by a piece of code. Model is not represented as data! The generation can take some time and of course the data can be pre calculated Procedural Techniques Three huge (vague) classes: Fractals Particle systems Grammars Used when shape cannot be represented as a surface (fire, water, smoke, flock of birds, explosions, model of mountain, grass, clouds, plants, facades, cities, etc.) The Mandelbrot Set the big logo The Mandelbrot set Discovered in 1970 by Benoit Mandelbrot It is a non linear deterministic fractal It is graph of a solution of a dynamic system Benoit Mandelbrot Used for Simulation of Natural Phenomena
The Mandelbrot Set Take the equation where: and are complex numbers and Explore complex numbers from the complex plane The Mandelbrot Set there are two kinds of points: for, (stable points) for certain and greater (unstable points) Measure the speed of divergence of the i.e., measure when (predefined value) The Mandelbrot Set a) stable points displayed in black b) unstable points The Mandelbrot Set Zooming into the Mandelbrot set for every point c in the plane <-2-2i>, <2+2i> do set z=0+i0 set n=0 while (n<max) and ( z <2) do z=z 2 +c end of while if (n==max) Draw Point(Black) else Draw Point(Color(n)) end of for
The Mandelbrot Set Zooming into the Mandelbrot set The Mandelbrot Set Zooming into the Mandelbrot set The Mandelbrot Set Zooming into the Mandelbrot set The Mandelbrot Set Zooming into the Mandelbrot set
The Mandelbrot Set Dimensions Dimension how long is the coast of Corsica? A stick of 500m will give 700km (not very precise) A stick of 100m will give 1200km (?) http://www.youtube.com/watch?v=0jgaio87u3a What if we use length equal to? The length will be Dimensions How long is the coast of Corsica? applied sticks of length times the total length is stick of the length and we need pieces if we need Dimensions In the case of Corsica we need to use formula to get reasonable results What is this D? (Richardson)
Dimensions How long is the coast of Corsica? Having we get Dimensions For a line segment we need to set it the case of Corsica needs to be non integer with (i.e., getting the stick shorter) we get The D is so called Hausdorff dimension Sometimes called fractal dimension Fractals (usually) do not have dimensions Fractals Fractals fractal is a set that is self similar, it is a set that is copy of itself here is transformation scales down Scale must be average contraction Fractals Vaguely Fractal is a set that is geometrically complex and its structure is given by repetition of a certain shape at different scales. Fractal is a set that has Hausdorff s dimension greater than its dimension topological
Fractals Classification Linear Deterministic Fractals Classification Deterministic (or exact) fractals Non deterministic or random fractals Depends on the type of self similarity (exact, random) Non-linear Fractals Non-deterministic Linear rotation, scale, translation, shear Non linear the others Depends on the used transformations Dimensions Special cases If we use just ONE transformation with fixed and repetitions the fractal dimension is Linear Deterministic Fractals The Cantor s discontinuum (published in 1883) 1) Take a line segment 2) Sale it 1/3x 3) Make two copies at the ends 4) Do it recursively (Georg Cantor - 1845-1918)
Linear Deterministic Fractals What is the dimension of the Cantor s discontinuum? scale new pieces for this we can use formula this object is something between a point and a line Linear Deterministic Fractals The Koch s snowflake 1) Take a line segment 2) Erase the mid third (similar to Cantor) 3) Create equilateral triangle 4) Repeat this recursively Scale,, Properties: does not have derivative infinite length zero area the area inside is non zero and non infinity (Helge von Koch 1870 1924) Linear Deterministic Fractals Linear Deterministic Fractals The Sierpinsky gasket 1) Take a triangle 2) Erase mid triangle 3) Repeat this recursively (Wacław Franciszek Sierpiński 1882-1969) The Menger sponge 1) Take a cube 2) Erase mid cross of cubes 3) Repeat this recursively (Karl Menger 1902-1985) Scale not plane, not line Note the similarity with Pascal triangle Dust of points.
Linear Deterministic Fractals The Peano curve 1) Take a line segment 2) Substitute it by the lines from the image 3) Repeat recursively on each line segment space filling curve (Guiseppe Peano 1858-1932) Non Linear Deterministic Fractals Quaternions if we apply the formula in quaternion space (hypercomplex numbers 4D) Non Linear Deterministic Fractals Linear Non Deterministic Fractals Involve random numbers and linear transformations Motivation: What would you hear if you increase the speed of playing music? Noise? The speed change is scaling Daniel White In other words: How large is this stone? 10cm? 1m? 10m?
Linear Non Deterministic Fractals Linear Non Deterministic Fractals The way to model random features in nature is capturing the self similarity with stochastic processes The key for these models are noise functions Noise is (usually) self similar Brownian Motion Brownian motion (Bm) Particles of pollen in water They move because of random hits of molecules of water Brownian Motion 1D Bm simulation: Random hits have Gaussian random number distribution This is also special case of the random walk Bm app
Brownian Motion How to get Gaussian Random numbers? Brownian Motion determines how steep the curve is the rand() function generates suppose we have of such numbers the Gaussian random number is: N=1 N=2 N=3 N=4 N=5 N=10 Gauss app Brownian Motion White noise is a random function with a constant power density Discrete samples are uncorrelated with and Brownian Motion 1D Bm simulation (contd.): Let s have that moves a point in the direction it has Gaussian random numbers distribution Gaussian white noise is one of them
Brownian Motion the Bm (Brownian function) we accumulate the perturbations W(t) X(t) is The fractal dimension is D=1.5 Bm app Fractional Brownian Motion (fbm) fbm if we scale the Bm in the axis by coefficient we have to scale in the y axis by, where is so called then the fractal dimension of the curve is this curve is called Fractional Brownian Motion or fbm (this is NOT Fractal Brownian Motion) Fractional Brownian Motion (fbm) Fractional Brownian Motion (fbm) fbm fbm has i.e., it is Bm fbm has fbm has higher D means wilder H=0.5 autocorrelation is 0 H<0.5 autocorrelation is positive H>0.5 autocorrelation is negative
Linear Non Deterministic Fractals In order to generate nice fractals, we need fbm The above described function is good The Midpoint Displacement Algorithm the MDP is the key algorithm for fractals 1) Take a line segment 2) Find its midpoint (center) 3) Move it randomly in the direction 4) Apply this step to all lines recursively But it does not provide adaptive results The Midpoint Displacement Algorithm The random numbers distribution has its and. Scale down the by two in every iteration. Divide the Gaussian random numbers by two The Midpoint Displacement Algorithm If we divide in each step by is the Hurst exponent we will get fbm with dimension
The Midpoint Displacement Algorithm Properties easy to implement it is interpolation of two points, so it is also called Fractal interpolation just division by two and random numbers call quite realistic The Midpoint Displacement Algorithm Two dimensional fbm works with 2D arrays it is called fbm surface dimension is, where so the The Midpoint Displacement Algorithm 2D fbm on quadrilaterals (diamond square) The Midpoint Displacement Algorithm 2D fbm on quadrilaterals (diamond square) having four points P 0,P 1,P 2,P 3 1) Evaluate the midpoint 2) Evaluate points on the edges 3) Evaluate points in the middle 4) Ad 2) etc... MDP app
Random Faults Random Faults Another method for generating fbm 1. take an object 2. divide it into two parts 3. increase the elevation of one and decrease the other one (change color, etc.) 4. apply this step many times 5. in each decrease the intensity of changes 2x 6. the limit of this process is fbm Cuda random faults Random Faults Implementation Data: 2D array Algorithm: Do this many times: 1) Generate random line (get two random points) 2) For each point in the 2D array I. Check if it is on the left or right (dot product) II. Increase/decrease the value Random Faults Variations Use any 2D object (circle, square) Randomly alter the area inside/outside
Random Faults on a Sphere Random Faults on a Sphere 1) Take sphere and divide it randomly into two hemispheres 2) Assign to each hemisphere different color 3) Apply the step 1 recursively, but decrease the intensity in each step with Perlin Noise Ken Perlin 1985, 2002 Perlin, K. (1985). An image synthesizer. ACM Siggraph Computer Graphics, 19(3), 287 296. Perlin, K. (2002). Improving noise. ACM Trans. Graph. 21, 3 (July 2002), 681 682. Academy Award for Technical Achievement 1997 Perlin Noise Properties: Statistically invariant to rotation and translation Continuous Perlin Noise is 1D, 2D, 3D, nd, Limited frequency spectrum Repeatable (returns the same value for the parameters) double noise(double t) //1D case double noise(double x, double) //2D case double noise(double x, double, y, double z)//3d case
Perlin Noise Limited frequency spectrum means we can chose the maximum desirable detail Returns value from It is seeded by the input parameter Perlin Noise Algorithm Initialization Divide the space to equally distributed cells with integer coordinates Each cell has a predefined pseudorandom gradient Matt Zucker Matt Zucker Perlin Noise Algorithm Perlin Noise Call: By calling with non integer coordinates,, Find the corresponding cell,,,, Calculate the vector from,, to each vertex The influence of each vertex Matt Zucker is given by its distance Sum the contributions by using sigmoid weighting function 3 2 For large tables hash function is used Matt Zucker
Summing Noise Functions Summing Noise Functions Maintains the overall shape where Add details and higher frequencies is called persistence is called noise frequency Summing Noise Functions Summing Noise Functions octaves=1 octaves=2 octaves=3 octaves=7 Paul Bourke
Turbulence Start with a simple color ramp Turbulence marble Perturb it by Perlin noise defines the influence (amplitude) of each octave 3 6 10 octaves Turbulence wood Subtract the integer part of Perlin noise: Hypertexture Defines properties close to the object surface It is a procedural definition, just perturbs the space Can be displayed by raycasting
Hypertexture libnoise http://libnoise.sourceforge.net/index.html Ken Perlin Diffusion Limited Aggregation DLA Diffusion Limited Aggregation DLA 1) Particles (molecules) are floating in the water 2) When a particle approaches an condensation center it is aggregated 3) The process is repeated for many particles The important part is the way the particles travel i.e., random walk Corals, lightings, frozen ice on a window, etc.
Diffusion Limited Aggregation DLA Diffusion Limited Aggregation DLA Corals app