70
Department of Science and Technology Institutionen för teknik och naturvetenskap Linköping University Linköpings universitet g n i p ö k r r o N 4 7 1 0 6 n e d e w S , g n i p ö k r r o N 4 7 1 0 6 - E S LiU-ITN-TEK-A-14/042-SE Example Based Procedural Distribution Tool Anders Nord 2014-09-26

Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Department of Science and Technology Institutionen för teknik och naturvetenskap Linköping University Linköpings universitet

gnipökrroN 47 106 nedewS ,gnipökrroN 47 106-ES

LiU-ITN-TEK-A-14/042-SE

Example Based ProceduralDistribution Tool

Anders Nord

2014-09-26

Page 2: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

LiU-ITN-TEK-A-14/042-SE

Example Based ProceduralDistribution Tool

Examensarbete utfört i Datateknikvid Tekniska högskolan vid

Linköpings universitet

Anders Nord

Handledare Stefan GustavsonExaminator Patric Ljung

Norrköping 2014-09-26

Page 3: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Upphovsrätt

Detta dokument hålls tillgängligt på Internet – eller dess framtida ersättare –under en längre tid från publiceringsdatum under förutsättning att inga extra-ordinära omständigheter uppstår.

Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner,skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat förickekommersiell forskning och för undervisning. Överföring av upphovsrättenvid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning avdokumentet kräver upphovsmannens medgivande. För att garantera äktheten,säkerheten och tillgängligheten finns det lösningar av teknisk och administrativart.

Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman iden omfattning som god sed kräver vid användning av dokumentet på ovanbeskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådanform eller i sådant sammanhang som är kränkande för upphovsmannens litteräraeller konstnärliga anseende eller egenart.

För ytterligare information om Linköping University Electronic Press seförlagets hemsida http://www.ep.liu.se/

Copyright

The publishers will keep this document online on the Internet - or its possiblereplacement - for a considerable time from the date of publication barringexceptional circumstances.

The online availability of the document implies a permanent permission foranyone to read, to download, to print out single copies for your own use and touse it unchanged for any non-commercial research and educational purpose.Subsequent transfers of copyright cannot revoke this permission. All other usesof the document are conditional on the consent of the copyright owner. Thepublisher has taken technical and administrative measures to assure authenticity,security and accessibility.

According to intellectual property law the author has the right to bementioned when his/her work is accessed as described above and to be protectedagainst infringement.

For additional information about the Linköping University Electronic Pressand its procedures for publication and for assurance of document integrity,please refer to its WWW home page: http://www.ep.liu.se/

© Anders Nord

Page 4: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Thanks

I would like to thank EA Frostbite for this opportunity and the Frostbite team for all thehelp provided. I would also like to thank my supervisor at Frostbite, Bjorn Ottosson, forgood advice and guidance. A lot of the ideas in this thesis arose during our discussions.

Figure 1: Frostbite logo inside FrostEd. Shards placed with the implemented tool.

Page 5: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Abstract

This report will deal with the process of creating an example based proceduraldistribution tool. This is accomplished within the Frostbite game engine editor, FrostEd.The design of the tool is based on artist’s desires and wishes. By using actual placementsof objects in the editor as in-data, the tool provides the artist with an unmatched visualfeel for calibrating its properties and settings. Note that this is a unique technique andwas invented during the creation of this tool. The tool is based on a machine learningapproach. It creates a feature vector from the example placements for each type ofobject. These vectors are then used to create statistical models which in turn areused to generate new object placements. The process of determining the position androtation when generating an object is divided into two parts. A new concept calledFeature Function (FF) is utilized to provide each element in the population with aprobability to obtain a certain position and rotation.For position dart throwing makes a first weed out. Simulated annealing helps avoidinggetting stuck in local maximas. And finally the Kolmogorov Smirnov Normality Testevaluates the probability for each sample that the simulated annealing has provided. Forthe second part multivariate distributions evaluate how the object is rotated accordingto certain predefined vectors, such as the surface normal and the world-up vector. Theresults were satisfying and proved that this new method works. The implemented toolhad a distribution time that scaled badly, but there are explanations to why and howto solve this issue in the report.

i

Page 6: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Acronyms

2D Two-Dimensional. 4, 14, 15

3D Three-Dimensional. 9, 14

CDF Cumulative Distribution Function. 13

CV Coefficient of Variation. 31, 54

ECDF Empirical Cumulative Distribution Function. 13

FF Feature Function. i, 7, 8, 17–19, 22–24, 31, 33, 41, 42, 44, 51, 52

FPF Feature Placing Function. 8, 9, 11, 13, 18, 20, 22, 23, 32, 40, 46, 50, 52

FRF Feature Rotation Function. 9, 18, 20, 27–30, 41, 48

GUI Graphical User Interface. 19

HD High-Definition. 1

KS Kolmogorov Smirnov. 13, 18, 32, 33, 46–48, 52

MPDF Multivariate Probability Density Function. 9, 10, 52

SA Simulated Annealing. 11–13, 18, 31, 32, 44, 45, 51, 52

SI International System of Units. 13, 31

STD Standard Deviation. 8, 12, 33, 42, 44, 46–48, 50, 51

UPDF Univariate Probability Density Function. 8, 9, 12, 13, 21

ii

Page 7: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Contents

I Introduction 1

II Background 3

III Theory 4

1 Sampling 41.1 Random sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Poisson disk sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3 Jitter grid sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 Final sample 62.1 ECO - Teleological . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 Density function - Ontogenetic . . . . . . . . . . . . . . . . . . . . . . . . . 62.3 Probability sampling - Ontogenetic . . . . . . . . . . . . . . . . . . . . . . . 7

3 Feature function 83.1 Feature placing function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.2 Feature rotation function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.2.1 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Search heuristics 104.1 Hill climbing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.2 Simulated annealing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 Test of normality 125.1 Arbitrary test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.2 Kolmogorov smirnov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6 Artistic control 146.1 Sampling area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

6.1.1 Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146.1.2 A volume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.1.3 Masks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

6.2 Iteration and workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.2.1 Seed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166.2.2 Freeze . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

IV Method 17

iii

Page 8: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

7 Preliminary study 17

8 Implementation 178.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178.2 Execution order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188.3 Graphical User Interface (GUI) . . . . . . . . . . . . . . . . . . . . . . . . . 198.4 Technical implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

8.4.1 Dart throwing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218.4.2 Feature Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228.4.3 Deciding which FF to use . . . . . . . . . . . . . . . . . . . . . . . . 318.4.4 Kolmogorov Smirnov . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

8.5 Freeze objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

V Result 388.6 Preliminary study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.7 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

8.7.1 Sampling area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.7.2 Showcase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408.7.3 Observations and measurements . . . . . . . . . . . . . . . . . . . . 42

8.8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

9 Discussion 529.1 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529.2 Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

10 Conclusions 53

11 Future work 5311.1 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5311.2 Distribution fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

A Source code 59A.1 Random sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59A.2 Jitter grid sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59A.3 Dart throwing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59A.4 Simulated annealing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

