• No results found

Generating 3D Avalanche Slabs with Voronoi Tessellation in Real-Time on the CPU

N/A
N/A
Protected

Academic year: 2021

Share "Generating 3D Avalanche Slabs with Voronoi Tessellation in Real-Time on the CPU"

Copied!
48
0
0

Loading.... (view fulltext now)

Full text

(1)

Bachelor of Science in Computer Science May 2020

Generating 3D Avalanche Slabs with

Voronoi Tessellation in Real-Time on

the CPU

Sebastian Tillgren

(2)

This thesis is submitted to the Faculty of Computing at Blekinge Institute of Technology in partial fulfilment of the requirements for the degree of Bachelor of Science in Computer Science. The thesis is equivalent to 10 weeks of full time studies.

The authors declare that they are the sole authors of this thesis and that they have not used any sources other than those listed in the bibliography and identified as references. They further declare that they have not submitted this thesis at any other institution to obtain a degree.

Contact Information: Author(s): Sebastian Tillgren E-mail: seti16@student.bth.se University advisor: PhD Prashant Goswami

Department of Computer Science

Faculty of Computing Internet : www.bth.se

(3)

Abstract

In computer graphics, when simulating fractured or cracked objects, most commonly physically based methods or hybrid solutions using physical and procedural methods are used to achieve the result. If only a static representation of a cracked surface, and not a simulation of an object cracking, is desired, these approaches of crack generation are not suitable. Non-physically based methods to generate the cracks or fractured objects has also been used where a fracture pattern is projected onto an object. In this thesis a novel method of generating 3D avalanche slabs directly from a 2D Voronoi pattern, in real-time, without using physically based methods or 3D procedural crack generation is presented. After the slabs are generated, they are placed on the surface of a terrain. To add a more realistic look, snow is added on the mountain around the avalanche slabs. Using this novel method of generating 3D avalanche slabs, separate 3D mesh objects are created directly from the Voronoi pattern, and no 3D model is needed initially to generate them from. The results show that this method can be used in real-time with limitations. With improvements suggested in this thesis, the presented method could be used to generate a large amount of slabs in a fairly large region, and software developers can benefit from using this method in their graphics renderer.

(4)
(5)

Acknowledgments

I would like to thank my supervisor PhD Prashant Goswami for supporting me and pushing me throughout this thesis work. I would also like to thank my family for supporting me and showing interest in my thesis work.

(6)
(7)

Contents

Abstract i

Acknowledgments iii

1 Introduction 1

1.1 Introduction . . . 1

1.2 Aim and objectives . . . 1

1.2.1 Aim . . . 1

1.2.2 Objectives . . . 1

1.3 Research Question . . . 2

2 Background 3 2.1 Background . . . 3

2.2 Key concepts and information . . . 3

2.2.1 Voronoi pattern . . . 3

2.2.2 Terrain and ray-marching . . . 3

2.2.3 Triangle length and API . . . 5

3 Related Work 7 3.1 Related work . . . 7

4 Method 9 4.1 Research method . . . 9

4.2 Flow of the process . . . 9

4.3 Selecting and creating the scene . . . 11

4.3.1 Terrain . . . 11

4.4 Creating avalanche slabs in a selected region . . . 11

4.4.1 Generating the Voronoi pattern . . . 11

4.4.2 Mapping the pattern . . . 11

4.4.3 Triangulating the polygons . . . 12

4.4.4 Placing the polygons on the terrain surface . . . 12

4.4.5 Adding volume to the polygons . . . 13

4.4.6 Scattering the slabs . . . 13

4.5 Creating snow . . . 14

4.5.1 Snow volume around the slab avalanche . . . 14

4.5.2 Snow shading . . . 15

4.6 Dividing generation process over several frames . . . 15

(8)

5 Results and Analysis 17 5.1 Results and analysis . . . 17 5.1.1 Time duration of complete generation process test . . . 17 5.1.2 Time duration comparison test between the different parts of

the generation process . . . 19 5.1.3 Observation of the frames per second . . . 20

6 Discussion 27

6.1 Discussion . . . 27

7 Conclusions and Future Work 29

(9)

Chapter 1

Introduction

1.1

Introduction

In this thesis a novel method of generating 3D avalanche slabs in real-time, on the central processing unit (CPU) is presented. Instead of fracturing already existing objects, the process of generating three-dimensional (3D) avalanche slabs is simpli-fied. By using two-dimensional (2D) Voronoi tessellation, extending the 2D polygons created from the Voronoi pattern to 3D, placing them on the terrain, and scatter-ing them, the same results as with 3D procedural crack generation can be achieved. Using this method of generating 3D avalanche slabs, no 3D model is needed initially to generate the slabs from, thus avoiding 3D tessellation and 3D procedural crack generation completely. With this method the user is given the control to choose where the slab avalanche will be generated, the size of the region where the slabs are generated, and the quantity of slabs to be generated. In this thesis the performance and scalability of using this novel method is tested and analyzed.Depending on the performance of this method, software developers can benefit from using this method in their graphics renderer. If this turns out to be an efficient way of generating 3D slabs (that has a Voronoi-looking pattern), it could help game developers to further increase their games‘ performance when generating these, or similar looking objects, and to implement such a technique in their engine.

