Download presentation
Presentation is loading. Please wait.
Published byRose Gray Modified over 9 years ago
1
CNM 190 Advanced Digital Animation Lec 08 : Procedural Modeling Basics Dan Garcia, EECS (co-instructor) Jeremy Huddleston, EECS (co-instructor) Jeff Ventrella, Jeff Ventrella, www.ventrella.com
2
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1902/31Procedural Modeling Basics Overview Dan on Procedural Modeling Basics Dan on Procedural Modeling Basics Great references Great references A note before starting A note before starting What IS it? What IS it? Why would you use it? Why would you use it? What are its varied flavors? What are its varied flavors? Control vs Chaos Control vs Chaos Randomness, Perlin Noise Randomness, Perlin Noise Fractals & L-systems Fractals & L-systems Genetic algorithms Genetic algorithms How do we do it? How do we do it? Conclusion Conclusion
3
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1903/31Procedural Modeling Basics Great references “Texturing & Modeling : A procedural approach” (2/e) “Texturing & Modeling : A procedural approach” (2/e) David S. Ebert, F. Kenton Musgrave, Darwyn Peachey Ken Perlin & Steven Worley David S. Ebert, F. Kenton Musgrave, Darwyn Peachey Ken Perlin & Steven Worley Morgan Kaufman, 1998 Morgan Kaufman, 1998 “The Computational Beauty of Nature” “The Computational Beauty of Nature” Gary William Flake Gary William Flake MIT Press, 2000 MIT Press, 2000
4
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1904/31Procedural Modeling Basics A note before starting This is a mixed group of programmers and non-programmers This is a mixed group of programmers and non-programmers I’m aiming this presentation at the non- programmers for whom much of this might be new, to bring us all up to the same level of discourse (roughly) I’m aiming this presentation at the non- programmers for whom much of this might be new, to bring us all up to the same level of discourse (roughly) I ask patience of the programmers, however, hopefully there is new information for all students I ask patience of the programmers, however, hopefully there is new information for all students
5
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1905/31Procedural Modeling Basics What IS it? “Procedural modeling is an umbrella term for a number of techniques in computer graphics to create 3D models (and textures) from sets of rules. L-Systems, fractals, and generative modeling are procedural modeling techniques since they apply algorithms for producing scenes. The set of rules may either be embedded into the algorithm, configurable by parameters, or the set of rules is separate from the evaluation engine.” “Although all modeling techniques on a computer require algorithms to manage & store data at some point…” “procedural modeling focuses on creating a model from a rule set, rather than editing the model by mouse.” “Procedural modeling is an umbrella term for a number of techniques in computer graphics to create 3D models (and textures) from sets of rules. L-Systems, fractals, and generative modeling are procedural modeling techniques since they apply algorithms for producing scenes. The set of rules may either be embedded into the algorithm, configurable by parameters, or the set of rules is separate from the evaluation engine.” “Although all modeling techniques on a computer require algorithms to manage & store data at some point…” “procedural modeling focuses on creating a model from a rule set, rather than editing the model by mouse.” en.wikipedia.org/wiki/Procedural_modeling
6
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1906/31Procedural Modeling Basics Why would you use it? “Procedural Modeling is applied when it would be too cumbersome (or impossible!) to create a model using general 3D modelers, or when more specialized tools are required. This is the case for plants & landscapes.” “Procedural Modeling is applied when it would be too cumbersome (or impossible!) to create a model using general 3D modelers, or when more specialized tools are required. This is the case for plants & landscapes.” Paul Martz, martz@frii.com en.wikipedia.org/wiki/Procedural_modeling garden of the metal
7
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1907/31Procedural Modeling Basics What are its varied flavors? Algorithm- or Data-driven geometry Algorithm- or Data-driven geometry …and animation (we’ll talk about later) …and animation (we’ll talk about later) Fractals Fractals Objects, landscapes, coastlines Objects, landscapes, coastlines Particle Systems Particle Systems Simulations Simulations Hair, fur, water, clouds, natural phenomena Hair, fur, water, clouds, natural phenomena Genetic Algorithms Genetic Algorithms More? More?
8
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1908/31Procedural Modeling Basics How much do you let randomness control your geometry? How much do you let randomness control your geometry? None at all means you’ll always get predictable results None at all means you’ll always get predictable results You can constrain randomness You can constrain randomness You can either randomize or set the initial seed, which can give repeatable randomness You can either randomize or set the initial seed, which can give repeatable randomness Or you can give in to chaos, setting initial conditions and letting it run Or you can give in to chaos, setting initial conditions and letting it run Sometimes deterministic rules generates chaotic sequence… emergent randomness! Sometimes deterministic rules generates chaotic sequence… emergent randomness! Control vs Chaos Life1D Rule 30 ControlChaos
9
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM1909/31Procedural Modeling Basics What is (pseudo) randomness? Almost every programming language has a built in random() and seed() Almost every programming language has a built in random() and seed() They usually return a uniformly-distributed floating point number [0,1). E.g., in Python : They usually return a uniformly-distributed floating point number [0,1). E.g., in Python : >>> from random import * >>> from random import * >>> random() >>> random() 0.72936670465656062 0.72936670465656062 That’s pretty good for almost every CG use That’s pretty good for almost every CG use For other applications (e.g., crypto), often use “natural randomness” from physical processes. For other applications (e.g., crypto), often use “natural randomness” from physical processes. See www.lavarnd.org See www.lavarnd.org 01 E(x) x en.wikipedia.org/wiki/Random_number_generator
10
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19010/31Procedural Modeling Basics What is the seed? The seed() allows for repeatability! The seed() allows for repeatability! >>> seed(0) # Arg => initialization >>> seed(0) # Arg => initialization >>> random() >>> random() 0.84442185152504812 0.84442185152504812 >>> random() >>> random() 0.75795440294030247 0.75795440294030247 >>> random() >>> random() 0.420571580830845 0.420571580830845 >>> seed(0) >>> seed(0) >>> random() >>> random() 0.84442185152504812 0.84442185152504812
11
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19011/31Procedural Modeling Basics What is the seed’s argument? Seeding allows for multiple repeatable paths! Seeding allows for multiple repeatable paths! >>> seed(0) >>> seed(0) >>> random() >>> random() 0.84442185152504812 0.84442185152504812 >>> seed(1) >>> seed(1) >>> random() >>> random() 0.13436424411240122 0.13436424411240122 >>> seed(0) >>> seed(0) >>> random() >>> random() 0.84442185152504812 0.84442185152504812 >>> seed(1) >>> seed(1) >>> random() >>> random() 0.13436424411240122 0.13436424411240122
12
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19012/31Procedural Modeling Basics How do we constrain it? Scale the random variables down so its effect isn’t felt much, and range changes Scale the random variables down so its effect isn’t felt much, and range changes >>> r = random() # [0, 1) >>> r = random() # [0, 1) >>> h = avg + 2*r*c - c # height >>> h = avg + 2*r*c - c # height What does the distribution of h look like? What does the distribution of h look like? If we want our noise to vary between -1 and 1, as we often do, how would we do that? If we want our noise to vary between -1 and 1, as we often do, how would we do that? E(x) x avgavg+cavg-c
13
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19013/17Procedural Modeling Basics Another way to use random What if we want a characters distribution to resemble demographics of Cal ugrads? What if we want a characters distribution to resemble demographics of Cal ugrads? osr2.berkeley.edu/Public/STUDENT.DATA/PUBLICATIONS/UG/ugsp06.html How can we use random() ? 54%46%
14
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19014/17Procedural Modeling Basics Simple, slice up [0,1)! Just use range = to that of distribution! Just use range = to that of distribution! >>> g = random() # [0, 1) gender >>> g = random() # [0, 1) gender >>> e = random() # [0, 1) ethnic >>> e = random() # [0, 1) ethnic And then use if … else from data! And then use if … else from data! >>> if g >> if g <.46: # 46% male... MakeCharacter(male)... MakeCharacter(male)... else:... else:... MakeCharacter(female)... MakeCharacter(female) …and similarly for ethnicity, height, etc …and similarly for ethnicity, height, etc
15
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19015/38Procedural Modeling Basics Perlin Noise Background Ken Perlin, NYU Prof Ken Perlin, NYU Prof In 1983 he “invented” the idea of CG noise In 1983 he “invented” the idea of CG noise In 1985 he wrote the seminal SIGGRAPH paper (top 10 most influential in CG!) In 1985 he wrote the seminal SIGGRAPH paper (top 10 most influential in CG!) In 1986 it started being adopted by all! In 1986 it started being adopted by all! In 1997 he received an Oscar for his work In 1997 he received an Oscar for his work mrl.nyu.edu/~perlin/doc/oscar.html
16
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19016/38Procedural Modeling Basics Perlin Noise Basics I Idea… start w/noise from random() Idea… start w/noise from random() Smoothly interpolate Smoothly interpolate …We have a continuous function of F(t), yay! …We have a continuous function of F(t), yay! freespace.virgin.net/hugo.elias/models/m_perlin.htm
17
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19017/38Procedural Modeling Basics Perlin Noise Basics II Amplitude and frequency Amplitude and frequency …which for a Noise wave …which for a Noise wave …is controllable via: AMP * F(FREQ * t) …is controllable via: AMP * F(FREQ * t) freespace.virgin.net/hugo.elias/models/m_perlin.htm
18
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19018/38Procedural Modeling Basics Perlin Noise Basics III Now, take combinations of these AMP and FREQ octaves and sum them together. Now, take combinations of these AMP and FREQ octaves and sum them together. Note that here we double the FREQ and halve the AMP, so the high frequencies affect the result much less than the low Note that here we double the FREQ and halve the AMP, so the high frequencies affect the result much less than the low freespace.virgin.net/hugo.elias/models/m_perlin.htm ++ ++ = Perlin noise fractal 1D mountain +
19
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19019/31Procedural Modeling Basics Perlin Noise Basics IV This also works in 2D This also works in 2D …and for 3D, and for 4D! …and for 3D, and for 4D! freespace.virgin.net/hugo.elias/models/m_perlin.htm Perlin noise fractal 2D mountain (or texture!) ++ ++ = + genesis
20
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19020/38Procedural Modeling Basics Perlin Noise Basics V How should you attenuate the AMP as you’re increasing FREQ ? How rocky will your mountain be? How should you attenuate the AMP as you’re increasing FREQ ? How rocky will your mountain be? Introduce Persistence Introduce Persistence Frequency = 2 i Frequency = 2 i Amplitude = persistence i Amplitude = persistence i freespace.virgin.net/hugo.elias/models/m_perlin.htm
21
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19021/38Procedural Modeling Basics freespace.virgin.net/hugo.elias/models/m_perlin.htm Perlin Noise Details How many octaves? How many octaves? Up to you, not more than you can see Up to you, not more than you can see How to interpolate? How to interpolate? Linear, cosine, cubic, many spline options Linear, cosine, cubic, many spline options Can smooth noise Can smooth noise Average with neighbors Average with neighbors Center random @ [-1, 1] Center random @ [-1, 1] You can turn noise up or down and it just “fuzzes out” to zero when the scale is small You can turn noise up or down and it just “fuzzes out” to zero when the scale is small
22
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19022/38Procedural Modeling Basics www.noisemachine.com/talk1/ Perlin Noise Final Thoughts Perlin summarizes history and context in an online talk (link shown above) Perlin summarizes history and context in an online talk (link shown above) “Making Noise”, 1999 “Making Noise”, 1999 He thinks of noise like salt He thinks of noise like salt Noise [salt] Noise [salt] is boring is boring F(blah) [food without salt] F(blah) [food without salt] can be boring can be boring F(noise, blah) F(noise, blah) can be really tasty can be really tasty We’ll see this again in CNM190 when we cover procedural textures (I.e., shaders) We’ll see this again in CNM190 when we cover procedural textures (I.e., shaders)
23
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19023/38Procedural Modeling Basics Fractal Geometry Overview A shape recursively constructed, or self- similar. How similar? A shape recursively constructed, or self- similar. How similar? Exact Exact Quasi Quasi Statistical Statistical Fractals are also found in nature, so can be used to model Fractals are also found in nature, so can be used to model Clouds, snow flakes, mountains, rivers Clouds, snow flakes, mountains, rivers Sierpinski pyramids
24
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19024/31Procedural Modeling Basics Fractal Geometry Simplicity The beauty of them is also how little code is required to author! The beauty of them is also how little code is required to author! Base case Base case Draw a straight line and choose an “up” Draw a straight line and choose an “up” Recursive case Recursive case Break every line in 2, bend them to make a right angle, and set the “left” line up and the “right” line down. Break every line in 2, bend them to make a right angle, and set the “left” line up and the “right” line down. Dragon curve en.wikipedia.org/wiki/Dragon_curve dragon, dan’s fractals, ucbugg 2d
25
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19025/31Procedural Modeling Basics Fractal Geometry in 3D It’s just as simple in 3D It’s just as simple in 3D Dan’s Menger cube: Dan’s Menger cube: Base case (n=0) Base case (n=0) Spit out cube Spit out cube Recursive case (n) Recursive case (n) Scale down the world by a third Scale down the world by a third –I.e., scale (1/3,1/3,1/3) Move to the rims of the cube, leaving middles empty (20 in total) Move to the rims of the cube, leaving middles empty (20 in total) –I.e., Translate (blah) Call yourself recursively with the n-1 case Call yourself recursively with the n-1 case siercube, ucbugg 3d en.wikipedia.org/wiki/Menger_sponge
26
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19026/38Procedural Modeling Basics Lindenmayer system (L-system) Formal grammar often used to model the growth of plant development Formal grammar often used to model the growth of plant development These can also be used to specify / generate fractals These can also be used to specify / generate fractals Simply put, it’s a series of rewriting rules that can succinctly describe fractal geometry using turtle graphics Simply put, it’s a series of rewriting rules that can succinctly describe fractal geometry using turtle graphics en.wikipedia.org/wiki/L-system Weeds
27
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19027/38Procedural Modeling Basics L-system example : C-Curve Angle 90 degrees Angle 90 degrees Initial string FX Initial string FX F means move forward, in Turtle graphics mode F means move forward, in Turtle graphics mode String rewriting rules String rewriting rules X X+YF+ X X+YF+ Y -FX-Y Y -FX-Y Example Example 1 : FX F 1 : FX F 2 : FX+YF+ F+F+ 2 : FX+YF+ F+F+ 3 : FX+YF++-Fx-YF+ F+F+F-F 3 : FX+YF++-Fx-YF+ F+F+F-F en.wikipedia.org/wiki/Dragon_curve Dragon curve
28
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19028/31Procedural Modeling Basics Particle systems Typically used to simulate fuzzy phonomena Typically used to simulate fuzzy phonomena Smoke, Explosions, Water, Sparks, Dust, Stars Smoke, Explosions, Water, Sparks, Dust, Stars Emitter controls particle generation, simulation Emitter controls particle generation, simulation What is involved with the geometry? What is involved with the geometry? Typically output as textured billboard quad Typically output as textured billboard quad Or, single pixel Or, single pixel Or, metaball (for gooey materials) Or, metaball (for gooey materials) YouTube: Cosmic Voyage (1080p) en.wikipedia.org/wiki/Particle_systems
29
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19029/31Procedural Modeling Basics Genetic Algorithms Karl Sims blew away his colleagues with his 1994 seminal work on evolved creatures Karl Sims blew away his colleagues with his 1994 seminal work on evolved creatures evolved virtual creatures web.genarts.com/karl/
30
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19030/31Procedural Modeling Basics Genetic Algorithms Genotype is the genetic information that codes the creation of an individual Genotype is the genetic information that codes the creation of an individual Phenotype is the individual Phenotype is the individual Selection is the process by which fitness of phenotypes is determined Selection is the process by which fitness of phenotypes is determined Reproduction is the process by which new genotypes are generated from existing ones Reproduction is the process by which new genotypes are generated from existing ones There must be probabilistic mutations with some frequency There must be probabilistic mutations with some frequency panspermia web.genarts.com/karl/papers/siggraph91.html
31
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19031/38Procedural Modeling Basics How do we do it in Renderman? Easy! Easy! Renderman supports a library that you can compile with your C program that will help you output RIB Renderman supports a library that you can compile with your C program that will help you output RIB RIB is the intermediate file that Renderman reads RIB is the intermediate file that Renderman reads The result of a render is a tiff file (or multiple tiffs) The result of a render is a tiff file (or multiple tiffs) renderman.pixar.com/products/whatsrenderman/ www.cs.berkeley.edu/~ddgarcia/renderman/
32
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19032/38Procedural Modeling Basics How do we do it in Maya? Easy! Easy! Every action you perform in Maya is available in the Script Editor Every action you perform in Maya is available in the Script Editor You can generate this text explicitly through a program using the techniques we just discussed. E.g., Name it Foo.mel You can generate this text explicitly through a program using the techniques we just discussed. E.g., Name it Foo.mel Or you can use MEL as a programming language (it looks like C) and do all your scripting there! Or you can use MEL as a programming language (it looks like C) and do all your scripting there! Open this in Maya (double-click, or use the Script Editor) Open this in Maya (double-click, or use the Script Editor)
33
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19033/38Procedural Modeling Basics I must program to randomize? Maya has randomness at many levels Maya has randomness at many levels Demo of Maya’s help, specifically “Random Number Functions” Demo of Maya’s help, specifically “Random Number Functions” It has most of the functions built-in! It has most of the functions built-in! seed() seed() rand() rand() gauss() gauss() noise() noise() gauss(5)
34
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19034/38Procedural Modeling Basics Set Dressing “The process of selecting, designing, adapting to, or modifying the performance space for a given purpose. This includes the use of stagecraft elements as well as the structure of the stage and its components.” en.wikipedia.org/wiki/Set_dressing
35
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19035/38Procedural Modeling Basics Set Dressing : Hand vs Procedural Which elements of the scene below were placed by hand and which were placed procedurally? Which elements of the scene below were placed by hand and which were placed procedurally? In general, when would you author code to place set elements? How much randomness would you allow? In general, when would you author code to place set elements? How much randomness would you allow? en.wikipedia.org/wiki/Set_dressing
36
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19036/38Procedural Modeling Basics Procedural Tree Set Dressing I Consider the problem of placing trees in a forest in a natural way Consider the problem of placing trees in a forest in a natural way How would you place them so that they don’t overlap? How would you place them so that they don’t overlap? What are some ideas? What are some ideas?
37
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19037/38Procedural Modeling Basics Procedural Tree Set Dressing II Random Trees Random Trees Pick random points and remove if new tree is too close to existing tree Pick random points and remove if new tree is too close to existing tree Start with trees regularly spaced and then perturb (wiggle) Start with trees regularly spaced and then perturb (wiggle) Add “relax” step which treats each point as having “negative gravity” to push away nearby points Add “relax” step which treats each point as having “negative gravity” to push away nearby points Find out what “right” answer is (check forestry research) or by looking at real forests and simulate Find out what “right” answer is (check forestry research) or by looking at real forests and simulate Voronoi diagram of random points
38
http://inst.eecs.berkeley.edu/~selfpace/ C10 Hearst Field Annex; 642-9920 CNM19038/38Procedural Modeling Basics Conclusion There’s a wonderful world of procedural geometry waiting for you to discover! There’s a wonderful world of procedural geometry waiting for you to discover! Let the mathematician in you run wild! Let the mathematician in you run wild! Take a look at some of the wonderful sculptures by Prof Séquin on the 6th floor for inspiration Take a look at some of the wonderful sculptures by Prof Séquin on the 6th floor for inspiration
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.