A.4.1 Flip function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60A.4.2 Acceptance funtion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

A.5 Random unit quaternion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

iv

Page 9: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 2: A forest generated by the final implementation of the tool. The feeling andcomposition created by the different objects are based on the example area seen in figure19, which is created by an artist.

Part I

Introduction

Game worlds are increasingly getting bigger, which means that more High-Definition (HD)content needs to be created. Hiring more artists is not really an option since there istoday already a couple of hundred people working on a AAA-game (pronounced ”tripleA”). AAA is the classification term used for describing high quality games with a largebudget, the equivalent in the film industry would be a blockbuster. By implementing artistfriendly procedural tools, the game worlds can be created in a more efficient and quickerway without losing quality.

The goal of this thesis was to create an artist friendly example based procedural distributiontool. By using sample placements, there will be an increase in the amount of productivityand control that the artist can achieve. The artist will be able to focus on the things thatare important, rather than creating similar areas over and over. To quote Ruben M. Smeliket al.[1]: ”A simple set of input parameters or a few generation rules of the proceduralmodel yield a wide variety of models”. This leads to the questions:

• How can procedural methods be applied when creating a useful procedural distribution

1

Page 10: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

tool which has the desired level of artistic control?

• How should a tool like that be designed?

The thesis has been delimited by criteria based on interviews carried out with artists. Themain focus is environments that can somehow be described by certain abilities. Like treesgetting clustered in nature, or trash getting collected close to the sidewalk. The artistshould be able to have good control over the objects getting created. They should also beable to remove the things they do not like and get direct feedback to make iteration easy.So a lot of earlier research in procedural content generation does not work very well for thistype of tool and workflow.

2

Page 11: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Part II

Background

There are a lot of different methods for creating game worlds procedurally. This the-sis started out with a very general direction. Many different areas were examined andevaluated accordingly to what tools already existed inside FrostEd and to what seemedexploratory. Three artists were interviewed about the chosen area, procedural object dis-tribution. The questions dealt with how they felt about the distribution tools alreadyexisting inside FrostEd today and what was requested from the new tool. These interviewsconcluded that:

• Tools for placing smaller non colliding objects like ferns and gravel-rocks works welland does what is desired.

• The object distribution tools that exists does not create realistic looking distributionsor areas when placing objects. They do not follow any specific pattern and that makesthem hard to use and predict.

And important aspects in general:

• Be able to iterate quickly to create a good workflow.

• Rotations often has to be altered later when procedurally distributed.

• Be able to align objects against the surface.

• In environments things are often clustered naturally.

• Key features of the environment are: Corners and slopes, material on the ground andtopography in general.

• A function for ”freezing” certain areas and redistribute the non-frozen areas.

• A high-quality foundation since there is often not enough time to place as manyobjects as desired.

• Have presets since it sometimes can be hard to understand a tool with many inputparameters.

3

Page 12: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Part III

Theory

As an introduction to get a general overview of procedural creation see [1]. For an introduc-tion to the different types of procedural methods and to the importance of artistic control,see [2]. There were no actual papers about example based procedural tools found thatseemed appropriate for this task. But many of the methods involved to achieve the finalresult has been researched individually and have papers dedicated to their solutions.

1 Sampling

To be able to compare different element placements, their positions are sampled in a discreteTwo-Dimensional (2D) space. Together these elements create a population. There are manydifferent ways of sampling an arbitrary amount of elements. The methods researched duringthis thesis were random sampling, jitter grid sampling and Poisson disk sampling.

1.1 Random sampling

Random sampling, also known as stochastic sampling, samples elements with random po-sitions. It is easy to implement but creates some unnatural clumping due to the nature ofchoosing random numbers. This can be observed in figure 3. For further reading see [4] andappendix A.1 for source code.

Figure 3: 200 elements uniformly sampled randomly. This method is computationally cheapbut ends up clumping the elements together if no bounding conditions are set.

4

Page 13: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

1.2 Poisson disk sampling

Poisson disk sampling samples evenly distributed elements with a random looking feel.This is achieved by sampling new elements around already added elements with a minimumdistance condition. This method is however computationally expensive and therefore timeconsuming. Depending on the application, this might be more or less justifiable. Theelements in figure 4 have been sampled using Poisson disk sampling. See [5] for furtherreading and code implementation.

Figure 4: Elements sampled with Poisson disk sampling. This method solves the clumpingproblem seen in figure 3 but is computationally more expensive.

1.3 Jitter grid sampling

The grid will distribute the elements evenly, as shown in figure 5.a. To get a random lookingfeel, the elements positions are displaced from the grid, as shown in figure 5.b. They areboth easy to implement and provide good performance. For further reading containing amore detailed explanation, see [4]. See appendix A.2 for source code.

Figure 5.a Figure 5.b

Figure 5: 5.a: Elements sampled using grid sampling. 5.b: Elements sampled using jittergrid sampling. Just by moving the elements a small distance a random feeling is created ata much lower cost than by using poisson disk sampling.

5

Page 14: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

2 Final sample

From the sampled elements representing the total population, only a few will be in the finalsample. This is achieved by using teleological or ontogenetic methods. A teleological methodis an accurate physical model of the environment, e.g. an eco-system. An ontogeneticmethod is an attempt to reproduce natural results with arbitrary algorithms.

The distance between sampled elements can be utilized to avoid overlapping by re-samplethem until a shortest distance condition is met. Compare figure 6 and figure 3 and visit [4]for a similar approach. There are other ways to achieve the same result by using 3D-meshes.In that case bounding boxes, bounding spheres, ray-tracing or vertex-intersection are a fewof the methods that can be used for collision detection.

Figure 6: 200 elements uniformly sampled randomly with a radius-distance collision condi-tion. Avoiding elements intersecting is often desired to avoid 3D-meshes from getting tooclose to each other.

2.1 ECO - Teleological

When sampling different species, every sampled element has a circle radius. Biologicallymotivated rules make use of the interaction between the intersecting circles. In [8] the rulesare defined as: If the circles representing two plants intersect, the smaller plant dies and itscorresponding circle is removed from the scene. Plants that have reached a limit size areconsidered old and die as well. For further reading visit [8] and [9].

2.2 Density function - Ontogenetic

By letting a continuous function affect the density, irregularity or regularity can be obtained.These type of functions are however hard to control. See figure 7 and figure 8 for visualresults using density functions.

6

Page 15: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 7: A density function consisting of sin and cos elements. This shows that it is possibleto control the density of the elements but the feeling of randomly generated positions islost.

Figure 8: Poisson disk sampling, where the minimum distance is driven by Perlin noise. Theclumping of elements is great when placing grass and many other type of objects. Picturetaken from [5].

2.3 Probability sampling - Ontogenetic

Each element is assigned an individual probability value. This is achieved by letting themget evaluated by a FF. Briefly the idea is to let each element in the current sample getevaluated by a FF that returns a value according to a specified task. In figure 9 a FF thatreturns the distance to the closest element in the current sample has been used. See 3 fora more detailed explanation.