1.2

Aim and objectives

1.2.1

Aim

The aim of this thesis is to test and evaluate the performance when creating three-dimensional avalanche slabs on the CPU by performing two-three-dimensional Voronoi tessellation and extending this to three dimensions. The user should be able to select the area of snow that is affected.

1.2.2

Objectives

• Capture geometry and textures of a given (ray-marched) scene as a textured mesh.

• A possibility to generate a 2D Voronoi tessellation pattern on demand. The user should be able to select an area where the slabs will appear and use a

(10)

2 Chapter 1. Introduction

slider to set the coarseness of the slabs.

• Map the generated Voronoi pattern in the scene, in 2D, to the region that the user selected, and extend to 3D slabs by adding volume.

• Measure and evaluate the performance.

1.3

Research Question

Research Question (RQ): Can avalanche slabs generated with Voronoi tessellation in

(11)

Chapter 2

Background

2.1

Background

In computer graphics, when simulating fractured or cracked objects, most commonly physically based methods or hybrid solutions using physical and procedural methods are used to achieve the result [11] [19] [10]. Some simulate the cracking of objects [12] [9], and others simulate the destruction or fracturing of objects [18] [16]. If only a static representation of a cracked surface, and not a simulation of an object cracking, is desired, these approaches of crack generation are not suitable. Instead, a non-physically based method could be used to generate the cracks or fractured objects. Some non-physically based approaches make use of user defined crack patterns [15], others produce images of fractured surfaces [17], and some use the Voronoi pattern, where it is projected onto polygonal meshes [20]. So far, no scientific work has been done on generating 3D avalanche slabs in general.

2.2

Key concepts and information

2.2.1

Voronoi pattern

The Voronoi pattern is a pattern that can be found in nature. For example, it can be found on a giraffe‘s fur, on dragonfly wings, honeycombs [23] or dried mud. The Voronoi pattern is also fitting to represent avalanche slabs, hence the reason why this pattern is used in this thesis to create said slabs. An image of a Voronoi pattern is presented in figure 2.1. Every colored area is called a cell and will be referenced as a polygon in this thesis because it is the actual polygon that is being worked on. Every cell has a site, which are represented as dots inside the cells in the image. The image was produced and taken by Viktor Eklund and Victor Olsson [7]. On Wolfram Web Resources, Eric Weisstein explains the Voronoi tessellation algorithm as a “... partitioning of a plane with n points into convex polygons such that each polygon contains exactly one generating point and every point in a given polygon is closer to its generating point than to any other” [25], where the generating point is the polygon’s site.

2.2.2

Terrain and ray-marching

The terrain mesh used in this project contains 512 X 512 vertices which corresponds to 522 242 triangles that are being drawn every frame. This affects the frames per

(12)

4 Chapter 2. Background

Figure 2.1: Image of a Voronoi pattern where every colored area is a cell, and every

dot inside those cells are their respective sites.

second to some degree and should be kept in mind when interpreting the results of this thesis.

(13)

2.2. Key concepts and information 5

Figure 2.2: An example of ray marching where the camera is the ray origin, the blue

line is the ray computed from the origin, the odd looking shape to the right is an object in the scene, the brown circles are the distance to the closest object in the scene from the current point on the ray, and the red points are that distance along the ray. The point of intersection is when the distance to the closest object in the scene is very small.

2.2.3

Triangle length and API

When describing a region dimension in this thesis, one of the edges of a triangle is referred to as a triangle length. This length may vary depending on what the triangle looks like but the computations in this thesis does not depend on the size or length of any particular triangle.

(14)
(15)

Chapter 3

Related Work

3.1

Related work

