4/20/2016 PA 199 Advanced Game Design Lecture 9 Procedural Forest and Cities Dr. Fotis Liarokapis 20th April 2016 Plants and Vegetation Variation Modeling Forests Plantsand • Model a forest scene -Procedural modeling -Grammars and L-Systems 4/20/2016 Procedural Modeling Use procedure to generate all needed geometric primitives Store complex tasks in procedure — Detail level — Shaders — Internal animation Procedural Trees • Trees are a classic example of complex natural objects that can be procedurally modeled • There have been numerous research papers published on various aspects of botanical modeling — One recent paper focused on creating the detailed sub-millimeter scale vein patterns seen on leaf surfaces Procedural Trees V By varying a number of key parameters, one can model a wide variety of plants and trees to any level of detail desired Even with about 10 parameters, can model a wide variety of overall plant shapes: — However real plant modeling systems may allow hundreds of parameters as well as the inclusion of custom geometric data to define leaf shapes or branch cross sections SimilarTree Forms Selected aspects of tree form A) Tree silhouette and growth habits B) Branch curving: hyponasty and epinasty C) Tropisms: no tropism, negative gravitropism, plagiotropism, positive gravitropism D) Branch flow: curved, angular E) Gravimorphism: epitony, amphitony, basitony Plant Morphology An important part of a plants morphology is the bud — A bud is where every part of a plants body starts growing There are two different types of buds -The apical bud at the end of a branch -The lateral buds • Can grow new branches, leafs or flowers 4/20/2016 Plant Morphology. The starting point for leaves (or sub-branches) at a branch is called Nodus — The part between two nodes is the Internodium A node can grow one or more leaves — The angular distance between all leaves grown at one Node will be constant Plant Morphology.. • Three basic types: - (a) One leaf per node, leafs of consecutive nodes are rotated by 180 degrees - (b) One leaf per node, but consecutive leafs are rotated by the mean building up a spiral shape - (c) Several leaves per node, leaves alternate M (b) (c) (a) (b) (c) Primary Shoot Growth • All plants grow according to the same basic pattern — Although there is a huge amount of variation within that pattern • Growth takes place at tips of stems — Where new leaves are formed Primary Shoot Growth Primary growth includes: — Development of these new leaves at relatively regular intervals — Elongation of the stem between the nodes 3 Axillary Growth At each leaf node an axillary bud is formed - Which may remain dormant - Or may develop into a whole new stem 4/20/2016 Flowers Flowers will form at the tips of younger stems at certain times of the year, triggered by seasonal properties - i.e. day length or temperature Flower petals and other floral components are modified leaves themselves Plant Shapes The variety of plant shapes is mainly due to variations in stem shapes, branching properties, and leaf shapes, and these can be broken down into specific properties that can be used to control a procedural plant model A simple way to model a plant is to start by thinking of it as a bunch of branches (stems) and leaves Branches V Think of a branch as being a circular extrusion along some path - But it would certainly be possible to use non-circular cross sections as well The radius of the cross section will either remain constant or may taper from being thicker at the base and thinner at the tip — Simplify by specifying a radius at each end and assume a linear interpolation along the branch Branches The path of the branch can just be a set of points These points could be a straight line - Not be hard to add some curvature and randomness The path could be randomly created just from - A starting point, an initial direction, and a desired length Branching Each branch can spawn off new branches The new branches would be placed at points along the original branch with some rule to define their initial direction - For example, it is nice to allow new branches to start at some percentage along the original branch Branching The length of the new branches can be defined by two percentages: — One describes the length of new branches at the base of the original branch — One describes the length at the tip The branching angle can be described similarly by values at the base and tip 4 4/20/2016 Branching and Leaves The branching is usually repeated two or three times so that we get sub-branches on sub-branches on branches At that point, we branch one final time — But create leaves instead of new branches The leaves can be placed along the branch according to similar rules as sub-branches Shapes of Leaves Details in the Leaf Shapes (a) (b) (c) (d) (a)2D leaf without any details, (b) leaf with jagged edges (teeth), (c) leaf with very sharp tip (drip-tip), and (d) leaf warped in 3D space Types of Leaves (a) (b) (a) Narrow leaves found in bryophytes, pteridophytes, and gymnosperms are slender (b) Broad leaves found in angiosperms are wide and their thickness is negligible compared to the surface area 5 4/20/2016 (a) (b) (c) (a) Straight: the margin is straight (b) Concave: the margin curves towards the primary vein, (c) Convex: the margin curves away from the primary vein, (d) Concavo-convex: the margin is concave proximallyand convex distally. (e) Complex: the margin has more then one point of inflection, (f) Cordate: the margin extends below the base Types of Apex Shapes (c) (d) (a) Straight: the margin is straight (b) Convex: the margin curves away from the primary vein (c) Acuminate: the margin is concave proximallyand convex distally or concave only (d) Emarginate: the margin extends above the apex TpeTof leaves based on the position^ and Max width of the lamina (a) Elliptic (b) Obovate (c) Ovate (d) Oblong (e) Linear Common Leave Shapes IHM elliptic Lanceolate Oblanccolate Oblong Oval 0 4 I * Obovate Ovale Rhomboidal Orbicular Deltoid Cordate Reniform Obcordale Types of Laminar Asymmetries Plant Example with asymmetric cordate base (c) A simple leaf with cordate base on one side and no extension on the other 6 4/20/2016 Fractal Trees and Plants Fractal trees and plants are among the easiest of fractal objects to understand — They are based on the idea of self-similarity V W Fractal Tree Pseudo-Code DrawTree(n, direction, length) if n > 0 do DrawTrunk(direction, length) DrawTree(n-l, 3DRandomAngle(direction), length*Factor(n)) DrawTree(n-l, direction + random % 10, length*Factor(n)) DrawTree(n-l, 3DRandomAngle(direction), length*Factor(n)) else DrawLeaf() end if end DrawTree Branch Strings Fractal Trees and Plants The main idea in creating fractal trees or plants is to have a base object and to then create smaller, similar objects protruding from that initial object — The angle, length and other features of these children can be randomized for a more realistic look — This method is a recursive method Fractal Branching Structures Trees and Plants Example 4/20/2016 Grammars and L-Systems How can we change the structure of something? — With textures can fake it To modify the object itself, change its change or add new shapes then need to use L-Systems Introduction to L-Systems • Developed by A. Lindenmayer to model the development of plants — Originally described cellular growth • Based on parallel string-rewriting rules — Formal set of rules and symbols — Rules applied iteratively to start sequence • Excellent for modeling organic objects and fractals L-Systems Definition The process of replacement can be formalized using a grammar, or parallel rewriting system is called an L-system L-Systems Structure • An L-System is a 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 L-Systems Structure L-Systems Physical Interpretation Variables: A B Start: A Rules: A->6 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: 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 The dragon curve drawn using an L-system 8 4/20/2016 Avan-l of Ihr Ksdl cuvr mrtinn usrsontf rgni-nngra ■ 4bb. ri^uu -Jm iupmr. * ineara; turn sft 30" svj - rrwsra: turn nnrt9fl,L 0K turtle gzpliics] n 0 its I: _n_ F4f.F-F»F MF-F-F*F*F*F-F*+F**F*-F*f*+F*.F*F+F+F-F.F»F FtF-F-F+F+F+F-F-F-t-F-F-t-F-F-F+F-F-t-F-F-FtF-rFtF-F-F"F-t F+F-F-F-tFtF-tF-F-FtF-FtF-F-F*F-FtF-F-FiFtF+F-F-F-tF- F-tF-F-F-fFiF-tFrFrF-tFT F'F-F-F'FF'FF-F-F'F'F-F F'F Ftp F-FtF'F' F F-F -FF'FFF *F-F *F F F'F'FtF F-F'Ft F*F-F-F •f'F'F-F-F'-F-Fi-F-f ■F'F-F'F-F' F*F*F»F-F-F*F rules : (X F-|[X)+X)+F[+FX|-X), (F -* FF) angle : 25° Here, F means "draw forward", - means "turn left 25°", and + means "turn right 25™ X does not correspond to any drawing action and is used to control the evolution of the curve. [ corresponds to saving the current values for position and angle, which are restored when the corresponding ] is executed. L-Systems Plans & Trees Examples L-System for Plants • L-Systems can capture a large array of plant species • Designing rules for a specific species can be challenging A Simple L-System Example • F [ & + F] F[ - > F] [- > F] [& F] Parametric Leaf Model • Coordinate system of the leaf model • Leaf without basal extension • Leaf with basal extension 9 4/20/2016 Coordinate system of the leaf model The parameters of the leaf model are expressed as: - A right-handed coordinate system with origin at the base - The y-axis pointing towards the apex of the leaf - The primary vein is defined to have a unit length Leaf without Basal Extension Pi =(0,0), Pa = (i2,tt0, Pa = (0,1), ti = (sin#&, cosÖ&j, ta = (0,1), ta = { — sinft,,cosft,). Leaf with Basal Extension Pi = (0,0), Ps = [xi,yi), P3 = 1.^3,Vi), P4 = (0,1), t! = (sin0t,cos#f), t2= (1,0), t2= (0,1), ts = (— sin fja, cos f)a Stochastic L-Systems Specify more than one production rule for a symbol, giving each a probability of occurring When a stochastic grammar is used in an evolutionary context, it is advisable to incorporate a random seed into the genotype — So that the stochastic properties of the image remain constant between generations Other L-Systems A number of elaborations on this basic L-system technique have been developed which can be used in conjunction with each other Among these are: — Stochastic — Context sensitive — Parametric grammars Stochastic L-Systems Several rules for each symbol Rules chosen based on probability Create different plants using same L-System Simulate environmental effects e. umbc.edu/--ebert/693/TLin/node 18. html 10 4/20/2016 Context Sensitive L-Systems • A context sensitive production rule looks not only at the symbol it is modifying, but the symbols on the string appearing before and after it • For instance, the production rule: -bc->aa transforms "a" to "aa" • Only If the "a" occurs between a "b" and a "c" in the input string: ...bac... Parametric Grammars L-Systems • Each symbol in the alphabet has a parameter list associated with it • A symbol coupled with its parameter list is called a module, and a string in a parametric grammar is a series of modules • An example string might be: -a(0,l)[b(0,0)]a(l,2) Context Sensitive L-Systems. Parametric Grammars L-Systems. • Parametric grammars allow line lengths and branching angles to be determined by the grammar — Rather than the turtle interpretation methods 11 4/20/2016 Randomness Definitions What is Random? • "Having no definite aim or purpose; not sent or guided in a particular direction.." — Oxford English Dictionary • "Free will is limited to low-level decision making." — Martin Luther • "God does not play dice with the universe." — Albert Einstein 48086S1S282306647093844609SS0S8283178S3S9408128481117 45028410270193852110S5596446229489S493038196442881097 56659334461284756482337867831652712019091456485669234 60348610454326648813393607260849141273784887006606313 58817488152092096282925409171536436789259036001133053 08488204668213841469819418116094330872703637698919830 92186117381932611793108118848074462379962749367351883 78272489122793818301194912983367336244088664308602139 49463952247371907021798609437027705392171762931767523 8467481846766940813200086812714S263S6082778S771342787 7896091736371787814684409012249S3430146S4988S3710S079 22796892389238420199861121290219608640344181898136297 74771309960318707211349999998372978049931089731732816 096318S9S02445945S34690830264252230825334468S0352619 31188171010003137838782886887833208381420617177669147 3038988854904287B64687311698688638823837878937819577 Computer Random Numbers Plot of the randQ Function • 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 .- • v ? : Randomness in CG Mountain Forest Example Typical example is Fractals "Clouds are not spheres, mountains are not cones, coastlines are not circles, and bark is not smooth.." Benoit Mandelbrot, (b. 1924) The Fractal Geometry of Nature, 1982 12 4/20/2016 Spiral Phyllotaxis Fermat's Spiral Many patterns in nature can be understood with very simple iterated functions 4 A Two leaves appear on opposite sides. A third appears between them. The first two push the 3[d away. The result is the golden angle. Iteration, adding new leaves, settles into the minimization of energy, which results in the golden ratio (angle) Phyllotaxis Pattern - Sunflowers Given a sequence of integers n: r = c yfn 9 = n • 137.50 (golden angle) r = distance from center 6 = angle •••••• 000• oo„° • °oO ogo0£o o oVoVooO o°0o °o°o°o0o0oo°o Phyllotaxis Examples A Collision-based Model of Spiral Phyllotaxis, 1992 Deborah Fowler, Przemyslaw Prusinkiewicz, Johannes Battjes Plant Ecosystems Plant Ecosystems Very common is the use of a pipeline system to create ecosystems, consisting of a number of succeeding steps such as: — Terrain Specification — Distribution Specification/Simulation — Plant Specification Depending on the application there are two steps in generating a virtual ecosystem (can be used alone or in conjunction): — Generating/specifying plant distributions — Simulating plant distributions 13 4/20/2016 Forest Example 1 Forest Example 2 Sometimes instancing can look pretty good. Pines trees all look similar Terrain and Forest Example City Modeling Introduction to City Modeling GIS and City Modeling Modeling 3D environments expensive Use CGA shape to create large detailed urban environments 14 4/20/2016 SkylineEngine Research oriented project \ Aims at the development of a | procedural urban modeling engine :i in PI http://eee.ude.edu/skvlineEneine/ Pixel City Written in C++ using OpenGL No fragment or vertex shaders are used http://code.eooele.eom/p/pixelcitv/ Pixel City Example V CityScape By PixelActive Features: - Enhanced road editing capabilities, improved GIS importing, a flexible meta data system, new import and export formats, a redesigned user interface with icons and hotkeys, and performance improvements The road editing tools add a tangent editor, tunnels, and complex intersections CityScape Example CityEngine Uses maps of population density to create a road network using Open L-systems - Spaces between blocks subdivided into lots for individual buildings Buildings generated using parametric stochastic L-systems, detail m/software/citveneine 15 4/20/2016 City Engine Example Environmentally Sensitive L-Systems So far, L-systems have been more or less self-contained Parameters provide global influences from the environment — Provide a way to have the environment affect the development of the system locally "ivironmentally Sensitive L-Systems ^ Examples Examples from Synthetic Topiary, by P. Prusinkiewicz, M. James & R. Mech Open L-systems Generalisation of environmentally sensitive L-systems When interpreted, control is passed to an external function representing some part of the environment Environment performs calculations, optionally passes back modified parameter values to be used in the next derivation step Two-way communication between system and environment Procedural Road Modeling Roads can be modeled as cross sections that get path extruded along some curve The cross section can include: — Lanes, curbs, sidewalks, center islands Intersections require special handling — Can still be generated using a set of procedural techniques Procedural Road Modeling Roads can be placed on height fields by placing the control points of the road curves on the height field — Note that this will require some local flattening for the road and the area to the side of the road Render road triangles onto the height field — Where a low detail road is extruded and 'rendered' into the cells of the height field to set their heights 16 4/20/2016 Procedural Road Modeling.. • Sides of roads can be blended — Using techniques similar to alpha blending • Note that the above operations will modify the existing shape the height field — Similarly to how real roads are constructed Procedural Road Modeling... • Ideally, the road surface would be an extrusion and the open terrain would be a height field • They can be sewn together into a single triangle mesh — Similarly to how trim curves are used in r~ patch tessellation /O Road Modeling Example __ ™s"^TjtyEngine - Road Generation Algorithm • Uses Open L-systems for road generation • Environment functions are the constraints imposed on the roads • Two types of roads: highways and streets — Highways connect areas of high population density — Streets connect the rest of the populace to the nearest highway Example of Production Rules for Roads pi: p2: p4: p5: p6: p7: *(0, initRuleAttr)?I(initRoadAttr, UWASSIGWED) R(del, ruleAttr): del < 0 ^ e R(del, ruleAttr) > ?I(roadAttr, state): state == SUCCEED -> + (roadAttr. angle) F (roadAttr. length) B (dell, ruleAttrl, roadAttrl) B (del2, ruleAttr2, roadAttr2) R(del0, ruleAttrO)?I(roadAttrO,UWASSIGWED) R(del, ruleAttr) > ?I(roadAttr, state): state == FAILED -* e B (del, ruleAttr, ^ B(del - 1, B (del, ruleAttr, B (del, R(del, roadAttr): del > 0 ruleAttr, roadAttr) roadAttr): del == 0 ;R(del, ruleAttr)?I(roadAttr, UWASSIGWED)] ruleAttr, roadAttr) : del < 0 -> e ruleAttr) < ?I(roadAttr, state): del < 0 p8: ?I(roadAttr, state): state ^ ?I(roadAttr, state) p9: ?I(roadAttr, state): state UWASSIGWED = UWASSIGWED CityEngine Parcel Generation 17 4/20/2016 Population Density Highways connect peaks on population density map End of segment shoots rays across map — Each ray is sampled and sample points look up population value Highway generation continues in the direction of the fittest ray Street Patterns • New York style — Streets form blocks by restricting the length of a block and the angles that streets follow • Paris style — Concentric rings around a central point, connected by short radial streets •San Francisco style — Tries to reduce the length of non-contour streets and uses gradient of elevation map Other Constraints Modify attributes (length, angle) of road segments in response to surroundings Make sure roads do not cross water and any other places you'd expect not to find them Creates intersections with other roads Road Intersections • No more dead ends than intersections • No intersecting segments without creating an intersection (node in the road graph) • Three rules: — 2 streets cross: generate an intersection — Segment ends close to intersection: join it to the intersection — Segment ends close to another segment: extend it and create an intersection Buildings Modeling Once the roadmap has been generated - Allotments can be generated - Geometry can be generated - Buildings can be assigned textures • Preferably procedural City Block Divisions City divided into blocks Blocks subdivided into allotments — Blocks assumed to be convex and rectangular • Concave allotments forbidden 18 4/20/2016 City Block Divisions. • Simple recursive algorithm - Divide longest edges that are approximately parallel -Stop when size less than threshold value • Allotments without street access or too small discarded • Maximum building height from image map Building Geometry • Parametric, stochastic L-System • One building per allotment • Each building style has own set of production rules • Manipulate arbitrary ground plan Mill Building Geometry. L-System modules: — Transformation modules — Extrusion module -Branching and Terminating modules -Geometric templates Final shape is ground plan transformed by L-System Building functionality not represented Ik Mass Models Generation 5 Crude volumetric building model Composed of shape primitives Shapes Generation Used by the grammar Consists of: -Symbol (string) — Geometric attributes • Position • Coordinate System • Size - Numeric attributes Y Production Process Configuration: Finite set of basic shapes Start configuration of shapes - Process: • Select active shape with symbol B • Choose a rule to compute a successor for B • Mark B as inactive, add the shapes BNEW to configuration and repeat Stop when there are no more non-terminals Assign a picking priority based on detail 19 4/20/2016 Scope Rules General shape modifying rules — Translate, Rotate, Scale I: A «-t [ T(0,0,6) S(8,10,18) I("cube") ] T(6.0,0) S(7,13,18) IC'cube") T(0,0,I6) S(8,I5,8) [("cylinder") Basic Split Rule Split current scope along one axis — For example: I: t'uc -J Suhdivf V"..1.5.0.3,3,3.3){ Hour | ktlje | flow | daw | Hour } V 1 0 a 0 m 0 0 0 0 0 0 0 m 0 n ) floor 3.0m ) floor 5.0m 1 floor 3.0m j ledge 30cm ! floor 3.5m Scaling V Repeat Relative values can be used I floor — SuMiv(-X",2,1 r. 1 r.2){ B | A | A | B f S(12, 3) floor -•- 3 [|B| A I A |B 2 4 4 2 S(10,3) floor 3 [JBJAJAJBJ 2 3 3 2 Tile a specified element - Example: • Tile as many B elements as possible along X axis • Number of elements = \^-'engthi2\ I: floors- Repeat("X",2){ B } Component Split Split into shapes of lesser dimensions type = type to split param = associated parameters (if any) {A| ...} = symbol of shape after split 1: Compdype, param){ A | B | ... | Z } Mass Modeling Union of volumetric shapes — Box, Cylinder, etc 20 4/20/2016 Roofs Facades Add roof shapes Categorize different types of roofs — i.e. according to building style or height Extract 2D facades from 3D shapes Result - Aligned 2D scope Grammar refines resulting quads and triangles Occlusion v Snapping Test for intersections between shapes None, partial, or full Avoid placing facade elements on intersections I: tile : Shape.occ("noparent") == "none" window 2: tile : Sh;ipe.occ("nop;irent") == "part" wall 3: tile : Sh;ipe.occ('"iioparent") == "full"~* £ Additional control of facade layout Used by repeat and subdivide Repeat ; Subdiv default: snapped: 21 4/20/2016 Layered Textures Two base functions form a layer Every layer defines a facade element Layering of Planes Stacked layers for facade texture Functions between layers model relation between facade elements J -tr Case Studies for City Modeling New Classic Buildings of Athens New Classic Buildings Roman Settlements Ionic Temples Demonstrate how some of the neoclassical buildings in Athens used to be around 100 years ago - Based on procedural modeling techniques used for the generation of these characteristic buildings L-System Road Structures IB| Sub-division of the niac \C: rj-rf rl Wnc, bc^rf The Tanstar-nat Tin ohne edge, straight lines after fl (D) Final roadgrid uilding Topologies and Pavement Generation v -'IJL--I 1 □□□Dosuoagi. IBpn nnrn GsajajDaoggi jaQDaaJSytiaüsö nüooaanaizigDrjc IC) City byautwitli blacks lefAblacksub-divided inlobuildingtopaloKies ■■;".-.■■-i,i.d_i--. r.i 2JstfEfj.Ts:>-|"-ii;,=,hr|,i ■: <" . = , 'tsl^-.:. ±1BHifSSE3!läacaSir.i|f (DJ City layautwltti blocks sub-divided nto building tcpologici 22 4/20/2016 Building Generation Generation of Building Roofs Buildings were done using boxes — Extruding based on the topologies Fixed height -Multiple floors — Variable number of windows Type 3: Flat with ceramics Balconies, Doors and Windows New Classic Buildings Video Door Window Modelling for Roman Settlements Automatic generation of Roman cities Grammar for describing Roman settlements derived from the writings of Vitruvius including - Location - Road structures - Important building structures • Temples, theatres, baths and civic buildings Roman Settlement Planning The corners of the city are recorded and the buildable area is marked off Next the buildings of significance are added - i.e. forum, theatre, and basilica The remaining space is filled with generic structures 23 4/20/2016 Building Placement Methods Method 1: Random Selection Method 2: Sectioned Districts Method 3: Probability Distribution The red square marks the centermost point of the city (i.e. the forum), and the yellow squares indicate a special buildings, such as the coliseum or temple. The light, medium, and dark grey squares represent residential structures, religious structures, and governmental structures respectively V Temple Implementation Example Temple Repeated Stairs Altar ][ Cuboid ][ Door ] J 1 Base 1 Roof 1 1 Cuboids II Facade | Tiles J Base || Shaft ]| Capital Vitruvius Temple Base Definition Basic Vitruvius roof shape Vitruvius Temple Cella Definition Vitruvius Temple Stairway Definition Vitruvius Temple Column Definition Results i i [ www r^^n r^^n r^^n , EE I r.'ijbc (mm. [:il)'n'--m'i 1 iíi I Tora I '12 polygon .I„ii:i '.Ii.nr:-.- Octagonal mlumr with polygon indents pnlyiy!-. Computer Graphics ii- po \