7

Page 16: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 9: The final sample of elements that has used a FF that returns the distance to theclosest element in the current sample. This FF replaces the need for having a radius-distancecollision condition.

3 Feature function

A Feature Function (FF) is a short function that evaluates each element in a sample sep-arately and returns an individual value accordingly. This individual value corresponds towhat the FF takes into account. Note that this is a unique technique created for this tool.In practice it is possible to let the FF calculate a value based on whatever is desired.

3.1 Feature placing function

The Feature Placing Function (FPF) uses the position of the element in various ways todetermine a return value. In figure 10 the stone-elements (grey circles) have used a FPF thatreturns the distance to the closest tree-element (green circles). This is the individual valueused to evaluate how likely the element is to end up in the final sample. The evaluationuses a Univariate Probability Density Function (UPDF). The mean and Standard Deviation(STD) are set by the artist or according to example element placements. E.g. the meandistance to trees and the estimated differential in the earlier example.

8

Page 17: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 10: A final sample of stones (grey circles) that has used a FPF which returns thedistance to the closest tree (green circles). The visualization creates a clear understandingof how the positions of the stones are related to the positions of the trees.

3.2 Feature rotation function

The Feature Rotation Function (FRF) utilizes arbitrary Three-Dimensional (3D)-vectorsrepresented in world space to describe the rotation of an object. The vectors are transformedinto the local space of the examined object. This local representation can contribute to ageneral perception of how the object is rotated compared to its X, Y and Z axes.

In figure 11 the red arrow is represented in two different coordinate systems. In world space,figure 11.a, it is parallel with the objects green Y-axis-arrow. In 11.b it is represented inthe objects local space with different X, Y and Z values. So the basic idea of a FRF issimilar to the one of a FPF. But instead of returning a single value to evaluate, it returnsa 3D-vector. To evaluate this vector, a Multivariate Probability Density Function (MPDF)is used instead of a UPDF.

9

Page 18: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 11.a Figure 11.b

Figure 11: 11.a: World space coordinate system. 11.b: Local space coordinate system. Thered arrow represents the world space up vector.

3.2.1 Quaternions

To be able to find rotations for the elements in the final sample that corresponds to theearlier apprehended local vectors, random unit quaternions are utilized. The identifiedworld space vectors are transformed into the local space of the quaternion. Then theMPDF, created from the mean of the examined objects local vectors, can return individualprobability values for each quaternion. This value represents how well it compared with thevectors represented by the MPDF. See appendix A.5 for source code.

4 Search heuristics

When examining the different samples and their element distributions, the goal is to findthe optimal global distribution. It is important to realize that there will be a large searchspace if thousands of elements are going to be evaluated, whilst maybe only a few of themwill be in the final sample.

4.1 Hill climbing

The hill climbing algorithm starts out with an arbitrary solution to the problem. It thentries to find a better solution by iteratively stepping forward. If a better solution is found,it will be the new best solution. This is repeated until no better solution can be found. The

10

Page 19: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

problem here is that the hill climbing algorithm is a local search algorithm, meaning it willget stuck in local optimums. Depending on the initial state it may or may not find the bestsolution. In figure 12, the hill climber will get stuck in the local maximum.

Figure 12: Hill climber algorithm getting stuck in a local maximum. Each FPF used wouldincrease the probability of getting stuck in a local maximum.

4.2 Simulated annealing

Simulated Annealing (SA) uses annealing in metallurgy as a metaphor to describe how itworks. When annealing metal, the metal is exposed to heat above its critical temperaturewhich makes it possible to alter its physical properties. The metal solidifies as it cools andadapts to its new form. This cooling process is simulated by a temperature variable. Asthe algorithm runs, the temperature is slowly decreasing. The effect is that the higher thetemperature, the bigger the jumps in the search space. The algorithm is also likelier toaccept a worse solution than the current one. The gist from this is that local maxima’s andminima’s can be avoided. This can be observed in figure 13, where the SA jumps from 2to 3 and from 4 to 5, even though they are worse solutions than the current ones. SA cancontribute to find an acceptably good solution within a shorter amount of time than anexhaustive enumeration would. But it might not find the best possible solution.

11

Page 20: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 13: SA jump behavior. This is a computationally expensive way to find a goodsolution, but badly needed for all the fall pits in the global space.

SA overview pseudocode:

1. Set the initial temperature and solution

2. Start the loop that iterates on the algorithm. This loop will stop when either thetemperature is too low or when a good enough solution has been found.

3. Make a change to the current solution, small or big depending on the temperature.

4. Decide whether or not to move to the new state by using an acceptance function.

5. Decrease the temperature and continue looping.

For implementation details see [10] and appendix A.4.2.

5 Test of normality

To be able to know how well the current element distribution fits the UPDF a test isperformed. This is called a test of normality.

5.1 Arbitrary test

To compare the observed values against the UPDF in a simple manner, the mean and STDvalues are utilized as in equation 1.

f(x) = (pdfMean − observedMean)2 + (pdfStd − observedStd)2 (1)

12

Page 21: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

This method does not work well if different International System of Units (SI) are used bythe different FPFs. It also fails to know whether or not the elements are evenly distributedaccordingly to the UPDF. Also only works well with a normal UPDF.

5.2 Kolmogorov smirnov

The Kolmogorov Smirnov (KS)-test calculates the biggest difference between a distributionevaluated by the Empirical Cumulative Distribution Function (ECDF), seen in equation 2where I is the indicator function, and the Cumulative Distribution Function (CDF), seenin equation 3.

Fn(t) =number of elements ≤ t

n=

1

n

n∑i=1

I(xi ≤ t) (2)

F (x) =

∫ x

−∞f(u)du. (3)

Figure 14: The red line is the CDF, the blue line is the ECDF, and the black arrow is wherethey differ the most, the KS value. By looking at how similar they are, it is easy to see howwell the SA performed.

Figure 14 visualizes the ECDF, the CDF and where they differ the most. The differenceis the KS value. The KS-test is independent of what type of SI-unit and magnitude theevaluated distribution is using since the CDF always returns a value between 0.0 and 1.0.It also tries to make sure that the elements are distributed according to the UPDF. Formore specific details see [11].

13

Page 22: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

6 Artistic control

One of the most important things when creating tools is the artist’s workflow and experiencewhen using it. This is a complicated problem when using procedural content creation. Tobe able to control and apprehend where the final element distribution will end up is not aneasy task. The result is often shaped by many stages.

6.1 Sampling area

The sampling area determines where the elements are sampled. This area is used as a highlevel description controlled by the user.

To find the objects height positions in a 3D space, each position is raytraced from above.This is due to that the position of the element is originally defined in the 2D plane. Thedensity affects the result in a very visual way. It is either defined separately, as in equation4, or combined with a high level description.

Density =number of objects

sampling area(4)

See [13] for more high level description techniques and example based workflows.

6.1.1 Square

A square that represents where the elements will get sampled. See figure 15.