Voronoi tessellation has been used in a number of different areas, for instance, A. Elyiv and colleagues use it in astrophysics to identify isolated galaxies, pairs and triplets [8]. Biology is another area Voronoi tessellation is used in; Daniel Sánchez-Gutiérrez and colleagues describe how “Voronoi diagrams are able to predict the diverse polygon distributions of any natural packed tissues“ [24]. More recently the Voronoi pattern is used in urban planning in the article “Microscopic Simulation of Cruising for Parking of Trucks as a Measure to Manage Freight Loading Zone”. Here, C. Lopez and colleagues evaluated the freight loading zone system of Lyon, France, using Voronoi diagrams [14]. Another example of the use of the Voronoi pattern, in computer graphics, is to animate lava flows, which is described by D. Stora and colleagues in the article “Animating Lava Flows” [22]. In this thesis, how-ever, the Voronoi tessellation is used to represent avalanche slabs. There are different algorithms that generate the Voronoi pattern. In the article “CPU Performance Eval-uation for 2D Voronoi Tessellation“ [6] V. Eklund and V. Olsson compares the Boyer watson and Fortune’s algorithm and concludes that Fortune’s algorithm is the most efficient algorithm for generating 2D Voronoi patterns of the two. Therefore, this al-gorithm will be used in this thesis. In computer graphics, when simulating fractured or cracked objects, most commonly physically based methods or hybrid solutions using physical and procedural methods are used to achieve the result. For exam-ple, in the article “Generating surface crack patterns“ Hayley N. Iben and James F. O‘Brien take the approach of a hybrid solution that uses physically based methods and heuristic methods to generate and simulate crack patterns [12]. Similarly S. Gobron and N. Chiba propose a semi-physical approach to simulate the cracking of different materials [9]. In 2001, M. Muller and colleagues presented a hybrid method for simulation deformation and fracture of materials, like clay and cinder blocks, in real-time [19]. More recently, in 2013, Muller and colleagues proposed another, physical method to “simulate the dynamic destruction of large and complex objects in real-time” with volumetric approximate convex decompositions computed based on the Voronoi decomposition of space [18]. K. Hirota and colleagues used a physical model to generate cracks and simulate drying mud [11]. Later, in 2000, Hirota and colleagues describe a physically based method for simulating the process of cracking [10]. O. Mazarak and colleagues explores the physical modelling of a blast wave impact on objects [16]. There are, however, non-physical approaches that make use of, for example, user defined crack patterns implemented as graphs to generate the

(16)

8 Chapter 3. Related Work

(17)

Chapter 4

Method

4.1

Research method

In this thesis the appearance of the avalanche slabs is not the main focus. Instead, this thesis focuses on the performance side of generating avalanche slabs in real-time. Therefore a quantitative approach is most suitable. The research method used in this thesis is formal experiment. In this experiment the performance and scalability of generating avalanche slabs in 3D using Voronoi tessellation is measured. The performance is measured by observing the frames per second. If we cannot reach 30 frames per second in all frames during the generation of the slabs it is not considered to be performing in real time [3].

4.2

Flow of the process

The flow of the process of the project consists of three major components:

1. Create a scene using ray-marching and obtain the mesh.

2. Select an area in the mesh and generate snow.

3. Generate slabs in the selected region.

(18)

10 Chapter 4. Method

(19)

4.3. Selecting and creating the scene 11

4.3

Selecting and creating the scene

4.3.1

Terrain

When generating the avalanche slabs a terrain mesh is needed to place the slabs on. A ray marched terrain by Inigo Quilez is fetched from Shadertoy [13]. Using this code with some additions, a terrain is ray marched from above. The world coordinates in a given space (determined by the minimum and maximum world coordinates) of the terrain are saved in a shader storage buffer object (SSBO). The color values in the terrain for the corresponding world space are then written to a texture in a framebuffer object (FBO) in a higher resolution (for greater detail) than the SSBO. The position values captured in the SSBO are then used to create a triangulated mesh and the texture containing the color values is used to sample from and texture the terrain mesh.

4.4

Creating avalanche slabs in a selected region

4.4.1

Generating the Voronoi pattern

The Voronoi pattern is generated using Dmytro Kotsur’s code [4] with some additions by Victor Olsson and Viktor Eklund [5]. The code generates edges that consists of two of the exact same points at times, so those has to be considered as “false edges” and thereby excluded (see algorithm 1). Edges at the borders around the Voronoi pattern is not generated by the acquired code, therefore these has to be added manually afterwards.

Algorithm 1 Simple check if an edge is a “fake edge”

1: if edge.V ertexA= edge.V ertexB then

2: f akeEdge← true

3: end if

4.4.2

Mapping the pattern

(20)

12 Chapter 4. Method

How the y-value of the vertices is calculated is explained under section 4.4.4 “Placing the polygons on the terrain surface”.

4.4.3

Triangulating the polygons

From the code that generates the Voronoi pattern only the edges of the polygons are generated. This means that the polygons would have to be drawn with lines. If we want the polygons to have volume (which is the case for this thesis) the poly-gons would have to be divided in to triangles, i.e triangulated. A polygon can be triangulated in a number of different ways, however, in this project there is an easy solution. Assuming that a Voronoi cell’s site is inside the polygon, and that the position coordinates of this site is accessible, triangles can be created by drawing lines from every vertex in the polygon to this site (see figure 4.2).

