20
CGT 581 – G Procedural Methods Fractals Bedrich Benes, Ph.D. Purdue University Department of Computer Graphics Technology © Bedrich Benes 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 © Bedrich Benes 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.) Used for Simulation of Natural Phenomena © Bedrich Benes 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

CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

Embed Size (px)

Citation preview

Page 1: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

CGT 581 – G Procedural MethodsFractalsBedrich Benes, Ph.D.Purdue UniversityDepartment of Computer Graphics Technology

© Bedrich Benes

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

© Bedrich Benes

Procedural TechniquesThree huge (vague) classes:• Fractals• Particle systems• GrammarsUsed  when shape cannot be represented as a surface (fire, water, smoke, flock of birds, explosions, model of mountain, grass, clouds, plants, facades, cities, etc.)

Used for Simulation of Natural Phenomena

© Bedrich Benes

The Mandelbrot Set – the big logoThe Mandelbrot set• Discovered in 1970 by  Benoit Mandelbrot

• It is a non‐linear deterministic fractal

• It is graph of a solution of a dynamic systemBenoit Mandelbrot

Page 2: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

The Mandelbrot SetTake the equation

where:and  are complex numbers and 

Explore  complex numbers from the complex plane Measure the speed of divergence of the i.e., measure when  (predefined value)

© Bedrich Benes

The Mandelbrot Set

there are two kinds of points:for  ,  (stable points)for certain  and  greater    (unstable points)

© Bedrich Benes

The Mandelbrot Seta) stable points  displayed in blackb) unstable points

for every point c in the plane <-2-2i>, <2+2i> doset z=0+i0set n=0while (n<MAX) and (|z|<2) do

z=z2+cend of whileif (n==MAX) Draw Point(Black)

else Draw Point(Color(n))end of for

© Bedrich Benes

The Mandelbrot SetZooming into the Mandelbrot set

Page 3: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

The Mandelbrot SetZooming into the Mandelbrot set

© Bedrich Benes

The Mandelbrot SetZooming into the Mandelbrot set

© Bedrich Benes

The Mandelbrot SetZooming into the Mandelbrot set

© Bedrich Benes

The Mandelbrot SetZooming into the Mandelbrot set

Page 4: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

The Mandelbrot Set

http://www.youtube.com/watch?v=0jGaio87u3A

© Bedrich Benes

DimensionsDimension ‐ how long is the coast of Corsica?A stick of 500m will give 700km (not very precise)A stick of 100m will give 1200km (?)

What if we use length equal to  ?The length will be…

© Bedrich Benes

DimensionsHow long is the coast of Corsica?applied  sticks of length  timesthe total length is stick of the length  and we need  piecesif  we need 

© Bedrich Benes

Dimensions

In the case of Corsica we need to use formula

to get reasonable results…

What is this “D”? (Richardson)

Page 5: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

DimensionsHow long is the coast of Corsica?

Having  we get  

with  (i.e., getting the stick shorter) we get 

→© Bedrich Benes

Dimensions

For a line segment we need to set it the case of Corsica  needs to be non‐integer…

The D is so called Hausdorff dimensionSometimes called fractal dimensionFractals (usually) do not have dimensions 

© Bedrich Benes

FractalsFractalsfractal is a set that is self‐similar,

it is a set that is copy of itselfhere  is transformation scales downScale  must be average contraction 

Fractal is a set that has  Hausdorff’s dimension greater than its dimension topological

© Bedrich Benes

FractalsVaguely

Fractal is a set that is geometrically complex and its structure is given by repetition of a certain shape at different scales.

Page 6: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Fractals Classification

Linear Deterministic

Non-linear Non-deterministic

Fractals

© Bedrich Benes

Fractals Classification• Deterministic (or exact) fractals• Non‐deterministic or random fractalsDepends on the type of self‐similarity (exact, random)

• Linear – rotation, scale, translation, shear• Non‐linear – the othersDepends on the used transformations

© Bedrich Benes

DimensionsSpecial casesIf we use just ONE transformation with fixed  and  repetitionsthe fractal dimension is