Figure 15: The blue square indicates the sampling area. The red objects are generated fromelements.

14

Page 23: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

6.1.2 A volume

When the sampling area is represented by a volume, there are some neat benefits. Theraytracing mentioned in 6.1 can start out from the ”roof” of the volume. This way objectscan get generated inside caves and such. The shape of the volume can also be altered. Toknow how you are inside the volume visit [12]. They implement a check to see if a point isinside a polygon in 2D.

6.1.3 Masks

The mask is painted on top of a terrain or object where the artist wants to generate newobjects. Masks are good at giving an indication about density and placing. See figure16.

Figure 16: The color of the mask indicates the magnitude of density. Green indicates highdensity, red indicates low density and blue indicates zero density. This is a very intuitiveand visual way of describing where the elements will end up.

6.2 Iteration and workflow

To be able to iterate when procedurally creating big areas, it is desirable to be able tocontrol what stays and what should be re-generated.

15

Page 24: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

6.2.1 Seed

Normally the pseudorandom number generator uses a random seed. But the seed can bepredetermined and this would have the algorithm generate numbers in the same sequenceevery time. This would ensure the elements to turn up on the same location each time,even on different machines.

6.2.2 Freeze

This effect can be created by freezing the objects that you want to keep and then re-generate the ones that you don’t want to keep. See 8.5 in the method chapter for picturesand workflow.

16

Page 25: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Part IV

Method

7 Preliminary study

For a background read part II. The main idea at this point was to focus on the usabilityand the workflow of the tool. This turned out to be difficult because of a plurality of factorsthat are mentioned in section 9.

An early decision was to ignore elements overlapping due to the observation studies per-formed on maps that shipped with battlefield 4. A lot of objects were tucked into eachother, which reads into the need for elements to be able to be placed on top of each otherwith mesh intersection as a result. Another observation from the maps was that objectstended to be located near corners and slopes. Also certain rotations like stones rotatedaway from bigger stones and a strong dependency of the normal and world up vector werenoticed.

8 Implementation

8.1 Overview

The final tool is based on a stratified sampling technique [3]. It divides the different typesof objects into separate groups referred to as strata’s. The strata’s are then generated ina predefined order set by the user. This causes the strata’s to have different dependency-possibilities between each other. For example: If trees and stones are two strata’s and thetrees are sampled first, they can only depend on themselves and the environment. The stonesare sampled second and can depend on themselves, the environment and the trees. Thiscan be observed in figure 17 where the trees cannot depend on the positions of the stones.The sampling-order-dependency has a great impact on how the FFs are structured.

17

Page 26: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 17: The trees were sampled first, only depending on the distance to each other.Secondly the stones were sampled, only depending on the distance to the trees.

FFs provides the possibility to analyze example placements in a natural way. A clearadvantage over the other final-sample-deciding methods. Normal univariate 5 and normalmultivariate distributions are the only distributions implemented. The normal distributionwas used because of two reasons: It is a distribution pattern occurring in many naturalphenomena’s but also because of limited development time. See the 11.2 section for adiscussion regarding this subject.

f(x, µ, σ) =1

σ√

2πe

−(x−µ)2

2σ2 (5)

8.2 Execution order

The elements are randomly sampled and sent through the FPFs where they obtain theirinitial individual probability values. When using more than one FPF, their probabilityvalues are multiplied together into a total probability value. These total probability valuesare then being normalized. Before entering the SA loop there is a weed out of the elements.This weed out is performed by a dart throwing algorithm explained in section 8.4.1. Thisdecrease in the element population affects SA and KS performance and results. SA combinedwith KS is utilized to find a suitable final distribution of the elements. The FRF will thendecide the rotation of the final elements.

18

Page 27: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

8.3 Graphical User Interface (GUI)

Figure 18: The context pad on the left shows the different object-strata’s in the order theywill be sampled. The property grid on the right shows the different settings available forthe selected strata. The goal with the tool is that the artist should never have to worryabout or change these values.

The implemented GUI can be seen in figure 18. Notice how the second object containsFFs that depends on the object that gets sampled first. E.g. RaytraceDistance - Against:Tree Pine 01.

The workflow:

• 19: Example object placements

• 20.a: Select the objects and analyze them

• 21.a: Mark the sampling area and start sampling

• 21.b: The result

19

Page 28: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 19: The example placements. This is all that the artist have to create to controlhow the resulting distribution ends up looking.

Figure 20.a Figure 20.b

Figure 20: 20.a: Analyze the selected example placements. 20.b: The resulting context padand property grid. By selecting the objects in the marked area and press analyze, the toolwill calibrate for all the FPFs and FRFs needed to recreate a similar area.

20

Page 29: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 21.a Figure 21.b

Figure 21: 21.a: Mark the distribution area and start scattering. 21.b: The resultingdistribution.

8.4 Technical implementation

8.4.1 Dart throwing

This dart throwing algorithm was invented for this tool and is utilized to weed out elementsfrom the population. The algorithm is most likely to pick elements with a high probability,but can also happen to pick elements with a low probability. This is essential so that later,the population will be able satisfy the UPDF.

The idea is to generate a random number between zero and the sum of all the individualprobability values. These values are added together into a total value, one at a time. Whenthe total value is larger or equal to the random value, the current element-index is returned.The result ends up being that indices for high probability elements are most often returned,but not always. See figure 22 for an example and appendix A: A.3 for source code.

Figure 22: Illustrates an array containing 3 individual values. For random value = 0.7,index 1 would have been returned.

21

Page 30: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 23.a Figure 23.b

Figure 23: 23.a: No dart throwing used. 23.b: Dart throwing used only. The smallest greendots obtained probability values from a ”distance to the closest tree” FF and were thenevaluated by dart throwing only.

8.4.2 Feature Function

Since this technique was invented for this tool, so was all of the implemented FFs. Theyreflect the specific desires of this tool, which is good to bear in mind.

Placing functionsThere are two types of placing functions. The ones that can take the current strata

and other strata’s into account, these are called dependency functions. And there are theones that only take the environment into account these are called solo functions. Whenthe dependency functions perform calculations against its own strata, it is called a selfie-dependency-function. This will affect how and when they are calculated. What needsto be avoided in a selfie-function-case are calculations being performed against the elementcurrently being evaluated. E.g. if an element wants to find the shortest distance to any otherelement in the current sample, calculations against itself would end up being devastatingfor the result.

The FFs are created using something called closures in the C# language. Closures makeit possible to have a list for each stratum with the FPFs that they are going to use. Theclosure also lets the function keep track of against which strata it is supposed to perform cal-culations. The FPFs will then be named ”*FPF name* - Against: *name of strata*”.

It was a big challenge to get these FPFs to work well together, but it is the key to make amethod like this produce good results. The individual probability values from each FF ismultiplied together as a total probability for each element. The tool settings in the propertygrid can be set using example data or by hand. Adjusting the settings by hand can be hard

22

Page 31: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