Figure 4.2: Polygon triangulated by adding edges from every vertex to the polygon’s

site (the point in the middle). Note that the site is not always located in the center of the polygon but always inside it.

4.4.4

Placing the polygons on the terrain surface

(21)

4.4. Creating avalanche slabs in a selected region 13 ray intersects the terrain and the vertex is assigned this position. If the point is not inside the triangle, the search continues to the next triangle in the region until the triangle where the ray intersects the terrain is found. If one would want to increase the performance further, there is a faster algorithm for deciding if a point is inside a triangle. This algorithm uses barycentric coordinates [2]. The reason why this is not implemented in this project is because it was decided to perform ray/triangle intersection tests late in the project and time only allowed for the easiest solution to be used.

4.4.5

Adding volume to the polygons

To make the top part of the avalanche slab, one vertex is added, for each vertex in the polygon, a number of units above the vertex that is placed on the terrain. These newly added vertices are connected in the same way as the original polygon vertices as described in section 4.4.3. Now, a bottom and a top part of the avalanche slab exist, and the only thing left to create a 3D slab is to connect the edges between the top and bottom polygons. To achieve this, triangles are created between the top and bottom polygon edge-vertices.

Figure 4.3: New vertices are added directly above the vertices on the terrain.

4.4.6

Scattering the slabs

(22)

14 Chapter 4. Method

Figure 4.4: Triangles are created between the polygon’s border-vertices on the terrain

and the newly created polygon’s border-vertices to make a 3D slab out of the two polygons.

4.5

Creating snow

4.5.1

Snow volume around the slab avalanche

(23)

4.6. Dividing generation process over several frames 15

Figure 4.5: Avalanche slabs appearing out of nowhere on the mountain.

Figure 4.6: Avalanche slabs appearing in the snow, looking more realistic.

4.5.2

Snow shading

The snow shading is inspired by the snow shading in a ray marched example code on Shadertoy [26] where two shades of white are interpolated using OpenGL Shading Language’s (GLSL) mix-function [1]. GLSL:s mix-function interpolates two vectors using a floating point value to weight between them [1]. Since the GLSL language is not available on the CPU this function is replicated as our own function. The function looks like this:

f(x, y, a) = x * (1 - a) + y * a

where x and y are vectors (three-component vectors in this case) and a is a value that weights between these vectors. In the Shadertoy example T. Zirr and A. Kaplanyan use the ray y-direction (of their ray marching ray) and the dot product between the normal and the direction to the light source to decide the a value [26]. In this project this is simplified to the dot product between the normal of the surface and the direction to the light source clamped to [0, 1]. The direction to the light source is set to the same direction as the light direction in the ray marched example that is used to generate the terrain (see section 4.3.1) so that the lighting would fit in to the scene.

4.6

Dividing generation process over several frames

A requirement for real-time rendering is that the program should run with more than 30 frames per second [3]. Therefore, the process of generating the avalanche slabs has to be divided over several frames as some parts of the process takes more than four seconds to complete, which would result in the program freezing while that frame is being processed. The frames per second would be one fourth of a second per second which is far from 30 frames per second. The process is divided as follows:

1. Adding snow(done in one frame).

(24)

16 Chapter 4. Method

3. Generate a Voronoi pattern, determine what edges belongs to what polygon in the pattern, as well as adding edges to the polygons that are touching the borders of the pattern.

4. Scattering the slabs, mapping them to the correct location in world space, adding volume to the slabs and placing them on the surface (done for one slab per frame).

The process could be divided even further and as a result the frames per second would be even higher. However, the complete generation process would be slower.

4.7

Testing

(25)

Chapter 5

Results and Analysis

5.1

Results and analysis

5.1.1

Time duration of complete generation process test

The first test measured the time duration to complete the full avalanche slab gen-eration process in three different region sizes; five by five, ten by ten and 20 by 20 triangle lengths. The test is performed with 20, 50, 100, 250, 500 and 1000 slabs for each region to measure the scalability of the method. The minimum of 20 generated slabs is decided due to the fact that the generation of any number of slabs below this number would cause the slabs to intersect the terrain. This is because the slabs become larger when decreasing the amount of slabs. The time duration is measured five times for each part of the test and the average of these values is computed. The result of this experiment is shown in figure 5.1. When the region is increased, the size of the slabs also increase in size to fit the region. When the number of slabs increase the slabs decrease in size so that all slabs fit in the region and vice versa. A com-parison image between two different region sizes and number of slabs for reference is provided in figure 5.2 and 5.3.