© Bedrich Benes

Linear Deterministic FractalsThe Cantor’s discontinuum(published in 1883)

(Georg Cantor - 1845 - 1918)

1) Take a line segment2) Sale it 1/3x3) Make two copies at the ends4) Do it recursively

Page 7: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Linear Deterministic FractalsWhat is the dimension of the Cantor’s discontinuum? scale 

new piecesfor this we can use formula

this object is something between a point and a line

© Bedrich Benes

Linear Deterministic FractalsThe Koch’s snowflake

Scale  ,  , Properties: does not have derivativeinfinite lengthzero areathe area inside is non‐zero and non‐infinity

(Helge von Koch 1870 –1924)

1) Take a line segment2) Erase the mid third (similar to Cantor)3) Create equilateral triangle4) Repeat this recursively

© Bedrich Benes

Linear Deterministic FractalsThe Sierpinsky gasket 

not plane, not lineNote the similarity with Pascal triangle

1) Take a triangle2) Erase mid triangle3) Repeat this recursively

(Wacław Franciszek Sierpiński 1882-1969)

© Bedrich Benes

Linear Deterministic FractalsThe Menger sponge

Scale 

Dust of points.

1) Take a cube2) Erase mid cross of cubes3) Repeat this recursively

(Karl Menger 1902 - 1985)

Page 8: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Linear Deterministic FractalsThe Peano curve

space filling curve

1) Take a line segment 2) Substitute it by the lines from the image3) Repeat recursively on each line segment

(Guiseppe Peano 1858-1932)

© Bedrich Benes

Non‐Linear Deterministic FractalsQuaternionsif we apply the formula

in quaternion space(hypercomplex numbers ‐ 4D) 

© Bedrich Benes

Non‐Linear Deterministic Fractals

© Daniel White © Bedrich Benes

Linear Non‐Deterministic FractalsInvolve random numbers and linear transformationsMotivation:What would you hear if you increase the speed of playing music? Noise?The speed change is scaling

In other words:How large is this stone?10cm?1m?10m?

Page 9: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Linear Non‐Deterministic Fractals

© Bedrich Benes

Linear Non‐Deterministic FractalsThe way to model random features in natureis capturing the self‐similarity with stochastic processes

The key for these modelsare noise functionsNoise is (usually) self‐similar

© Bedrich Benes

Brownian MotionBrownian motion (Bm)Particles of pollen in water

They move because of random hits of molecules of water 

This is also special case of the random walk

Bm app

© Bedrich Benes

Brownian Motion1D Bm simulation:Random hits have Gaussian random number distribution

Page 10: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Brownian MotionHow to get Gaussian Random numbers?

the rand() function generates 

suppose we have  of such numbers the Gaussian random number  is:

© Bedrich Benes

N=1 N=2 N=3 N=4 N=5 N=10

Brownian Motiondetermines how steep the curve is

Gauss app

© Bedrich Benes

Brownian MotionWhite noise is a random function with a constant power density

Discrete samples are uncorrelated with  and 

Gaussian white noise is one of them

© Bedrich Benes

Brownian Motion1D Bm simulation (contd.):

Let’s have  that moves a point in the  directionit has Gaussian random numbers distribution 

Page 11: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Brownian Motionthe Bm (Brownian function)  is

we accumulate the perturbations

W(t)

X(t)The fractal dimension is D=1.5

Bm app

© Bedrich Benes

Fractional Brownian Motion (fBm)fBmif 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)

© Bedrich Benes

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 0H<0.5 autocorrelation is positiveH>0.5 autocorrelation is negative

© Bedrich Benes

Fractional Brownian Motion (fBm)

Page 12: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Linear Non‐Deterministic Fractals

• In order to generate nice fractals, we need fBm

• The above described function is good

• But it does not provide adaptive results 

© Bedrich Benes

The Midpoint Displacement Algorithm• the MDP is the key algorithm for fractals

1) Take a line segment2) Find its midpoint (center)3) Move it randomly in the direction4) Apply this step to all lines recursively