when some FFs do not use easily understandable units. This justifies example data analysisand why it is something worth putting more effort into. These are the main implementedFPFs:

ShortestDistanceThis is a dependency function. It calculates and returns the distance to the closest element

in the current sample. Only the positions of the elements are utilized. This function is usedwhen the distance between elements needs to be controlled. E.g. elements overlapping canbe avoided and it measures in meters.

Figure 24.a Figure 24.b

Figure 24: 36: Example placings. 24.b: Result.

ShortestDistanceTo4ClosestThis is a dependency function. It calculates and returns the total distance to the four

closest elements in the current sample. Only the positions of the elements are utilized. Thisfunction is used when clumping of elements is desired and it measures in meters.

23

Page 32: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 25.a Figure 25.b

Figure 25: 25.a: Example placings. 25.b: Result.

RaytraceDistanceThis is a dependency function. It calculates and returns the distance to the closest earlier

placed strata-object-mesh. The difference between the RaytraceDistance and the Shortest-Distance FF is that RaytraceDistance will cast a ray towards the strata-objects-mesh. If theelement is located inside the mesh, RaytraceDistance will return a negative distance value.This ends up working similar to a signed distance field. The RaytraceDistance function iscomputationally more expensive than ShortestDistance but will find the actual edge of theearlier placed mesh. It measures in meters.

Figure 26.a Figure 26.b

Figure 26: 26.a: Example placings. 26.b: Result.

24

Page 33: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

FindEdgesThis is a solo function. It uses the discrete Laplace operator seen in equation 6 to calculate

if the element is located near an edge or slope. It can separate between if a position is belowor above an edge.

∆f(x, y) ≈ (f(x− h, y) + f(x+ h, y) + f(x, y − h)

+f(x, y + h)− 4f(x, y))/h2 (6)

Figure 27: Example placings.

Figure 28: Result.

25

Page 34: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

SlopeAngleThis is a solo function. It calculates the angle between the normal and world up vector,

seen in equation 7, where the element is located. It measures in degrees.

f(x, y) = acos(worldup · normal) ∗ 180

π(7)

Figure 29.a Figure 29.b

Figure 29: 29.a: Example placings. 29.b: Result.

Rotation functions Arbitrary landmark vectors were used to identify the rotations.These were apprehended by talking to the artists and by looking at levels from Battlefield4. The conclusions drawn:

• The surface normal is important when aligning objects with the terrain.

• The World Up vector is important in cases when vertical objects ( e.g. trees ) arelocated in slopes. Even though they are in a slope, they point almost straight up.

• It is important to be able to know how the object is rotated in general, not just howaligned it is with the surface. To solve this, the gradient of the slope and directiontowards other objects was utilized.

The general happening for each object when analyzing example placements rotations, endedup looking like:

26

Page 35: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

1 fo r each ob j e c t2 Extract landmark vec to r in world space34 Transform landmark vec to r in to l o c a l space5 end67 Create a MPDF from observed ve c t o r s

The general happening for each element in the final sample, when applying rotations, lookslike:

1 fo r each quatern ion2 Extract landmark vec to r in world space34 Transform landmark vec to r in to quatern ion l o c a l space56 Let the MPDF eva luate the transformed vec to r7 end89 Use dart throwing to choose quatern ion

It was made sure that there were enough quaternions that satisfied a rotation for the worldup vector. This was achieved by generating extra quaternions with a small random deviationfrom the desired rotation. The more quaternions generated, the likelier it is to find a goodfit for the distribution. In the following FRF-descriptions, only the current function is takeninto account when choosing which quaternion to use.

Surface NormalThis FRF transforms the surface normal into the local coordinate space of the object. In

figure 31, the trees local up vector is aligned with the surface normal direction.

Figure 30: Example placings.

27

Page 36: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 31: Result.

WorldUpThis FRF transforms the World up vector into the local coordinate space of the object.

In figure 33, the trees local up vector is aligned with the world up vector.

Figure 32: Example placings.

28

Page 37: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 33: Result.

Surface GradientThis FRF transforms the surface gradient into the local coordinate space of the object.

In figure 35, the shards rotations are depending on the surface gradient. They are perpen-dicular to the world up vector and rotated away from the hill.

Figure 34: Example placings.

29

Page 38: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 35: Result.

DirectionThis FRF transforms the direction against the closest object, from another stratum, into

the local coordinate space of the object. In figure 37, the shards rotations are dependingon the direction towards the rock.

Figure 36: Example placings.

30

Page 39: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 37: Result.

8.4.3 Deciding which FF to use

When using example placing’s there is a need for knowing if a FF is relevant. In thiscase, a relevant FF would describe something that the artist have taken into account whenplacing the objects. This is important mainly due to performance but also for avoidingbiased results. The most common technique to decide if a distribution is relevant is calledCoefficient of Variation (CV). The CV is defined as the ratio of the standard deviation σto the mean µ as seen in equation 8.

cv =σ

µ(8)

The CV is a dimensionless number, meaning it does not matter in which unit it has beenmeasured. And a lot of different SI-units are used in the FFs. The CV however, does notwork well when dealing with distributions that can have mean values close to zero. Thisdid not get solved during the thesis but propositions for solving this can be found in section11.2.

Simulated annealingThe SA is utilized as a global optimization algorithm to test out different combinations

of elements. Functionality for deciding if an element is in the current sample or not isimplemented. The temperature will affect how many elements that are switched each timeand randomly chosen elements are set as the initial current sample. When the SA starts,a new sample is generated by a function that switches the elements. This switch-functionuses the current sample as a foundation for the new sample. The new sample is then first

31

Page 40: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

re-evaluated by the selfie-FPFs, then evaluated by the KS-test and finally by an acceptancefunction. If the new sample gets accepted by the acceptance function, it overwrites thecurrent sample. The SA also keeps track of the best sample that has occurred so far,according to the KS-test-value. In figure 38 the SA is running. The current sample is red,the new sample is green and the best sample is blue. The new sample does not differ fromthe current sample. This indicates that the new sample was accepted.

Figure 38: SA while testing different samples. Red are current sample, blue is the bestsample and green is the evaluated new sample.

Pseudocode for the SA-algorithm:

1 Set an i n i t i a l cur r ent sample2 whi l e temperature > a rb i t r a r y value3 Switch−f unc t i on gene ra t e s a new sample45 The new sample i s re−eva luated by the s e l f i e −f e a t u r e p l a c ing func t i on s67 KS−t e s t eva lua t e s new sample89 i f the new sample i s accepted

10 s e t new sample as cur rent sample ;11 i f new sample > best sample12 s e t new sample as bes t sample ;13 Decrease temperature ;14 end15 end

Source code can be found in appendix A at: A.4.

32

Page 41: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

8.4.4 Kolmogorov Smirnov

The KS-test uses the total probability from each element as indata. The following figureshas used the FF shortestDistance 8.4.2 with a mean µ = 1,0 and STD σ = 0,1. These aremeasurements between visual result and the corresponding KS-test values:

Figure 39.a Figure 39.b