The time duration of the generation process does not differ significantly between the different region sizes when the number of slabs are 100 and below, as can be seen in figure 5.1. The average time duration of the complete generation process for all region sizes is approximately between 0,2 and 2 seconds when generating less than 100 slabs. When closing 250 number of slabs however, the 20 by 20 region is starting to show a more significant difference in time duration from the other two region sizes. The 20 by 20 region’s time duration continues to grow exponentially away from the other two region sizes’ time duration as the number of slabs increases. At 250 number of slabs the 20 by 20 region takes more than a second longer to complete than the other two, smaller, regions. At 500 number of slabs the five by five and ten by ten region also starts to show a significant difference in time duration. At this point the five by five and ten by ten region differs by almost one second ( 0,9 s), the 20 by 20 and ten by ten region differs with approximately 2,5 seconds, and the 20 by 20 and five by five region differs with around 3,5 seconds. At 1000 number of slabs the ten by ten and five by five region differs with approximately two seconds, the ten by ten and 20 by 20 region differs with approximately five seconds, and the five by five and 20 by 20 region differs with approximately seven seconds.

The results in figure 5.1 can be interpreted as such:

(26)

18 Chapter 5. Results and Analysis

slab generation process linearly. Increasing the size of the region, where the slabs are being generated, increases the time duration of the avalanche slab generation process exponentially.

Figure 5.1: Average time duration, in seconds, to complete the avalanche slab

gen-eration process from start to finish with different region sizes and number of slabs in that region.

Figure 5.2: 250 slabs in a 10 by 10

region

Figure 5.3: 1000 slabs in a 20 by 20

(27)

5.1. Results and analysis 19

5.1.2

Time duration comparison test between the different

parts of the generation process

For further optimization of the program it is interesting to know what part of the generation process is a bottleneck. Therefore, the time duration of each part of the generation process is measured individually. The generation process is divided as described in chapter 4, section 4.6. For the fourth part of the process, which will be referenced as the ray/triangle intersection part for easier readability, we know that the first slabs in the region will be completed faster since these slabs are intersecting some of the first triangles in the list that is being looped. Hence, the loop breaks early. With this in mind, the average of the time duration of the first five generated slabs are computed, as well as the average time duration of the last five generated slabs to capture the variance of the time duration between the different slabs. These measurements are performed on a 20 by 20 triangle lengths region with 250 number of slabs generated. The results are shown in figure 5.4. From the results it can be seen that the ray/triangle intersection part becomes a bottleneck, taking just over 18 milliseconds to complete, when the ray/triangle intersection test is performed on the last five generated slabs in the region. When the ray/triangle intersection test is performed on the first five slabs however, the Voronoi generation and polygon separation part of the process becomes the bottleneck instead.

Figure 5.4: Comparison of the time duration, in milliseconds, between every part of

(28)

20 Chapter 5. Results and Analysis

5.1.3

Observation of the frames per second

Given the research question “Can avalanche slabs generated with Voronoi tessellation in 3D be performed in real-time using a novel method?” it is fundamental to know the current frames per second (fps) each frame of the generation process to determine if this method can be used in real-time. Usually it is considered to be real-time if the fps does not go below 30. The current fps is observed three separate times per region size, and the average of these is computed, for the first three parts of the generation process. The snow region is not changed during these tests and the process of generating snow averaged around 73 fps. The results of the other two fps observations are shown in figure 5.5 and 5.6. Furthermore, the fps is observed each frame of the ray/triangle intersection part of the process. Each frame processed one slab. From these observations the highest and lowest current fps is particularly interesting to measure the performance variance as well as determining whether this process can be performed in real-time (with over 30 fps). The result of this test is shown in figure 5.7. A last test is performed to compare the performance between a very low number of slabs and a very high number of slabs. The results of these tests are shown in figures 5.8, 5.9 and 5.10.

From the result shown in figure 5.5 it can be seen that even when the size of the region is 20 by 20 triangle lengths the fps average is 320 fps when calculating the minimum and maximum coordinates of the region and computing the normals of each triangle in the region. This is well above the required 30 fps for real-time rendering and the region could therefore be increased further (if desired) and yet fulfill the requirement of 30 fps (for this part of the process).

The result in figure 5.6 shows that when generating a Voronoi pattern with 20 polygons and separating them in to different meshes, the fps is averaging 1009, with 50 polygons the fps averages 484, with 100 polygons it averages 276 fps, 250 polygons averages 77 fps, 500 polygons averages 26 fps, and 1000 polygons averages 8 fps. This means that up to 250 generated polygons are definitely above the threshold of 30 fps, but when we are closing 500 polygons the fps tend to fall short of 30 fps and thus, would not be recommended to be used in real-time rendering. By dividing this process further over more frames however, 30 fps or more might be achievable for this part of the generation process with over 500 slabs as well.