© Bedrich Benes

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

© Bedrich Benes

The Midpoint Displacement Algorithm• If we divide in each step by 

is the Hurst exponent

• we will get fBm with dimension 

Page 13: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

The Midpoint Displacement AlgorithmProperties• 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

© Bedrich Benes

The Midpoint Displacement AlgorithmTwo dimensional fBmworks with 2D arraysit is called fBm surfacedimension is 

,

where so the 

© Bedrich Benes

The Midpoint Displacement Algorithm2D fBm on quadrilaterals (diamond‐square)having four points P0,P1,P2,P3 1) Evaluate the midpoint2) Evaluate points on the edges3) Evaluate points in the middle4) Ad 2) etc...

© Bedrich Benes

The Midpoint Displacement Algorithm• 2D fBm on quadrilaterals (diamond‐square)

MDP app

Page 14: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Random FaultsAnother method for generating fBm1. take an object2. divide it into two parts3. increase the elevation of one and decrease the 

other one  (change color, etc.)4. apply this step many times5. in each decrease the intensity of changes 2x6. the limit of this process is fBm

© Bedrich Benes

Random Faults

Cuda random faults

© Bedrich Benes

Random FaultsImplementationData: 2D arrayAlgorithm: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

© Bedrich Benes

Random FaultsVariationsUse any 2D object (circle, square)Randomly alter the area inside/outside

Page 15: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Random Faults on a Sphere1) 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 

© Bedrich Benes

Random Faults on a Sphere

© Bedrich Benes

Perlin NoiseKen Perlin 1985, 2002Perlin, 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

© Bedrich Benes

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 casedouble noise(double x, double) //2D casedouble noise(double x, double, y, double z)//3D case

Page 16: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Perlin Noise• Limited frequency spectrum means we can chose 

the maximum desirable detail

• Returns value from 

• It is seeded by the input parameter

© Bedrich Benes

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

© Bedrich Benes

Perlin Noise ‐ Algorithm• Call:

• By calling with non‐integer coordinates  , ,• Find the corresponding cell  , , , ,• Calculate the vector from, , to each vertex• The influence of each vertex

is given by its distance• Sum the contributions by 

using sigmoid weighting function3 2• For large tables hash function is used

© Matt Zucker

© Matt Zucker

© Bedrich Benes

Perlin Noise

Page 17: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Summing Noise Functions

where

is called persistenceis called noise frequency

© Bedrich Benes

Summing Noise Functions• Maintains the overall shape• Add details and higher frequencies

© Bedrich Benes

Summing Noise Functionsoctaves=1 octaves=2

octaves=7octaves=3

© Bedrich Benes

Summing Noise Functions

© Paul Bourke

Page 18: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Turbulence• Start with a simple color ramp

© Bedrich Benes

Turbulence ‐ marble• Perturb it by Perlin noise

defines the influence (amplitude) of each octave

3  6  10 octaves 

© Bedrich Benes

Turbulence ‐ wood• Subtract the integer part of Perlin noise:

© Bedrich Benes

Hypertexture• Defines properties close to the object surface• It is a procedural definition, just perturbs the space• Can be displayed by raycasting

Page 19: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Hypertexture

© Ken Perlin © Bedrich Benes

libnoise

http://libnoise.sourceforge.net/index.html

© Bedrich Benes

Diffusion Limited Aggregation – DLA1) Particles (molecules) are floating in the water2) When a particle approaches 

an condensation centerit is aggregated

3) The process is repeated for many particles

The important part is the way the particles traveli.e., random walkCorals, lightings, frozen ice on a window, etc.

© Bedrich Benes

Diffusion Limited Aggregation – DLA

Page 20: CGT 581 –G Procedural Techniques Procedural Methods …hpcg.purdue.edu/bbenes/classes/CGT581-G/lectures/CGT581-G-06... · with Pascal triangle 1) Take a triangle 2) ... • just

© Bedrich Benes

Diffusion Limited Aggregation – DLA

© Bedrich Benes

Diffusion Limited Aggregation – DLA

Corals app