Figure 39: 39.a: Visual result - SA cooling constant = 0,1 - Final ks value = 0,632. 39.b:Visual result - SA cooling constant = 0,01 - final ks value = 0,217.

Figure 40: Visual result - SA cooling constant = 0,0001 - final ks value = 0,039.

33

Page 42: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 41: The cumulative and empirical values from figure 39.a.

Figure 42: The cumulative and empirical values from figure 39.b.

34

Page 43: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 43: The cumulative and empirical values from figure 40.

Figure 44: The elements total probability values from each stage. Notice how series3 isshaped like the normal distribution.

8.5 Freeze objects

The ability to freeze objects between re-sampling was implemented. After the initial sam-pling, the objects that are desired for keeping can be frozen. Then when the sampling-button

35

Page 44: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

is pressed again, all of the objects except the ones that are frozen gets re-sampled.

Figure 45: Initial sampling.

Figure 46: Select objects to freeze.

36

Page 45: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 47: Frozen objects.

Figure 48: Result after re-scattering.

37

Page 46: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Part V

Result

8.6 Preliminary study

The obtained information from the preliminary study contributed to apprehend a deeperknowledge and insight into procedural methods. Based on this study, the tool and visionfor the thesis could be justified.

8.7 Implementation

8.7.1 Sampling area

The example placings used can be seen in figure 19. Here are the resulting final sample fordifferent sampling areas:

Figure 49: Total time: 2:44 minutes - Area: 432 m2.

38

Page 47: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 50: Total time: 10:48 minutes - Area: 864 m2.

Figure 51: Total time: 50:30 minutes - Area: 1728 m2.

39

Page 48: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 52: Measured from section 8.7.1.

8.7.2 Showcase

Edge findingThis example demonstrates how the FPF FindEdges can distinguish between positions

above and below edges.

Figure 53: Example placements.

40

Page 49: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 54: Result using FFs FindEdges and SlopeAngle.

RotationThis example demonstrates how the FRF Direction can identify and apply a rotation

depending on where another object is located.

Figure 55: Example placements.

41

Page 50: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 56: Result using FF ShortestDistanceTo4Closest, RaytraceDistance and Direction.

Pre-placed objectsThe tool is able to use pre-placed objects and take them into account when sampling new

objects.

8.7.3 Observations and measurements

Dart throwingIn this example the tool was set to sample 5000 candidate elements and have 50 elements

in the final sample. The RaytraceDistance FF was used with a mean µ = 0,2 and STD σ= 0,1.

42

Page 51: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 57.a Figure 57.b

Figure 57: 57.a: Result when dart throwing set to keep 100% of the candidate elements.57.b: Result when dart throwing set to keep 50% of the candidate elements.

Figure 58.a Figure 58.b

Figure 58: 58.a: Result when dart throwing set to keep 10% of the candidate elements.58.b: Result when dart throwing set to keep 2% of the candidate elements.

43

Page 52: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 59: Sampling time visualized for different dart throwing values.

Simulated annealingIn this example the tool was set to sample 5000 candidate elements and have 50 elements

in the final sample. The RaytraceDistance FF was used with a mean µ = 0,2 and STD σ= 0,1.

Figure 60.a Figure 60.b

Figure 60: 60.a: Result when SA cooldown rate set to 0,1. 60.b: Result when SA cooldownrate set to 0,01.

44

Page 53: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 61.a Figure 61.b

Figure 61: 61.a: Result when SA cooldown rate set to 0,001. 61.b: Result when SAcooldown rate set to 0,0001.

Figure 62: Sampling time visualised for different SA cooldown rates.

Number of candidate elementsThe chart in figure 63 visualize how the amount of candidate elements affects the sampling

time:

45

Page 54: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 63: Sampling time visualized for different amount of candidate elements.

Different Standard Deviation values for Feature Placing FunctionsThe STD values have a great impact on the results and do not always act as predicted.

A lower STD value generates less deviation from the mean value. But if the STD value istoo low; a lot of elements will obtain a zero probability value. This phenomenon can beseen in figure 64.a where the STD value is very low. Here are a few pictures that show howSTD affects the KS value and the visual result:

Figure 64.a Figure 64.b

Figure 64: 64.a: KS = 0,604 and STD = 0,001. 64.b: KS = 0,26 and STD = 0,01.

46

Page 55: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 65.a Figure 65.b

Figure 65: 65.a: KS = 0,12 and STD = 0,1. 65.b: KS = 0,14 and STD = 0,5.

Figure 66.a Figure 66.b

Figure 66: 66.a: KS = 0,127 and STD = 1,0. 66.b: KS = 0,15 and STD = 2,0.

47

Page 56: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 67: KS = 0,14 and STD = 5,0.

Figure 68: Chart visualizing the STD results.

Different variance values for Feature Rotation FunctionsDemonstrates how much the variance can affect the ability to find a good quaternion.

The only FRF used is the Normal:

48

Page 57: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 69: XYZ Variance = 0,001.

Figure 70: XYZ Variance = 0,5.

49

Page 58: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

Figure 71: XYZ Variance = 1,0.

Normal distribution close to edgeFigure 72.a and figure 72.b show the effects of using a normal distribution. A potential

problem is that the new objects gets placed inside the rock when the STD value increases.With a normal distribution it is not possible to create a gradient of trees fading away fromthe rock. This issue is mentioned in the future work section 11.2.

Figure 72.a Figure 72.b

Figure 72: Trees using the RaytraceDistance 8.4.2 FPF against the rock. 72.a: STD = 0,1. 72.b: STD = 0,5.

50

Page 59: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

8.8 Evaluation

It is hard to evaluate a method that can’t be compared with any equivalent existing method.This evaluation will be based upon opinions and measured data that has been discussedwith various different people.

When using example placements, the artist does not need to know about all the propertiesthat each stratum has. This is a big advantage even though it is good to know about themif small changes has to be made. From a workflow and artistic point of view, the tool isa bit unintuitive. The FFs contributes to a versatile tool and workflow. If an artist needsthe tool to take something new into account in the environment, the programmer can easilyadd such a FF. The different parts of the algorithm can each individually have a greatimpact on the outcome, hence it is important not to neglect any part of it. The STD value,the variance, the dart throwing, the SA cooling rate and the amount of candidate elementsgenerated will all have great impact on the final sample.

51

Page 60: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

9 Discussion

9.1 Method

The final method is producing good results and proves that these new methods for con-trolling how elements get generated works well. There are however some drawbacks inperformance visualized in figure 52.

As stated earlier, the implementation of FFs is a new solution for distributing objectsprocedurally. Both the placing and rotation methods were invented for this tool. Becauseof this a lot of effort was put into developing and testing these theories as how to implementand find solutions for them. This meant that other parts had to suffer, which should havehad a greater impact on the problem statement. It has been difficult to produce an intuitivetool with good workflow when so much was unknown about the method and solution fromthe beginning.