The result in figure 5.7 shows that the highest fps observed in this part of the process does not depend on either the size of the region or the number of slabs being generated. The lowest observed fps however, greatly depends on both the size of the region and the number of slabs being generated. In the 20 by 20 triangle lengths region the lowest observed fps goes below the required threshold of 30 fps when the number of slabs are 1000, and is just above 30 fps when the number of slabs are 500, 250, 100 and 50.

(29)

5.1. Results and analysis 21

Figure 5.5: Average frames per second when calculating the minimum and

maxi-mum coordinates of the given region, and computing all triangle normals in the given region.

0.9 and 1.3, which is low enough to not be visible in this diagram. During this part of the process, the relation between the fps and the region dimension appears to be random from looking at the result in figure 5.10. This is most likely due to the bugs that arise when generating such low number of slabs. The figure also shows that the quantity of slabs affects the fps. When generating only five slabs in any region dimension, the visual aesthetics are not impressive. The slabs are large and intersects the terrain, and in the part where the edges are created bugs arise. When generating 3000 slabs, bugs in the Voronoi pattern generation arise and it looks like a spiderweb, which probably affects the result and hence, the result of this test is considered invalid.

(30)

22 Chapter 5. Results and Analysis

Figure 5.6: Average frames per second when generating the Voronoi pattern and

separating the polygons of the pattern in to different meshes. * The fps goes higher but has been cut out at 600 so that the lower fps can be shown better.

(31)

5.1. Results and analysis 23

Figure 5.7: Highest and lowest observed frames per second when performing

(32)

24 Chapter 5. Results and Analysis

Figure 5.8: Lowest observed frames per second when performing ray/triangle

inter-section tests, adding volume to a slab, offsetting the slabs, and mapping them to the correct location in world space. One slab per frame is processed and the ray/triangle test is performed for every vertex in a slab every frame. Here, a very low quantity of slabs are compared to a very high quantity of slabs in different region sizes.

Figure 5.9: Highest observed frames per second when performing ray/triangle

(33)

5.1. Results and analysis 25

Figure 5.10: Frames per second comparison between a very low number of slabs and a

(34)
(35)

Chapter 6

Discussion

6.1

Discussion

In section 5.1.1 it is shown that the time duration of the complete generation process increases exponentially when increasing the region size. The reason it increases exponentially is because the program is looping through every triangle’s normal in the given region for every vertex in every slab until the triangles that are being intersected by the ray from each vertex is found. In section 5.1.1 it is also concluded that the time duration of the avalanche slab generation process increases linearly when increasing the number of slabs that are being generated. This is expected as the average time for completing the process of one slab in a given region should not vary much since the only thing that changes is the size of the slab. More slabs are processed but the average time per processed slab is about the same depending on where the slab is located (a slab at the end of the region will on average be processed slower than a slab in the start of the region because the triangles it is intersecting will be found later as shown in figure 5.4).

In section 5.1.2 it is shown that when generating 250 avalanche slabs in a region of 20 by 20 triangle lengths, the ray/triangle intersection part of the process becomes a bottleneck when the last five slabs in the region are being processed. It is also established that, when processing the first five slabs of the region, the Voronoi gen-eration and polygon separation part of the process becomes the bottleneck instead. The reason, yet again, is because it takes longer for the program to find the triangles that the slabs in the last part of the region are intersecting than finding the triangles the slabs in the first part of the region are intersecting. A suggestion of improvement for this part is to have the loop start further in to the region as more slabs are being placed on the surface. However, when the slabs are large they will intersect triangles further in to the region, so where to start the search from would have to take the size of the slabs in to account as well. Another suggestion would be to, about half-way through the processed slabs, start the search from the back instead of the front. The slabs processed later are more likely to be intersecting a triangle at the end of the region than in the first part of the region and thus, be found faster if the search is performed from the back instead of the front.

Which part of the process that is the bottleneck is, in fact, mostly interesting when the fps falls short of 30, as this is essentially when the program needs to improve to achieve real-time requirements. In the tests performed in this thesis the fps falls short of 30 in two parts of the generation process; the generation of the Voronoi generation part (see figure 5.6 ), and the ray/triangle intersection part (see figure 5.7). In figure

(36)

28 Chapter 6. Discussion

