Procedural Texturing and Modeling Advanced Animation and Motion Capture (AA&MC) Topics covered: Fractals & Noise a. Random b. Pseudo-random c. Perlin Noise d. Iterated functions e. Spiral Phyllotaxis Grammars a. Recursion b. L-Systems 2D and 3D Textures a. Surface textures b. Cellular textures c. 3D Textures d. Hypertextures Procedural Modeling a. Instancing b. Replication c. Placement Noise What is randomness? Randomness: Some definitions… “Having no definite aim or purpose; not sent or guided in a particular direction..” Oxford English Directionary “Free will is limited to low-level decision making.” Martin Luther “God does not play dice with the universe.” Albert Einstein “Don’t tell God what to do.” Neils Bohr “[God] gave humans free will. He gave them free will because a world of mere automata could never love..” C.S. Lewis Randomness in the universe implies free will. Michael Noll, 1962. Computer Composition with Lines Based on Piet Mondrian’s Composition with Lines Bela Julesz, Hungarian psychologist Random-dot stereograms. 3D object hidden in random images. Is it random? What makes it random? How do we get true randomnesss? Which of these are random? a. Throwing dice b. Roulette wheel c. Temparature of a specific point in nature d. The next number I say e. Digits of PI Roulette wheel The Eudaemonic Pie, 1985. Thomas A. Bass. Describe a group of physics graduates from University of Santa Cruz who knew that roulette wheels obey Newtonian physics, but is just very sensitive to initial conditions. Using miniaturized computers, hidden in special shoes, they could capture the state of the ball and the wheel, and could increase their odds by 44%. Hardware Random Number Genarators Best sources of physical randomness so far: - Nuclear decay of atoms. - Photos traveling through a partial mirror SSL Accelerator card Applications to cryptography. Many security systems are based on a random key. If the key is not really random, system is not safe. How do computers generate random numbers? ? Tn Tn+1 Numbers are generated as a sequence, starting from some seed point. Problem is finding the next number so that it has nothing to do with the last. Why is this hard? Because computers are deterministic. The computer program to get Tn+1 is an exact sequence of steps. So if you figure out what is Tn, my program will give you Tn+1. Computer has no free will to choose a different number. Plot of the rand() function in C. int r = rand(); When your computer really needs something random, how does it do it? srand ( time() ); // check the second hand on the clock int r = rand(); // get random number This says the seed of the random number generator is based on the when you tell the program to run. All numbers after that will look random. If you start the program over, a different clock time is used for the sequence. These are called pseudo-random sequences. Randomness in Computer Graphics We actually like pseudo-random sequences in graphics. Why? 1. Results can be reproduced, while still appearing random. Useful for testing. 2. Randomness that depends on time will not jump around from one frame to the next. e.g. Random placement of trees in a game. 3. Faster to compute Computer Graphics Patterns in nature are semi-random. Wood chips. Natural and Man-Made Patterns often have a grain. Wood – due to process of growth Metal – due to process of cleaning Sheet metal Random noise Scaled on one axis Fractals Nature often exhibits pattens of a fractal structure. - Exhibit scale invariance. Same structure at different scales. - Exhibit self-similarity. - Exhibit Fractal dimensionality. “Clouds are not spheres, mountains are not cones, coastlines are not circles, and bark is not smooth..” Benoit Mandelbrot, French-American (b. 1924) The Fractal Geometry of Nature, 1982 Perlin Noise Fractal noise. Simple idea: Generate random noise at different scales (frequencies) and add them together. Ken Perlin, New York University. Invented in 1982. Academy award for Tron. Chaos The property of a non-linear system to be stable at times, but occasionally enter into a chaotic, seemingly-random state. Exhibited by many physical systems: Simple Example – Logistic Map Based on the logistic map, developed to study population dynamics. x n+1 = r xn ( 1 – x n) Creates a number sequence. Where: 0 < Xn < 1 Ratio of existing populaton to maximum possible population. % population r Combined rate for reproduction and starvation. So we have two competing factors: r Xn Says that population will increase based on the previous population. r (1-Xn) Says that population will decrease based due to starvation based on how close we are to maximum. Biologist Robert May, 1976. Mathematics first from Pierre Francois Verhulst (1804) Bifurcation Diagram Iterated Functions All these systems share a common feature: How to Generate a sequence Tn+1 from Tn. - Noise Generator is pseudo-random sequence - Roulette Generator is the law of Newtonian physics - Chaos Generator is a non-linear system /w feedback - Logistic Map Generator is competition between population factors Iterative functions describe many basic processes in nature. The previous state of the system determines the next state. See the chaos game, Michael Barnsley. Method of making geometric fractals. Spiral Phyllotaxis Many patterns in nature can be understood with very simple iterated functions. Two leaves appear on opposite sides. A third appears between them. The first two push the 3rd away. The result is the golden angle. Iteration, adding new leaves, settles into the minimization of energy, which results in the golden ratio (angle). Wilhelm Hofmeister, 1868. Fermat’s Spiral Phyllotaxis pattern found in sunflowers. o A Collision-based Model of Spiral Phyllotaxis, 1992 Deborah Fowler, Przemyslaw Prusinkiewicz, Johannes Battjes “The Algorithmic Beauty of Plants” Przemyslaw Prusinkiewicz Entire book available online: http://algorithmicbotany.org/papers/#abop Procedural Textures – 2D and 3D f ( x, y ) = image f ( x, y, z) = volume Deals specifically with generated images and volumes and their application to graphics. Procedural Textures – 2D and 3D f ( x, y ) defines an image, or surface texture. Image f ( x, y ) Object Polygon World space Texture space Texture mapping. Two-dimensional function is mapped onto the three dimensional geometry. Process is usually done with inverse sampling, where you look up the desired value in f. Texture mapping Texture appears on surface, and follows surface distortions of the object. Volumetric Textures f ( x, y, z ) defines a volume texture Volume f ( x, y, z ) Object Polygon World space f ( x, y, z) Volume Texture space Texture is defined at every point in space. Texture color is selected directly from the 3D volume location. Wood and marble are naturally described as volumetric textures. Modeling and Rendering of Weathered Stone Julie Dorsey, Alan Edelman, Henrik Jensen, Justin Legakis, Hans Pedersen Combine Perlin noise with other simluated physical processes, such as rain or rust, and layer them together. Texture mapping: - Faster to compute - Less memory to store (only if you need to save) - Texture appears on the surface of object - Texture distorts with changes in the object. Volume textures: - Slower to compute - More memory to store (only if you need to save) - Texture remains rigid relative to object. - Object changes in shape will move through the texture. - Good for rigid objects with cracks or breaks. Cellular Textures There are other ways to generate the texture function f ( x, y ) aside from using random noise. Generate a set of polygons in the plane (2D). Compute the distance to the nearest edge. Crocodile skin Procedural Texturing – Types of mappings Texture mapping assigns a function f to the color of a point on an object. Different features of an object can be modified by procedural textures. Procedural Texturing – Types of mappings Bump mapping modifies the surface normal based on the function f. The surface normal determines the visible orientation of the surface for lighting calculations. Notice the silouette does not look bumpy. The geometry is not changed, only the surface direction relative to the light source. Procedural Texturing – Types of mappings Environment mapping modifies the reflected ray color based on function f. Useful for reflective surfaces. Notice that the geometry of the surface is still not changed. The sphere is still smooth. Procedural Texturing – Types of mappings Displacement mapping modifies the actual surface position based on function f. Most realistic for any rough surface. Notice silouette is also bumpy. Can be expensive to compute. May need to increase the geometric detail of the object in order to give a good appearance. Grammars and L-Systems How can we change the structure of something? With procedural textures there is essentially one object, the function or system, which can change over time. Differences are between points in space or sequences in time. What if we want to modify the object itself, change its change or add new shapes? Example: L-Systems Process of replacement can be formalized using a grammar, or parallel rewriting system, called an L-system. An L-system is a tuple (set of three things): G = ( V, w, P ) V = Alphabet. Set of symbols that can be replaced. w = Start or axiom. P = Set of production rules. Aristid Lindenmayer, 1968. Hungarian biologist and botanist. Variables: A B Start: A Rules: A -> B B -> AB Process: 1. Take the Start (w) as the current string 2. Apply the production rule to every symbol in the current string. 3. When finished, call this the new string. 4. Repeat start: iteration 1: iteration 2: iteration 3: iteration 4: A B AB BAB ABBAB (rule A->B) (rule B->AB) (rules A->B, B->AB) (rules B->AB, A->B, B->AB) L-Systems can have a physical interpretation, if we assign meaning to letters. L-System Plants L-system Weeds Procedural Cities L-systems can be used to describe many objects where the structure changes iteratively, such as city blocks. http://www.youtube.com/watch?v=yI5YOFR1Wus Procedural Buildings Generative Modeling Language (GML) “A Generative Theory of Shape”, Michael Leyton. (availabe online) Procedural Furniture Parametric modeling allow you to change the size and shape of various parts of an object continuously. Instancing and Replication or.. How to make a complete forest. (First try) Noise L-system Structure of branches Noise can tell us where to plant trees. L-system can tell us how to build a three-dimensional tree. But do we make one tree and copy it, or do we make lots of different trees? Some times instancing can look pretty good. Pines trees all look similar. In other cases, instancing does not produce enough visual variation. This also depends on the placement algorithm. 1 instance 2 instances 1 instance 8 instances 1 Procedural Modeling - Efficiency Procedural modeling can produce a lot of geometry. Steps must be taken to reduce the number of polygons. 1. Level of detail – Only create new geometry where it is needed 2 2. Instancing – Copy geometry already in memory instead of rebuilding 3. Imposters – Use a picture for distant objects instead of rendering the whole thing. http://www.youtube.com/watch?v=rl5p63JabrA 3