The solutions for the encountered problems were though up along the way and there wereproblems that were hard to foresee. An example would be when the SA and KS took toolong to produce good results, which lead to an implementation of dart throwing. But therewere also problems that could have been though about earlier. An example of this wouldbe that the rotations was not though about until after the FPF was proven working. Theamount of different implementations and the versatile approaches have contributed to timebeing consumed which in turn has led to little time for optimizations and fine tuning of thetool.

There were some problems with the covariance matrices in regard to the MPDF. If the userchanges the variance of a MPDF, the covariance matrix easily becomes non positive definite.This could however probably be solved by scaling the whole covariance matrix.

The idea from the beginning was to create a good foundation for the artists to hone. Alower SA cooling rate might produce better results, but the time increase is huge as seenin figure 62. Since the artist will still want to do changes afterwards, it might be better toincrease the cooling rate and still get an acceptable result.

Combinations of different FFs can produce results that differ from the individual FFs.FindEdges combined with SlopeAngle can for example help each other to find edges withflat tops, as seen in figure 54.

It is great with a tool that can cluster objects from a performance perspective since envi-ronment artists today cannot create a thick forest if they want great detail.

Finally the tool and functions have been implemented in C] which could affect the perfor-mance as well.

52

Page 61: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

9.2 Result

The increase in time when adding strata’s and when enlarging the distribution area are thebiggest issues. Seen in 8.7.1 there is an time increase in the order of 5 times per m2 betweenfigure 49 and 51.

10 Conclusions

Developing tools that are going to be used by someone else is tricky and the fact that theyprobably have a totally different technical background does not help. This is why it iscritical to get input and opinions from the end user.

The problem statement was as following: How can procedural methods be applied whencreating a useful procedural distribution tool which has the desired level of artistic control?How should a tool like that be designed?

The effort regarding workflow and getting artistic input was hard to maintain when so muchtime and energy had to be put into developing the new technique. Also since no reportswere followed, the entire method was though up along the way. This led to a lot of testingand research.

The level of artistic control is good. But for the artist to be able to do desired changes inthe tool; they need to understand quite well what is happening.

Because of the fact that the tool settings can be set and controlled in such a visual way andwithout the artist having to calibrate anything, example based procedural tools should beregarded as the future of procedural tools.

11 Future work

11.1 Optimization

The huge time increase when enlarging the area was mainly due to the global optimization.Instead by dividing the sampling area into smaller individual areas, a local optimizationcan be applied. Then by running the scattering algorithm locally instead of globally willsave a lot of computing power. The individual square areas should probably not be smallerthan the original example placements area.

11.2 Distribution fitting

By implementing distribution fitting instead of just using normal distributions, a few advan-tages could be gained. When fitting a distribution the exact distribution would be obtained.The tool would be able to mimic the example placements better. This would be able to

53

Page 62: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

solve the edge-problem with normal distributions mentioned and seen in 8.7.3. It would alsolead to the possibility that every distribution could be taken into account, hence the CVwould not be needed. A downside from a performance point of view is that all distributionsmight still not be needed to create a good final sample.

54

Page 63: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

References

[1] Ruben M. Smelik, Tim Tutenel, Rafael Bidarra and Bedrich Benes. A Survey on Pro-cedural Modeling for VirtualWorlds. 2014: COMPUTER GRAPHICS Forum http:

//graphics.tudelft.nl/~rafa/myPapers/bidarra.CGF.2014.pdf.

[2] Markus Lipp Direct Artist Control for Procedural Content Generation of Urban En-vironments. Oktober 2010: Dissertation http://www.cg.tuwien.ac.at/research/

publications/2010/lipp_markus-2010-DAC/lipp_markus-2010-DAC-Thesis.pdf.

[3] SAGE Choosing the Type of Probability Sampling. - http://www.sagepub.com/

upm-data/40803_5.pdf.

[4] Mick West Random Scattering: Creating Realistic Landscapes. 2008: Gamasutrahttp://www.gamasutra.com/view/feature/1648/random_scattering_creating_

.php?print=1.

[5] Herman Tulleken Poisson Disk Sampling. 2008: devmag http://devmag.org.za/2009/

05/03/poisson-disk-sampling/.

[6] Robert Bidson Fast Poisson Disk Sampling in Arbitrary Dimensions.2007: ACM SIGGRAPH https://www.cs.ubc.ca/~rbridson/docs/

bridson-siggraph07-poissondisk.pdf.

[7] Ares Lagae and Philip Dutre A Comparison of Methods for Generating Poisson DiskDistributions 2008: COMPUTER GRAPHICS forum http://people.cs.kuleuven.

be/~ares.lagae/publications/LD08CMGPD/LD08CMGPD.pdf.

[8] Oliver Deussen, Pat Hanrahan, Bernd Lintermann, Radomir Mech, Matt Pharr andPrzemyslaw Prusinkiewicz Realistic modeling and rendering of plant ecosystems 1998:SIGGRAPH http://www.graphics.stanford.edu/papers/ecosys/ecosys.pdf.

[9] Bedrich Benes, Michel Abdul Massih, Philip Jarvis, Daniel G. Aliaga and Carlos A.Vanegas Urban Ecosystem Design 2010: Purdue University https://www.cs.purdue.

edu/cgvlab/papers/aliaga/i3d11.pdf.

[10] Lee Jacobson Simulated Annealing 2013 http://www.theprojectspot.com/

tutorial-post/simulated-annealing-algorithm-for-beginners/6.

[11] NIST/SEMATECH e-Handbook of Statistical Methods 2012 http://www.itl.nist.

gov/div898/handbook/eda/section3/eda35g.htm.

[12] Tasos Giannakopoulos VoidInSpace 2013 http://www.voidinspace.com/2013/06/

procedural-generation-a-vegetation-scattering-tool-for-unity3d-part-i/.

[13] T Ijiri, R Mech, T Igarashi & G Miller An Example-based Procedural System for El-ement Arrangement. 2008: EUROGRAPHICS http://www-ui.is.s.u-tokyo.ac.jp/

~ijiri/publications/ijiri_EG08_ExampleBasedProceduralModeling.pdf.

55

Page 64: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

[14] Jay L. Devore & Kenneth N. Berk Modern Mathematical Statistics withApplications. 2007 http://books.google.se/books/about/Modern_Mathematical_

Statistics_with_Appl.html?id=3X7Qca6CcfkC&redir_esc=y.

56

Page 65: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

List of Figures