5.6 it can be seen that the fps averages under 30 when the number of slabs to be generated are 500 or more (independent of region dimension), and in figure 5.7 it is shown that, for the ray/triangle intersection part of the process, the lowest fps is under 30 only when generating 1000 slabs in a 20 by 20 region (though more tests are needed to ensure that the fps does not fall short of 30 when generating 100 and 250 slabs). This means that in 5 out of the 6 different combinations of conditions (region dimensions and number of slabs) where the fps falls short of 30 fps, the Voronoi generation part is the part of the generation process that prevents the process from being done in real-time (i.e over 30 fps). In one out of the 6 combinations of conditions where the fps falls short of 30 fps, both the Voronoi generation part and the ray/triangle intersection part are the parts that prevents the program from being run with over 30 fps. This means that, first and foremost, the Voronoi generation part needs to be improved, specifically the part when generating the polygons. In this part of the generation process all edges that are generated from the Voronoi pattern are looped, and every edge is assigned to one or two polygons. In section 4.4.1 it is explained that the code used for the Voronoi pattern generation produced “false edges”. When generating 1000 Voronoi cells approximately 100 fake edges (out of approximately 3000 edges) are produced, which only affects the performance slightly and hence, this cannot be the cause of the bottleneck. Furthermore, after communication with one of the authors of the modified Voronoi tessellation code, there might be an updated version of the code where these “fake edges”, along with another bug caused by “floating point errors”, does not exist. Since the “fake edges” are not the cause of the bottleneck, the evidence points to that the entire process of determining what edges belongs to what polygon is the part that is most time consuming, most likely because at, for instance, 1000 generated slabs approximately 3000 edges are produced and needs to be looped when creating the polygons. A suggestion of improvement for this part of the process could be to run this loop over several frames instead of in one single frame. On one hand, the overall process of generating the avalanche slabs will take slightly longer. On the other hand, the fps will most likely exceed 30 each frame and thus, be eligible for real-time rendering, which is the aim and purpose of this thesis. Another suggestion of improvement to this part of the process is to use a faster algorithm for determining if a point is inside a triangle. Using barycentric coordinates is a better alternative than the current solution. Every slab that has already been processed is drawn every frame during the processing of the other slabs. Avoiding to draw the slabs during the process and, instead, only draw the slabs after all slabs have been processed would also improve the fps during the later part of the process. However, the slabs would not be seen showing up one by one in real-time, but rather, all slabs would be drawn at once.

(37)

Chapter 7

Conclusions and Future Work

7.1

Conclusions

In this thesis a novel method of generating 3D avalanche slabs directly from a 2D Voronoi pattern, in real-time, without using physically based methods or 3D proce-dural crack generation is presented. After the slabs are generated, they are placed on the surface of a terrain. To add a more realistic look, snow is added on the mountain around the avalanche slabs. The research question in this thesis is:

“ Can avalanche slabs generated with Voronoi tessellation in 3D be performed in real-time using a novel method?”

The short answer to this question is yes. 3D avalanche slabs can be generated using 2D Voronoi tessellation in real-time using the novel method described in chapter 4, though in a limited region with a limited number of slabs. 250 avalanche slabs, in a region of 20 by 20 triangle lengths (800 triangles) is the maximum number of slabs and region size that could achieve real-time performance requirements in this thesis’ experiments. It is also possible to generate a larger quantity of slabs in real-time in smaller regions. It is possible, for example, to generate 1000 avalanche slabs in a region of 10 by 10 triangle lengths (200 triangles). After implementing improvements suggested in chapter 6 , section 6.1, larger number of slabs in bigger region sizes are also likely to pass real-time requirements using this method.

7.2

Future work

Future work to be done is, first of all, to improve the parts of the code that are limiting the scalability of the slab generation in real-time as suggested in chapter 6 , section 6.1. After we have a program that can generate more than 1000 avalanche slabs over a fairly large region of triangles in real-time, other additions could be added to the program. For instance, a goal of this thesis was that the user should be available to change region size and the number of slabs in real-time using, for example, sliders and mouse clicks. Due to the limitation of time, this was not possible to implement during this thesis work. Another addition could be to add animations to the slabs where they are sliding down the mountain with a cloud of snow following them, and investigate if this could be done in real-time. Visual improvements can also be implemented to achieve a more realistic look.

(38)
(39)

References

[1] Opengl reference pages. https://www.khronos.org/registry/ OpenGL-Refpages/gl4/html/mix.xhtml.

[2] Same side technique. https://blackpawn.com/texts/pointinpoly/default. html.

[3] Wikipedia contributors. Real-time computer graphics. https://en.wikipedia. org/w/index.php?title=Real-time_computer_graphics&oldid=953556729. [4] Kotsur Dmytro. Fortunealgo. https://github.com/dkotsur/FortuneAlgo. [5] V. Eklund and V. Olsson. 2d-voronoi-fracture. https://github.com/Vekzzor/

2D-Voronoi-Fracture/tree/master.

[6] V. Eklund and V. Olsson. Cpu performance evaluation for 2d voronoi tessella-tion. DiVA, 2019.

[7] V. Eklund, V. Olsson. 2d voronoi fracture. https://raw.githubusercontent. com/Vekzzor/2D-Voronoi-Fracture/master/VoronoiExampleAA.png.

[8] A. Elyiv, O. Melnyk, and Vavilova I. High-order 3d voronoi tessellation for identifying isolated galaxies, pairs and triplets. Monthly Notices of the Royal

Astronomical Society, 394(3):1409–1418, 2009.

[9] S. Gobron and N. Chiba. Crack pattern simulation based on 3d surface cellular automata. The Visual Computer, 17:287–309, 2001.

[10] K. Hirota, Y. Tanoue, and T. Kaneko. Simulation of three-dimensional cracks.

The Visual Computer, 16:371–378, 2000.

[11] K. Hirota, T. Ysuyuki, and T. Kaneko. Generation of crack patterns with a physical model. The Visual Computer, 14:126–137, 1998.

[12] N. H. Iben and O‘Brien F. J. Generating surface crack patterns. Graphical

Models, 71:198–208, 2009.

[13] Quilez Inigo. Terrain tubes. https://www.shadertoy.com/view/4sjXzG. [14] C. Lopez, L. Zhao, C, S. Magniol, N. Chiabaut, and L. Leclercq. Microscopic

simulation of cruising for parking of trucks as a measure to manage freight loading zone. Sustainability, 11, 2019.

(40)

32 References

[15] A. Martinet, E. Galin, Desbenoit B., and Akkouche S. Procedural modeling of cracks and fractures. Proceedings Shape Modeling Applications, pages 346–349, 2004.

[16] Oleg Mazarak, Claude Martins, and John Amanatides. Animating exploding objects. 12 2000.

[17] D. Mould. Image-guided fracture. GI‘05: Proceedings of Graphics Interface

2005, pages 219–226, 2005.

[18] Matthias Müller, Nuttapong Chentanez, and Tae-Yong Kim. Real time dynamic fracture with volumetric approximate convex decompositions. ACM Trans. Graph., 32(4), July 2013.

[19] Matthias Müller, Leonard Mcmillan, Julie Dorsey, and Robert Jagnow. Real-time simulation of deformation and fracture of stiff materials. pages 113–124, 2001.

[20] S. Raghavachary. Fracture generation on polygonal meshes using voronoi poly-gons. Siggraph ‘02: conference abstracts and applications, page 187, 2002.

[21] Scratchapixel. Ray-plane intersection. https://

www.scratchapixel.com/lessons/3d-basic-rendering/ minimal-ray-tracer-rendering-simple-shapes/

ray-plane-and-ray-disk-intersection.

[22] Dan Stora, Pierre-Olivier Agliati, Marie-Paule Cani, Fabrice Neyret, and Jean-Dominique Gascuel. Animating lava flows. In Graphics Interface, pages 203–210, Jun 1999.

[23] D‘Agostino Susan. Voronoi tessellations and scutoids are every-where. https://blogs.scientificamerican.com/observations/ voronoi-tessellations-and-scutoids-are-everywhere/.

[24] D. Sánches-Gutiérrez, M. Tozluoglu, D. J. Barry, A. Pascual, Y. Mao, and M. L. Escudero. Fundamental physical cellular constraints drive self-organization of tissues. EMBO J, 35:77–88, 2016.

[25] Eric W. Weisstein. Voronoi diagram. From MathWorld–A Wolfram Web Re-source, https://mathworld.wolfram.com/VoronoiDiagram.html.

(41)

Chapter 8

Source Code

For the source code, contact the author via e-mail: seti16@student.bth.se

(42)
(43)

Appendix A

Supplemental Information

Figure A.1: 50 avalanche slabs in a 5 by 5 triangle lengths region.

(44)

36 Appendix A. Supplemental Information

(45)

37

(46)

38 Appendix A. Supplemental Information

(47)
(48)

References

Related documents

Sufficient understanding is frequently signalled by uni- modal vocal-verbal yeah, okay, m, ah, and yes, unimodal gestural nods, nod, smile, up-nod, and up-nods, and

According to Gustafson and Stille (2005) and Kobayashi and Stille (2008) “Real Time Grouting Control Method” is a theory to formulize grouting in order to predict the penetration

Therefore, in line with the recognized knowledge gaps concerning e-commerce in the context of business and operations strategy in general and service operations management

The score for active coping consists of six sub-scores (diverting attention, reinterpreting pain sensations, coping self- statements, ignoring pain sensations, increasing

There was consistently no obvious beneficial effect of anticoa- gulation treatment on cerebral infarction and stroke in men and women younger than 65 years and one additional

With methods based on ray tracing the sound waves are traced from the audio source to the listener in the virtual environment, where the environment is based on a scene consisting

[r]

Using µ-analysis to verify linear stability criteria and find worst case static parameter combinations can be done without great effort. The theory involved is not too hard to