1 Frostbite logo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i2 Result teaser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Random scattering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Poisson disk sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Grid sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Random sampling with radius . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Density function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Density - Poisson disk and Perlin noise . . . . . . . . . . . . . . . . . . . . . 79 FF: Shortest distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810 FF: Distance to the closest trees . . . . . . . . . . . . . . . . . . . . . . . . 911 Grid sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012 Hill climbing: dncsite.files.wordpress.com . . . . . . . . . . . . . . . . . . . 1113 SA jump behavior: ieatbugsforbreakfast.wordpress.com . . . . . . . . . . . . 1214 KS test: http://en.wikipedia.org/wiki/KolmogorovSmirnov test . . . . . . . 1315 Square distribution area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1416 Mask distribution area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1517 Dependency between stratas . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818 GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1919 Workflow 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2020 Workflow 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2021 Workflow 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2122 Dart throwing example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2123 Dart throwing comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2224 ShortestDistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2325 ShortestDistance4Closest . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2426 RaytraceDistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2427 FPF: FindEdges Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2528 FPF: FindEdges Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2529 FPF: SlopeAngle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2630 FRF: Surface Normal Example . . . . . . . . . . . . . . . . . . . . . . . . . 2731 FRF: Surface Normal Result . . . . . . . . . . . . . . . . . . . . . . . . . . 2832 FRF: WorldUp Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2833 FRF: WorldUp Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2934 FRF: Surface Gradient Example . . . . . . . . . . . . . . . . . . . . . . . . 2935 FRF: Surface Gradient Result . . . . . . . . . . . . . . . . . . . . . . . . . . 3036 FRF: Direction Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3037 FRF: Direction Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3138 SA different samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3239 KS fit example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3340 KS high fit example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3341 KS low fit chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

57

Page 66: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

42 KS mid fit chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3443 KS high fit chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3544 Total probability plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3545 Freeze workflow 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3646 Freeze workflow 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3647 Freeze workflow 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3748 Freeze workflow 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3749 Result Forest 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3850 Result Forest 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3951 Result Forest 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3952 Result Forest Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4053 Result Palm 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4054 Result Palm 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4155 Result Desert 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4156 Result Desert 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4257 Dart throwing measurements 1 . . . . . . . . . . . . . . . . . . . . . . . . . 4358 Dart throwing measurements 2 . . . . . . . . . . . . . . . . . . . . . . . . . 4359 Dart throwing measurements chart . . . . . . . . . . . . . . . . . . . . . . . 4460 SA measurements 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4461 SA measurements 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4562 SA measurements chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4563 Candidate elements measurements chart . . . . . . . . . . . . . . . . . . . . 4664 STD comparison 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4665 STD comparison 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4766 STD comparison 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4767 STD comparison 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4868 STD chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4869 Variance comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4970 Variance comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4971 Variance comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5072 Normal distribution close to edge . . . . . . . . . . . . . . . . . . . . . . . . 50

58

Page 67: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

A Source code

A.1 Random sampling

//w = width

//h = height

public void Random ( int w, int h, int numOfSamples )

{

Random rnd = new Random ();

for(int i = 0; i < numOfSamples; i++)

{

var x = rnd.Next( 0, w );

var y = rnd.Next( 0, h );

AddSample( x, y );

}

}

Listing 1: C] code for generating random samples

A.2 Jitter grid sampling

//w = width

//h = height

//d = displacement

public void Random ( int w, int h, int d, int rows , int cols )

{

Random rnd = new Random ();

var xd = w/rows;

var yd = h/cols;

for(int y = 0; y < rows; y++)

{

for(int x = 0; x < cols; x++)

{

var dx = rnd.Next( -d, d );

var dy = rnd.Next( -d, d );

AddSample( x * xd + dx, y * yd + dy );

}

}

}

Listing 2: C] code for generating samples with a jitter grid

A.3 Dart throwing

59

Page 68: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

public int GeneralDartThrowing ( List <float > individualValues )

{

Random rnd = new Random ();

var sum = individualValues.Sum ();

var randValue = rnd.NextFloat ( sum );

float totValue = 0.0f;

int index = 0;

while (totValue < randValue && index < individualValues.Count - 1)

{

totValue += individualValues[index ];

if (totValue < randValue && index < individualValues.Count - 1)

{

index ++;

}

}

return index;

}

Listing 3: C] code for dart throwing algorithm

A.4 Simulated annealing

A.4.1 Flip function

public void SimulatedAnnealingFlipFunction ( List <SampleExtension >

pSamples , int pNumOfPlacements , float currTemp , float startTemp )

{

float tempValue = currTemp / startTemp;

int countTotalFlips = 0;

while (countTotalFlips == 0) // Will always flip at least once.

{

foreach (SampleExtension s in pSamples)

{

float rndFlipValue = FastRandom.Instance.NextFloat ();

if ( rndFlipValue < tempValue && s.m_inScene )

{

s.m_inScene = false;

int rndIndex = FastRandom.Instance.Next ( 0, pSamples.Count

);

while (pSamples[rndIndex ]. m_inScene)

{

rndIndex = FastRandom.Instance.Next ( 0, pSamples.Count );

60

Page 69: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

}

pSamples[rndIndex ]. m_inScene = true;

countTotalFlips ++;

}

}

}

}

Listing 4: C] code for the sample flip function

A.4.2 Acceptance funtion

public double AcceptanceProbability ( double currDistPoints , double

newDistPoints , double currTemp , double startTemp )

{

double tempValue = currTemp / startTemp; // Between 0.0 and 1.0

tempValue = Math.Pow ( tempValue , 2.0 );

// If the new solution is better , accept it

if (newDistPoints < currDistPoints)

{

return 1.0;

}

// If the new solution is worse , calculate an acceptance

probability

if (!( currDistPoints - newDistPoints < 0.0))

{

return 0.0;

}

return Math.Exp ( (currDistPoints - newDistPoints) / tempValue );

}

Listing 5: C] code for the acceptance function

A.5 Random unit quaternion

public static List <Quaternion > GenerateRandomUnitQuaternions (int

numOfGeneratedQuaternions)

{

Random rnd = new Random ();

List <Quaternion > quaternionList = new List <Quaternion > ();

var sphereRadius = 1.0;

int numOfQuaternions = numOfGeneratedQuaternions;

61

Page 70: Example Based Procedural Distribution Tool763228/FULLTEXT01.pdf · probability to obtain a certain position and rotation. For position dart throwing makes a rst weed out. Simulated

for (int i = 0; i < numOfQuaternions; i++)

{

var theta0 = 2.0 * Math.PI * rnd.NextDouble ();

var theta1 = Math.Acos ( 1.0 - 2.0 * rnd.NextDouble () );

var theta2 = 0.5 * (Math.PI * rnd.NextDouble () + Math.Acos (

rnd.NextDouble () );

var x0 = sphereRadius * Math.Sin ( theta0 ) * Math.Sin ( theta1

) * Math.Sin ( theta2 );

var x1 = sphereRadius * Math.Cos ( theta0 ) * Math.Sin ( theta1

) * Math.Sin ( theta2 );

var x2 = sphereRadius * Math.Cos ( theta1 ) * Math.Sin ( theta2

);

var x3 = sphereRadius * Math.Cos ( theta2 );

Quaternion randomQuaternion = new Quaternion ( (float)x0,

(float)x1, (float)x2, (float)x3 );

randomQuaternion.Normalize ();

quaternionList.Add ( randomQuaternion );

}

return quaternionList;

}

Listing 6: C] code for generating random quaternions. Formula from:http://mathproofs.blogspot.se/2005/05/uniformly-distributed-random-unit.html

62