• No results found

Real-time View-dependent Triangulation of Infinite Ray Cast Terrain

N/A
N/A
Protected

Academic year: 2022

Share "Real-time View-dependent Triangulation of Infinite Ray Cast Terrain"

Copied!
76
0
0

Loading.... (view fulltext now)

Full text

(1)

Master of Science in Engineering: Game and Software Engineering June 2019

Real-time View-dependent

Triangulation of Infinite Ray Cast Terrain

Fritjof Cavallin Timmie Pettersson

Faculty of Computing, Blekinge Institute of Technology, 371 79 Karlskrona, Sweden

(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 Master of Science in Engineering: Game and Software Engineering. The thesis is equivalent to 20 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):

Fritjof Cavallin

E-mail: frcb14@student.bth.se Timmie Pettersson

E-mail: tipa13@student.bth.se

University advisor:

Dr. Prashant Goswami, Assistant Professor Department of DIDA

Faculty of Computing Internet : www.bth.se

Blekinge Institute of Technology Phone : +46 455 38 50 00

SE–371 79 Karlskrona, Sweden Fax : +46 455 38 50 57

(3)

Abstract

Background. Ray marching is a technique that can be used to render images of infinite terrains defined by a height field by sampling consecutive points along a ray until the terrain surface is intersected. However, this technique can be expensive, and does not generate a mesh representation, which may be useful in certain use cases.

Objectives. The aim of the thesis is to implement an algorithm for view-dependent triangulation of infinite terrains in real-time without making use of any preprocessed data, and compare the performance and visual quality of the implementation with that of a ray marched solution.

Methods. Performance metrics for both implementations are gathered and com- pared. Rendered images from both methods are compared using an image quality assessment algorithm.

Results. In all tests performed, the proposed method performs better in terms of frame rate than a ray marched version. The visual similarity between the two meth- ods highly depend on the quality setting of the triangulation.

Conclusions. The proposed method can perform better than a ray marched version, but is more reliant on CPU processing, and can suffer from visual popping artifacts as the terrain is refined.

Keywords: terrain, rendering, triangulation

i

(4)
(5)

Sammanfattning

Bakgrund. Ray marching är en teknik som kan användas för att rendera bilder av oändliga terränger definierade av en höjdfunktion genom att testa funktionens värde längs en stråle tills terrängens yta korsas. Tekniken kan dock vara dyr, och genererar inte en triangel-representation, vilket kan vara användbart i vissa användningsområ- den.

Syfte. Målet med avhandlingen är att implementera en algoritm för vy-beroende triangulering av oändliga terränger i realtid utan att använda någon förbehandlad data, och jämföra prestandan och den visuella kvaliteten av implementationen med en lösning som använder ray marching.

Metod. Prestandavärden för båda implementationerna samlas och jämförs. Render- ade bilder från båda metoderna jämförs med en algoritm som bedömer bildkvalitet.

Resultat. Alla test som utfördes visar att den förslagna metoden generellt presterar bättre vad gäller bilduppdateringsfrekvens än en version som använder ray marching.

Den visuella skillnaden mellan de två metoderna beror starkt på kvalitetsinställnin- gen för trianguleringen.

Slutsatser. Den föreslagna metoden kan prestera bättre än en version som använ- der ray marching, men beror mer på processorkraft, och kan lida av plötsliga visuella skillnader när terrängen förfinas.

Nyckelord: terräng, rendering, triangulering

iii

(6)
(7)

Acknowledgments

We would like to thank Dave Hoskins and Íñigo Quílez for creating the terrains used for evaluation, as well as our supervisor Prashant Goswami for his valuable feedback.

v

(8)
(9)

Contents

Abstract i

Sammanfattning iii

Acknowledgments v

1 Introduction 1

1.1 Ray Marching . . . . 1

1.2 Mesh Creation . . . . 2

1.3 Delaunay Triangulation . . . . 3

1.4 Aim and Research Question . . . . 5

2 Related Work 7 2.1 Grid . . . . 7

2.2 GPU . . . . 8

2.3 TIN . . . . 8

2.4 Ray Tracing . . . . 9

3 Method 11 3.1 Evaluation . . . 11

3.2 Algorithm . . . 13

3.2.1 Asynchronous Execution . . . 15

3.2.2 Terrain Definition . . . 16

3.2.3 Select and Split Terrain Area . . . 16

3.2.4 Delaunay Triangulation Algorithm . . . 20

3.2.5 Generate Initial Triangulation . . . 23

3.2.6 Refine Vertex Selection . . . 33

3.2.7 Update Triangulation . . . 35

3.2.8 Algorithm Thread Procedure . . . 36

4 Results 39 4.1 Implementation . . . 39

4.2 Experimental Results . . . 40

4.2.1 Triangulation . . . 41

4.2.2 Visual Quality . . . 41

4.2.3 Performance . . . 42

5 Analysis and Discussion 49

vii

(10)

6 Conclusions 53

7 Future Work 55

References 57

viii

(11)

List of Figures

1.1 Ray marching . . . . 2

1.2 Triangulated irregular network . . . . 3

1.3 Delaunay triangulation . . . . 4

1.4 Sliver triangles example . . . . 4

1.5 Popping . . . . 5

3.1 SSIM visual reference . . . 12

3.2 Algorithm overview . . . 14

3.3 Thread setup overview . . . 16

3.4 Selected quadtree . . . 18

3.5 Triangle connections . . . 19

3.6 Uneven node borders . . . 19

3.7 Quadtree shifting . . . 20

3.8 Frustum culling . . . 21

3.9 Triangulation example . . . 22

3.10 Concave surface triangulation . . . 24

3.11 Generation illustration 1 . . . 28

3.12 Predefined grid vertices . . . 28

3.13 Generation illustration 2 . . . 29

3.14 Generation illustration 3 . . . 30

3.15 Generation illustration 4 . . . 31

3.16 Generation illustration 5 . . . 32

3.17 Moving vertex example . . . 34

3.18 Triangulation example at border . . . 36

3.19 Moving triangles comparison . . . 36

4.1 Worker thread count impact . . . 40

4.2 Used terrain examples . . . 41

4.3 Resulting triangulation example . . . 42

4.4 Triangulation of different terrain areas . . . 43

4.5 Node border visibility . . . 43

4.6 Node border triangulation example . . . 44

4.7 Resulting SSIM image comparison . . . 44

4.8 Frame rate results . . . 45

4.9 Algorithm iterations per second . . . 45

4.10 Algorithm subroutine times . . . 46

4.11 Rendered nodes per second . . . 46

4.12 Generated nodes per second . . . 46

ix

(12)

4.13 Rendered triangles per second . . . 47 4.14 Generated triangles per second . . . 47 4.15 Image quality comparison results . . . 47

x

(13)

List of Algorithms

1 Render Thread Main Loop . . . 17

2 Triangulation Algorithm . . . 22

3 Initial Triangulation Generation . . . 26

4 Move Internal Triangles . . . 27

5 Move External Triangles . . . 27

6 Refine Vertex Selection . . . 33

7 Algorithm Thread . . . 37

xi

(14)
(15)

Chapter 1

Introduction

Procedurally generated terrain is used in a variety of applications, such as real- time rendering and simulation. Terrain is often represented as a two-dimensional height map, which can be converted into a triangle mesh. Typical terrain rendering solutions subdivide the terrain into smaller areas, and pregenerate several meshes at different levels of detail (LOD) for every area [1, 21, 3, 36]. During run-time, the application selects one of these meshes to render for every area depending on factors such as observer distance, and dynamically connects the separate meshes into a multi- resolution mesh. For use cases with unlimited terrain bounds, it is non-trivial to generate a terrain mesh in advance, which means these methods are not applicable.

Instead, this type of terrain is usually generated procedurally using ray casting, where the 3D shape of the surface is described with a mathematical function. This type of approach is well suited for rendering using ray marching [9, 2, 10, 35, 34, 37].

Although it is possible to render a scene fully using ray-marching, some of the benefits of using a triangulated mesh are lost, such as the possibility for more complex terrain interactions and the performance gains generated by the existence of persistent data.

By developing an approach that procedurally creates a triangulated mesh from an infinite terrain, these disadvantages can be avoided, which is the aim of this thesis.

1.1 Ray Marching

Ray casting, or ray marching, is a technique that involves sampling consecutive points along rays until a certain criteria is met, until a maximum number of samples have been taken, or until a certain maximum distance has been traveled. In the context of terrain rendering, the height of the terrain specifies the criteria. Normally, a ray is shot from every pixel in the frame buffer. An example of ray marching with a single ray against a terrain function is seen in Figure 1.1a. The ray is shot from the camera in a given direction. While traveling in that direction, the terrain function is sampled at consecutive points along the ray. The goal of the ray marching is to identify if it intersects the terrain surface at some point. If an intersection is detected, the position is calculated, as well as features such as surface normal and terrain color at that location. To make sure this point is found with as much precision as possible, the length of sample steps should decrease as the ray nears the terrain surface. Therefore, the vertical distance from the ray to the terrain is used to calculate the length of the next step. A small vertical distance yields a short step, while a higher vertical distance yields a greater step.

An advantage of this method is the low storage space required, as only the code for

1

(16)

2 Chapter 1. Introduction

Camera

(a) (b)

Figure 1.1: a) Example of ray marching of one single ray from a camera against a terrain surface. The variable step lengths has been marked along the ray travel path.

b) Image from a fully ray cast implementation used in this thesis with example rays inserted, emitted from the position of the camera.

evaluating the function needs to be stored. The disadvantage is the lack of temporal coherence, which means an increased per-frame computational cost to ray cast the terrain instead of creating a mesh representation that can be directly rendered using hardware rasterization. Despite the relatively high computational cost, the algorithm is simple to implement and generates accurate results, as every pixel is evaluated separately. For these reasons, and because ray marching does not make use of any preprocessed data, it is often the preferred solution for rendering infinite terrain.

Figure 1.1b depicts a modified version of a program from ShaderToy.com [34] that represents an infinite terrain.

Another disadvantage is that rendering a terrain with ray marching does not entail mesh creation. However, certain 3D interactions, such as those involving physics and collisions, are best handled using a mesh. Whereas ray marched scenes can conveniently handle scene description with respect to object placements, they are unsuited for more complex object-terrain interactions.

1.2 Mesh Creation

Marching cubes [26] is a common choice for triangulating surfaces described by func-

tions [43, 8, 16]. The algorithm subdivides 3D space into equally sized cubes and

samples the function for every cube corner. Cubes whose corner samples do not all

have the same sign are considered to cross a surface, and a predetermined triangula-

tion pattern is inserted at the cube’s position. However, in its simple form it is best

used for limited meshes that can fit into main memory and where the appropriate

mesh density can be predetermined. It also requires complicated border stitching

algorithms to ensure mesh connectivity if it is done in an adaptive manner. Addi-

tionally, it is non-trivial to refine an existing mesh without completely recreating

it. Terrains are most often represented using either a completely regular grid pat-

tern of vertices or a triangulated irregular network (TIN) [31]. A TIN is a mesh with

vertices at arbitrary positions, making the triangles vary in size. An example TIN

(17)

1.3. Delaunay Triangulation 3

Figure 1.2: Triangulated irregular network (TIN) example from the proposed solu- tion.

from the proposed solution is shown in Figure 1.2. In the context of terrain repre- sentation, the vertices of a TIN are most often placed at the positions that are the most necessary to accurately represent the terrain surface. The advantages of a TIN is that it may require less memory to represent the terrain compared to a regular grid, as it allows for a higher degree of simplification. The disadvantages are more complex algorithms for calculating which vertices that most accurately represent the terrain and the connectivity at borders. Since vertices are not in a predetermined pattern, a triangulation algorithm like Delaunay triangulation is required to connect the vertices into correct triangles.

1.3 Delaunay Triangulation

Delaunay triangulation is a triangulation algorithm that maximizes the minimum angle for all triangles in a mesh [29]. In the 2-dimensional case, this is achieved by making sure that no vertex, other than the vertices defining the current triangle, are within the enclosing circle, or circumcircle, of the triangle, see Figure 1.3a and 1.3b.

The circumcircle of a triangle is the circle that have all three corner vertices of the triangle on its border. The condition above, which drives the Delaunay triangulation, is called the Delaunay condition and it tends to minimize the number of triangles with extremely acute angles, called sliver triangles, in the resulting mesh. An example of how sliver triangles are reduced is seen in Figure 1.4a and 1.4b. Sliver triangles are undesired as issues with numerical precision can occur as a result of their use.

Although Delaunay triangulation produces high quality meshes, it can only do so

if it has access to all vertices. If two regions are triangulated separately, the border

between the resulting meshes does not necessarily match on both sides. This is not

acceptable in most applications, as it creates visible cracks in the mesh that will

cause undesired results. Cracks between different meshes is not unique to Delaunay

triangulation but is rather a general problem when using multiple meshes side by

side as patches/nodes [24, 27]. A common approach to solve this is to force use of

the exact same vertices along the border between two regions [39, 20], and this is

(18)

4 Chapter 1. Introduction

(a) (b)

Figure 1.3: Example of Delaunay triangulation: a) A simple mesh with circum- circles marked and a new vertex (green) to be added. b) The modified mesh and circumcircles with the new vertex added.

(a) (b)

Figure 1.4: Sliver triangle example: a) Triangulation that does not conform to the

Delaunay condition, which produces a sliver triangle that could be avoided. b) The

same vertices with a triangulation that fulfills the Delaunay condition and thus avoids

the sliver triangle.

(19)

1.4. Aim and Research Question 5

(a) (b)

Figure 1.5: Example of popping. a) Three connected vertices. b) A fourth vertex has been added one frame later, causing a sudden change in the height of the terrain, resulting in so-called popping. For an observer close by, this change will be clearly visible and might draw attention.

part of the chosen approach for this thesis.

When changing a part of a visual scene in a noticeable way from one frame to the next, e.g. using Delaunay triangulation, it might cause a problem known as popping.

Popping is a visual artifact that is often a result of a mesh being replaced by another, a mesh suddenly appearing, or a mesh being modified. A simplified example is seen in Figure 1.5. This type of sudden change in the scene might then be noticed by a human, if looking in the right direction, and is then called popping due to the fact that the change looks like something popping in.

Adaptive terrain rendering means creating and rendering a terrain representation where the amount of detail in an area depends on its distance to the viewer. It is a well-studied area [17, 42, 15, 25], however, to the best of our knowledge, there is no solution that does not require use of preprocessed terrain data or a preexisting mesh.

This means that existing solutions are ill-suited or inefficient for use with infinite terrains. We propose a terrain rendering method that does not make use of any pregenerated data, enabling use with infinite terrains. This is achieved by creating a dynamic triangulation of a terrain function, such as those employed in ray marching applications.

1.4 Aim and Research Question

The aim of the thesis is to explore and implement a technique for on-the-fly, adap- tive, continuous, generation of a TIN from procedural terrain produced through ray casting, without making use of preprocessed terrain data. As the terrain represen- tations in question are infinite and thus cannot be triangulated in their entirety, the triangulation is adaptively updated in a view dependent manner, and refined peri- odically based on object domain features. Since the intended use case is interactive applications, the technique needs to be computationally efficient enough to perform in real-time. Because of the scope of the thesis, the work is limited to terrains that have exactly one surface height for every position on the horizontal plane.

For the resulting mesh to be useful, it needs to approximate the surface accurately, such that the result of rendering the mesh produces an image that is similar to the ray marched version. At the same time, the computational performance should make the solution viable for use in real time applications.

This technique may be useful in any case where ray marching is employed for ter-

rain rendering. In addition to potentially increased performance and the creation of

a triangle mesh approximating the terrain, its use may lead to lower GPU utilization

(20)

6 Chapter 1. Introduction for rendering, allowing further resources to be used for other tasks.

Summarized, the aim of the work is to provide a solution for on-the-fly, adap- tive, view-dependent, continually refined triangulation of terrain produced through ray marching, without using preprocessed terrain data. This leads to the following research question:

• How do ray marching and the proposed solution compare with respect to per-

formance and visual quality?

(21)

Chapter 2

Related Work

Previous work on terrain generation and view-dependent rendering primarily focus on use cases where the terrain data is known in advance, allowing various forms of preprocessing to be done before the terrain is rendered by an application. This chapter presents solutions and work based on: grids, GPU, TIN and ray tracing.

2.1 Grid

Vertices of the terrain mesh might be organized into a regular pattern, which allows for use of simple triangulation and data structures such as restricted quadtrees [38]

and binary trees of triangles.

Evans et al. present a technique they call Right-Triangulated Irregular Net- works [7]. It utilizes a predetermined set of vertices to create a binary tree that approximates the terrain surface by partitioning it into a set of right-angled isosceles triangles. An approximation error is maintained for every leaf node triangle. A trian- gle’s approximation error and observation distance is used to determine the required level of detail, and the mesh is refined or coarsened to meet the detail requirement by adding or removing leaf nodes in the binary tree.

A similar approach is described in [32], which partitions the terrain with a re- stricted quadtree, where the difference in level of detail can be at most one between neighbouring nodes. An error metric approximation is maintained for every vertex, and is used to determine the level of detail of nodes.

Lindstrom et al. [22] use a predefined high-resolution mesh with vertices placed in a uniform grid. A quadtree division is used to partition the terrain into rectangular regions, for which an approximate simplification level is calculated in real-time. The regions are further simplified by fusing neighbouring triangle pairs based on an error metric that considers the clip space distance between a removed vertex and the corresponding point on the fused triangle.

RASTeR [14] is a technique that involves splitting terrain data into square regions called M-blocks, which are organized into quadtree hierarchies. The quadtree is related to a binary tree of K-patches, a subdividable triangular data structure. The terrain level of detail is selected with the use of object space error. To render the mesh, the K-patch structure is used to construct a triangle strip that is sent to the GPU.

7

(22)

8 Chapter 2. Related Work

2.2 GPU

With improvements in GPU performance and the development of programmable graphics hardware, GPU-based techniques have been created, a few of which are presented below.

Geometry clipmaps [27] store terrain data at a number of different levels of detail in GPU memory. Rectangular areas around the viewer utilize geometry data from the different levels of detail depending on the distance to the observer. Geometry at edges of the rectangular areas is stitched together in real-time to produce a continuous surface.

Persistent grid mapping [25] projects a clip space grid onto a horizontal plane in world space. Terrain data is sampled at the projected grid points to produce a triangle grid that is then rendered.

Lambers and Kolb [17] describe a data structure, the edge mark array, that enables use of Right-Triangulated Irregular Networks in a parallel manner on the GPU, which can be used to render potentially dynamic terrain data.

Zhai et al. describe an approach to terrain rendering utilizing GPU hardware tessellation [42]. In a preprocessing step, the terrain is subdivided with a quadtree hierarchy, where quadtree levels correspond to terrain level of detail. At run-time, the appropriate detail level is selected by taking distance to camera and terrain rough- ness into account. The terrain mesh is then further refined using GPU tessellation functionality.

2.3 TIN

Instead of storing terrain vertices in a regular pattern, geometry data may take the form of a TIN. While this approach can make ensuring mesh connectivity more com- plicated, TIN may represent a surface with less error and fewer redundant triangles, as vertex positions are not limited to a specific pattern.

BDAM [4] utilizes a binary tree to partition terrain data into small precomputed TIN patches. Hierarchical view frustum culling is used to ensure only visible nodes are rendered. The algorithm uses a custom memory manager to cache geometry and texture data, which optimizes GPU cache behaviour.

Hu et al. present a GPU algorithm for dynamic view-dependent level of detail for any mesh [11]. Vertex splits and edge collapses are stored in a precalculated data structure. During run-time, an error metric based on surface orientation, camera frustum, and screen-space geometric error determines if an edge collapse or vertex split is necessary, and if so, modifies the index buffer used to render the mesh to produce the appropriate level of detail.

Vertex relocation [18] is a technique used to focus geometry detail in areas where the terrain is rougher, to produce a more accurate approximation. The terrain cur- vature is estimated at every vertex, and vertices are given an attraction force that is higher for vertices in rough terrain areas. Vertex positions are then modified according to these forces, and the terrain data is re-sampled.

Bertilsson and Goswami [1] divide a terrain data-set into rectangular patches but

uses no or minimal preprocessing. During run-time, vertices are added or removed

(23)

2.4. Ray Tracing 9 to the triangle mesh depending on an error metric based on height difference to neighbour vertices projected onto the camera plane. The active vertices are then triangulated using a Delaunay algorithm to obtain a triangle mesh. Vertices along the edge of a patch only consider other border vertices, which ensures that neighbouring patches always obtain matching edges along the border.

2.4 Ray Tracing

An alternative to rasterization-based rendering is ray tracing. With this technique, a mesh representation of the terrain does not need to be created and maintained. This can reduce memory consumption, but means that there is no terrain representation that can be used across multiple frames to reduce computational cost. Instead, ray tracing must be performed for every frame. Because meshes are not used, ray tracing can also reduce popping artifacts.

Dick et al. [6] present a method for rendering terrains using ray tracing. The ter- rain height field is partitioned into tiles. Every frame, the visible tiles are determined and the back faces of their bounding boxes are rendered in front-to-back order. In the fragment shader, a ray is cast through the pixel and is traversed from the entry point on the bounding box until it intersects terrain or leaves the bounding box.

Terrain intersection is evaluated using a mipmap chain of the terrain height map.

Silvestre et al. [37] use a similar method where they implemented LOD by lim- iting mipmap chain traversal based on a tile’s distance to the camera. Additionally, secondary rays used for rendering shadows were introduced.

A hybrid method employing both rasterization and ray tracing is presented by Dick et al. [5]. The terrain data is split into rectangular tiles. At run-time, the implementation decides whether to render the tile using ray tracing or rasterization based on the estimated time required for both methods.

Research on terrain rendering often focus on use cases where the terrain data is

known in advance and can be preprocessed in various ways. While the preprocessing

steps can be implemented to run dynamically, it is often too expensive or slow to

allow for real-time performance. This means that these solutions are not suited for

use with procedurally generated or infinite terrains. The approach presented in this

thesis is designed to be used with infinite terrains, without generating terrain data

until it is required.

(24)
(25)

Chapter 3

Method

This chapter begins with introducing the method of evaluation, and then presents the details of the presented algorithm.

3.1 Evaluation

When comparing different rendering methods, an objective comparison between re- sulting visuals is commonly performed [19, 18, 23, 41]. This is called image quality assessment (IQA) and can be performed either subjectively or objectively. In sub- jective comparisons, human participants are asked to rate or in some way provide information about which result looks the best or is preferred. Since every human is slightly different, the results from one person is not enough. Instead, the answers from many individuals needs to be summarized to produce a statistically significant result.

Objective comparisons are performed using computers and algorithms. This in- volves inputting two images to an IQA algorithm: one reference image, and one to evaluate. Since the solution or technique that is evaluated will be used by humans, the algorithms attempt to approximate human opinion. The output is therefore an approximation of how visually similar a human would perceive the images to be.

The advantage of using objective IQA methods is that no human participants are required and the results are guaranteed to be the same, but the drawback is that the algorithms can not completely guarantee that a human study would give the same results.

An application implementing both the ray marched solution and the proposed triangulation and rendering solution is created and used for testing and evaluation.

The research question is answered using two measurements: algorithm performance and visual quality.

The performance of the implementation is measured by comparing the frame rates of the triangulated and the ray cast terrain rendering approaches. Measuring performance through run-time performance is important, as the goal is to use the proposed solution as one of many subsystems in run-time applications. The reason for specifically using frame rate as a metric is because it is a close approximation of the efficiency and continuous performance cost of an application, and is a commonly used performance metric [28, 5, 18, 36, 15]. The per-second rates is gathered for number of generated nodes, rendered nodes, generated triangles, rendered triangles and algorithm iterations. Data on thread count impact on performance, as well as the run time for the main subroutines of the algorithm, is also gathered.

11

(26)

12 Chapter 3. Method

(a) (b)

(c) (d)

Figure 3.1: Example images of the same scene from the implemented application using the Elevated terrain [34]. a) Ray marched reference image. b) Presented solution with low refinement. With the ray marched image as a reference, this image results in a Structured Similarity Index [40] value of 0.70. c) A more refined terrain mesh with similarity index 0.81. d) Highly refined terrain with similarity index 0.86.

Visual quality is evaluated by calculating the perceptual error between the image generated using the proposed method and the original ray cast versions. This thesis uses the Structural Similarity Index (SSIM) IQA algorithm [40]. Instead of just measuring the difference between two images, like earlier methods, SSIM attempts to measure the change in structural information. The result of the SSIM algorithm is a value in the range [0, 1], where higher values correspond to more similar images, and a result of 1 implies identical input images. Figure 3.1 shows three example images along with a reference that they are compared to, as well as the resulting similarity index.

SSIM is uses as it is a well established algorithm for comparing images [19, 18,

23, 41]. PSNR is another well established algorithm, but has been repeatedly shown

to perform poorly compared to other quality metrics [12, 13]. There are state-of-the-

art IQA algorithms, such as PieAPP [33], that are accurate, but have not yet been

established. PieAPP in particular, however accurate, is aimed towards comparing

two images with a reference one, and the image that receives the lowest output is

the one the algorithm considers that a human would prefer. The reason for not

comparing the proposed solution to existing work is that while there are existing

solutions for terrain rendering (see Chapter 1 and 2) no existing work fulfills all of

the requirements of the aim, particularly supporting infinite terrains while creating

adaptive triangulation.

(27)

3.2. Algorithm 13 A subjective study using human participants might have been used instead of, or in addition to, the IQA algorithm, but such a study is not performed for this thesis.

This is partially due to time and risk factors, as performing this type of experiment is time consuming, and there is a risk of not gathering sufficient participants for the results to be statistically significant. In addition, the relevance of data gathered from a subjective study would be questionable in the case of this thesis. As the presented method produces an approximation of the ray marched terrain and the ray marched version is used as a reference, the quality of the presented method cannot be higher than the ray marched version. Unlike the ray marched version, the proposed method also suffers from noticeable popping artifacts. For these reasons, the question of visual quality is not if the presented method can outperform ray marching, but rather how visually similar results the presented method is able to produce. If data on similarity is gathered through a subjective study, the results are rather arbitrary and dependant on the scales or questions used for the study. Using an IQA algorithm produces objective results without the risk of insufficient participants, and is directly comparable with other work using the same IQA algorithm.

Testing is carried out for three different terrain functions. For every terrain, two separate tests measure the performance and the visual quality of a test scene. A test scene consists of a short predefined fly through of the terrain. The tests are repeated for a number of different values for the user defined threshold used in the triangulation algorithm. This demonstrates how much the triangulation quality, and therefore visual quality, affects the performance. The reason for doing a predefined path for each terrain is to ensure that the results, especially for the image quality comparison, are comparable between different test runs.

The performance test collects data by recording the data at specific intervals for the two test fly throughs; one using the presented method and the other using ray casting. For the visual quality test, both rendering methods execute simultaneously using identical camera settings. Both resulting images are saved at a regular interval, and later used to calculate the perceptual error. During the tests, constant values used by the algorithm are set to constant values obtained through empirical testing.

In the following section, the details of the proposed solution are introduced.

3.2 Algorithm

One possible approach for accomplishing the aim of the thesis could be to continue the work of existing solutions, such as the one proposed by Bertilsson and Goswami [1], that uses no or minimal preprocessing. If the preprocessing that is necessary could instead be done at run-time as new terrain areas are introduced, their solution would fulfill most of the requirements of the aim of this thesis. The reason for not following this route is that performing the preprocessing in run-time would create a consider- able risk of inefficient performance, compromising the interactivity of the application.

Moreover, such a solution could create vertices that might never be used unless the observer came close.

The proposed algorithm consists of 4 main steps, which are shown in Figure 3.2.

As rasterized rendering is the method of choice in this thesis, a mesh is needed, but

rendering an infinite terrain using an infinite mesh is not feasible, as it would require

(28)

14 Chapter 3. Method an infinite amount of memory and processing power. Selecting an appropriate area of the terrain to work with is therefore necessary.

Select and split terrain area Identify visible terrain area. Split the visible

area into smaller regions, called nodes.

Generate initial triangulation

For each node, create an initial, view-independent triangle mesh.

Refine vertex selection

Create vertices required to refine mesh where necessary.

Update triangulation

Run triangulation algorithm on each node to insert the new vertices.

Treat current node and its neighbours as a single mesh to ensure consistent triangulation quality across the entire terrain.

Figure 3.2: Overview of the steps taken by the proposed algorithm.

In order to enable parallelism and to avoid processing unseen terrain, the area is split into smaller, constant size regions, called nodes. The utilization of these nodes makes movement over long distances in the world simpler to handle, as one otherwise would have to re-triangulate the whole area after removing the unwanted vertices.

The refinement and triangulation steps of the algorithm operate on triangle meshes, and as such require a mesh to operate. Whenever a node is visible for the first time, an initial mesh is created to fulfill this requirement. How new ver- tices are acquired is one of the ways this thesis differs from traditional ray casting.

Ray casting requires traversing a potentially large number of steps to find the correct height, while the proposed algorithm simply calculates the height at already specified locations.

It is important for the proposed algorithm to produce visually similar results to

ray casting, as ray casting is the most used alternative and produces visually ac-

curate terrain representations. Distant terrain usually does not benefit from fine

triangulation. Geometry that does not contribute visually decreases the rendering

performance without increasing visual quality, and highly refined terrain may intro-

duce aliasing artifacts when in the distance. For this reason, the initial triangulation

is coarse and the terrain is continually refined to add detail only where it is needed

visually. If it is determined that refinement is required, new vertices need to be

(29)

3.2. Algorithm 15 created. The positions of new vertices needs to be selected so that they produce the best terrain representation with the least amount of vertices.

When the new vertices have been created, the existing mesh is updated to include them with a triangulation algorithm based on Delaunay triangulation. During the triangulation, the mesh of the current node and the meshes of neighbour nodes are treated as a single mesh, which ensures that triangulation quality is consistent across the entire terrain mesh, even along node borders. Due to this, the triangle mesh does not have any perceivably different triangulation at node borders. The above steps are then repeated as required while running the application.

The algorithm is implemented in an asynchronous manner, which is discussed in the following section. This allows the application to render new frames continuously, without waiting for the algorithm at every step. The remainder of this chapter presents the algorithm in detail. Section 3.2.2 presents how the terrains used by the algorithm are represented, and Section 3.2.3 introduces terrain area selection, quadtree and nodes. The mesh refinement algorithm used in the initial triangle generation and triangulation update steps is described in Section 3.2.4. Section 3.2.5 details the initial mesh generation, Section 3.2.6 discusses the refinement process, and Section 3.2.6 presents the algorithm for inserting new vertices into the terrain mesh. Lastly, Section 3.2.8 shows the complete procedure for the algorithm.

3.2.1 Asynchronous Execution

The algorithm is performed on two main threads: the render thread and the algorithm thread. The render thread is responsible for handling user input, camera movement and rendering the terrain to the screen. In the algorithm thread, the steps detailed in Figure 3.2 are performed, which involve handling and refining the terrain. In addition, a number of worker threads are utilized by the algorithm thread to enable parallelism where applicable. The thread setup is visualized in Figure 3.3.

The main loop of the rendering thread is presented in Algorithm 1. The procedure for the algorithm thread is presented later, in Section 3.2.8, when the necessary concepts have been introduced. Work for the algorithm thread is produced by the render thread. Whenever the algorithm thread is idle, the render thread provides input in the form of camera position and frustum, which the algorithm thread uses to execute one algorithm iteration, consisting of selecting and splitting terrain area, generating initial triangulation, refining vertex selection and updating triangulation, as described in Figure 3.2. This is performed asynchronously, and the render thread may continually handle input and rendering while the algorithm thread is executing.

When the algorithm thread finishes executing the algorithm iteration, the render thread detects it during its next frame. Any updated mesh data which results from the algorithm is then uploaded to the GPU, and the visible terrain areas that the render thread needs to draw is updated. A new iteration of the algorithm is then started on the algorithm thread, with updated camera data. The render thread then continues handling input and rendering of the visible terrain areas until the next algorithm iteration has finished execution, at which point this process is repeated.

As several parts of the algorithm are parallelizable, those tasks are spread across

the worker threads to improve performance. The initial triangulation generation, ver-

tex selection refinement and triangulation update steps are all parallelizable to some

(30)

16 Chapter 3. Method

Render

thread Algorithm

thread

Worker

thread 1 Worker

thread 2 Worker

thread 3 Worker

thread n Launch algorithm iteration

Sends camera data

Sends visible terrain areas when done

Figure 3.3: Overview of the thread setup. The render thread launches the algorithm thread and gives it the camera data. The algorithm thread starts running the algo- rithm and uses worker threads to parallelize the load. The render thread continually renders the scene while waiting for the algorithm thread to finish and send the new data to the render thread.

extent, which is further discussed below, in Sections 3.2.5, 3.2.6 and 3.2.7. Where possible, work on these algorithms are delegated to the worker threads. However, no terrain area may be updated by several threads simultaneously.

The next section describes how the terrains used by the algorithm are defined.

3.2.2 Terrain Definition

As infinite terrains are the focus of the algorithm, terrains are not defined using preprocessed data. Instead, the terrain description is provided by two functions, whose input is a two-dimensional position on the horizontal plane. The two functions, called the terrain height function and the terrain color function, return the surface height and the surface color, respectively, at the specified input location.

The following section introduces the terrain area handling and the concept of nodes, which are used subdivide the infinite world.

3.2.3 Select and Split Terrain Area

As the world handled by the algorithm is unbounded, it is infeasible to work with

the entire terrain simultaneously. For this reason, a subset of the world needs to

be selected to work with. To accomplish this, the horizontal plane of the world is

treated as a collection of static square areas of constant size. A collection of these

areas that make up a square centered on the camera is selected, and this is the subset

of the world that the algorithm handles. This collection of areas is treated as the

leaf cells of a quadtree, which allows for efficient traversal of the structure.

(31)

3.2. Algorithm 17 Algorithm 1 Render Thread Main Loop

1: procedure MainLoop

2: VisibleTerrainAreas ← ∅

3: for all frames do

4: gather user input

5: update camera position and direction

6:

7: // If algorithm thread has finished execution, update

8: // VisibleTerrainAreas and start new algorithm iteration

9: if algorithm thread is idle then

10: // Visible terrain areas has been updated by

11: // algorithm thread and need to be updated

12: VisibleTerrainAreas ← GetVisibleTerrainAreas()

13:

14: // If algorithm thread updated terrain mesh,

15: // upload mesh data to GPU for rendering

16: upload updated mesh data to GPU

17: start new algorithm thread iteration

18:

19: Render(VisibleTerrainAreas)

Quadtree

The quadtree structure always contain the same number of cells of the same size. The leaf cells are referred to as nodes, and every node correspond to a square terrain area mentioned above. Nodes contain terrain data such as vertices and indices for their associated terrain area. The quadtree contains one constant size area of memory per node, which is used to store the terrain data. In addition, the quadtree handles a constant size GPU memory area for every node, where the index and vertex data of the terrain mesh is uploaded and used for rendering. While the terrain mesh is made up of meshes from several nodes, the node meshes must connect to create a continuous mesh surface to avoid visible holes in the terrain.

Nodes

A node in the quadtree is associated with one square terrain area in the quadtree, and is responsible for the mesh data that represents the terrain within that area.

Nodes may be in one of two states: valid or invalid. Invalid nodes do not contain any mesh data and are not rendered. Only nodes that have not yet been seen by the observer may be in this state. Valid nodes do have mesh data, and are rendered if visible. Their mesh data may additionally be refined by the triangulation update step of the algorithm.

Nodes contain the data required to create and refine the terrain mesh by the

various steps of the algorithm. Mesh vertices and indices are stored, along with the

center and radius of the circumcircle of every triangle in the mesh. A list of new

vertices to be added to the mesh is also stored. These vertices are generated by the

(32)

18 Chapter 3. Method

Figure 3.4: A small quadtree (green outline) with the selected nodes inside it and the observer (green dot) in the center of the quadtree.

vertex selection refinement step of the algorithm, and are added to the terrain mesh in the triangulation update stage. Every new vertex also has an associated triangle used by the triangulation update step. This is discussed further in Section 3.2.4.

Along with every terrain mesh vertex and new vertex, an approximation of the terrain curvature at the vertex location is stored. This approximation is used by the vertex selection refinement step of the algorithm, presented in Section 3.2.6, and is created along with every vertex, in the vertex selection refinement or initial triangulation generation steps. The curvature is approximated using a Laplacian of Gaussian convolution, as presented by Lee et al. [18], sampling the terrain height function.

In addition, data on triangle connections is kept. Two triangles are connected if they share an edge, i.e. if two vertices are used by both triangles. This data is used in the triangulation algorithm, presented in Section 3.2.4. As a triangle contains three edges, it may have up to three connections. This means that in a TIN, all triangles except those along the edge have three connections. Similarly, the triangles in the mesh of a node contain three connections unless they lie on the border of the node. Consequently, triangles that have less than three connections must lie on the border of the mesh. This type of triangle is called a border triangle, and a list of every border triangle within a node is maintained by that node. This list is used to improve performance when a task requires access to only border triangles. The border triangles are identified by the fact that one or more of their connections are not pointing to another triangle within the node. These connections are referred to as invalid, and instead of pointing to a triangle within the node, special marker values are used to signify which neighbouring node a border triangle connects to.

This information is used in the initial triangulation generation step of the algorithm.

Figure 3.5 provides a visualization of triangle connections.

The triangles within a node are not necessarily enclosed within the terrain area

associated with the node. The algorithm prioritizes triangulation quality instead of

simplicity of connecting node triangulations, which ensures the quality of the trian-

(33)

3.2. Algorithm 19

A

B

Figure 3.5: Two triangles, A and B, with their respective connected triangles marked blue. The thick horizontal line indicate the border between two nodes. Triangle A lies next to another node (light gray triangles at the top) and is therefore only connected to two other triangles, with the third connection being set to invalid.

gulation remains consistent across the terrain, even along node borders. No special patterns or restrictions are used for the triangles or vertices along the border of a node. However, this means that triangle edges along the mesh border do not nec- essarily match the edge of the square terrain area that the node is associated with.

This is illustrated in Figure 3.6. In order to keep the terrain mesh consistent and con- tinuous, it is necessary to update the mesh of neighbour nodes when border triangles are modified in a way that affects the triangulation of neighbouring nodes. Addi- tionally, the triangulation update step of the algorithm, discussed in Section 3.2.7, ensures that newly created triangles are assigned to the node which encloses the center position of the triangle.

Figure 3.6: Example of how the triangulation can look at the border between two nodes. The dashed line represents the border between the two square terrain areas that the nodes are associated with.

The next section details how the quadtree moves along with the observer to ensure that an infinite terrain is supported.

Quadtree Shifting

The quadtree and node structure described above handle a subset of the infinite

terrain. In order to enable the observer to move to any part of the terrain, the

position of this structure must be updated to match the location of the observer. This

process is referred to as quadtree shifting. When the observer moves a predefined

distance away from the center of the quadtree structure, rows or columns of nodes in

(34)

20 Chapter 3. Method the quadtree structure furthest away from the observer are discarded and replaced with new rows or columns in the direction of travel. Data in the discarded nodes is not kept, and the memory used by them is granted to the newly created nodes.

As there is no mesh data associated with the created nodes, they are in the invalid state. Figure 3.7 illustrates quadtree shifting.

Figure 3.7: Simplified example of the observer moving from the red point to the green point. The red lines represents the outline of the old quadtree and the green line the outline of the new quadtree. The movement causes the nodes that are within the red border, but not within the green border, to be discarded. The nodes that are within the green outline and not the red outline are created, but placed in the invalid state, as they contain no mesh data yet.

Frustum Culling

In order to reduce processing costs, the algorithm does not render or refine the meshes of nodes that are not visible to the observer. This is accomplished by frustum culling, and ignoring the nodes that do not intersect the camera frustum. The ignored nodes are not processed by any following step in the algorithm. A wider frustum is used for this culling than the one used for rendering. This allows the algorithm to refine terrain outside the view of the observer, which reduces the amount of visible geometry being modified as the view changes. The frustums are shown in Figure 3.8. When an iteration of the algorithm is finished, information about which nodes are visible is sent to the render thread, which will render these nodes until the next iteration is finished.

The next section introduces the triangulation algorithm that is used in both the initial triangulation generation and triangulation update steps of the algorithm.

3.2.4 Delaunay Triangulation Algorithm

The triangulation algorithm presented in this section is used in the initial triangu-

lation generation and triangulation update steps of the algorithm. Its purpose is to

refine an already existing mesh by adding a list of vertices to it, while updating the

(35)

3.2. Algorithm 21

Figure 3.8: Image from the implemented application showing the frustum used for rendering (red), inside the wider culling frustum (green). The wider frustum is used in the algorithm, as this allows geometry outside the visible area to be refined, which reduces visible mesh modification.

triangulation to take the new vertices into account. The triangle connection data stored in nodes is used to improve performance of the triangulation.

The triangulation algorithm is an incremental version of Delaunay triangulation, and is described in Algorithm 2. It operates on a terrain mesh projected onto the horizontal plane, which means the height values of vertices are ignored. Vertices in the new vertex list of the node are added in succession. The first step finds all triangles within the mesh with a circumcircle that contains the new vertex. To satisfy the Delaunay condition, no vertex may be contained within any circumcircle. As a result, these triangles must be modified if the vertex is to be added to the mesh while still satisfying the condition. The triangles found are removed from the mesh, leaving a polygonal hole, which will be filled with new triangles.

For every edge in the polygonal hole, a triangle is created which contains the two vertices of the edge, along with the vertex currently being added. These triangles are added to the mesh, which fills the hole while satisfying the Delaunay condition.

Figure 3.9 illustrates the process of adding one vertex to a simple mesh.

(36)

22 Chapter 3. Method

(a) (b)

Figure 3.9: Example of adding one new vertex to a simple node. a) The vertex to be added is shown as a green dot. Triangles with circumcircles that contain the new vertex will be removed, and are colored red. The circumcircles of these triangles are also shown. b) Removing the red triangles from the mesh leaves a polygonal hole, whose edges have been colored red. For every edge in the hole, a new triangle containing that edge and the vertex being added is created and used to fill the hole.

These triangles are shown in green.

Algorithm 2 Triangulation Algorithm

1: procedure DelaunayRefinement(node N )

2: for each vertex V ∈ N.NewVertexList do

3: // If a triangle’s circumcircle contains the new vertex,

4: // it should be removed

5: TrianglesToRemove ← all triangles in N whose circumcircle contain V

6:

7: // Remove all triangles in TrianglesToRemove from the mesh of N

8: for each triangle T ∈ TrianglesToRemove do

9: remove T from N

10:

11: // Removing triangles leaves a hole in the mesh

12: // Store the edges of the hole in Edges

13: Edges ← edges of hole left in N

14:

15: // For every edge in Edges, create a triangle with the two

16: // vertices of the edge and V. Add the triangle to N

17: for each edge E ∈ Edges do

18: Triangle ← triangle with vertices E.Vertices and V

19: N.Triangles.Append (Triangle)

Optimization with Triangle Connections

The process of finding all triangles with a circumcircle that contains a new vertex

is optimized using the triangle connection data stored in nodes. As a result of the

Delaunay condition, the triangles that need to be removed are always a connected

(37)

3.2. Algorithm 23 group. If one initial triangle within this group can be identified, the others can be found by traversing the connection data. This means that every triangle in the mesh does not need to be tested. The way the initial triangle is identified differs between the initial triangulation generation and triangulation update steps, and is discussed further in Sections 3.2.5 and 3.2.7, respectively. The index of the initial triangle is stored in the node data, along with the new vertex. To find the remaining triangles of the connected group, the circumcircles of triangles connected to the initial triangle are tested. If the circumcircle of a triangle contains the new vertex, the triangle is part of the group, and its connected triangles are also tested. If the new vertex is outside the circumcircle, the triangle is not part of the group, and its connected triangles are not tested. This process continues until there are no more connected triangles to test. At this stage, the entire connected group has been found, and is removed from the mesh.

A triangle that is removed might be the initial triangle associated with another vertex in the new vertex list. To ensure correct results, a new initial triangle must be found for the associated vertex. The required property of an initial triangle is that its circumcircle contains the vertex it is associated with. As the circumcircles of the newly created triangles are likely to contain the vertex associated with the removed triangle, the new triangles are tested first. If any of them is a valid initial triangle for the vertex, it is assigned as the new associated triangle. If a valid initial triangle is not found among the new triangles, the remaining triangles of the node are tested.

The next section describes the initial triangulation generation step of the algo- rithm.

3.2.5 Generate Initial Triangulation

As the vertex selection refinement and triangulation update steps of the algorithm operates on meshes, a mesh is required for them to operate. The purpose of the initial triangulation generation step is to create a mesh used as a starting point for refinement by these later steps in the algorithm. This is only required for nodes that are in the invalid state, and thus do not already have an associated terrain mesh.

For this reason, nodes in the invalid state that intersect the view frustum are the input to this stage of the algorithm. A terrain mesh is generated and assigned to the nodes, which are then placed in the valid state.

As mentioned in Section 3.2.3, the triangulation at node borders do not follow any predetermined pattern. In addition, the other steps of the algorithm assume that the triangulation across nodes is continuous and consistent, without any holes or duplicate triangles, and that the edges of meshes of neighbouring nodes match. This means that the initial triangulation generation step of the algorithm must ensure that the initial mesh generated for a node fulfills these criteria. This is accomplished by modifying the initial mesh generated to take any neighbour nodes into account, and create a matching mesh edge. Situations that require this modification arise when the observer moves away from, and then back towards, a refined terrain mesh area.

When moving away, nodes at the edge of the quadtree structure are removed. If the

observer then moves back toward the refined area while only some nodes of the area

have been removed, the nodes at the edge of the quadtree will have mesh borders

that do not match any predefined pattern. Nodes created next to these nodes must

(38)

24 Chapter 3. Method obtain a triangle mesh whose edges match that of their neighbour node.

Overview

This section presents an overview of the initial triangulation generation step of the algorithm. This step does not operate on individual nodes, but rather on groups of connected nodes. In this context, nodes are considered connected if the square terrain areas they are associated share a border or corner. All invalid nodes within the view frustum are divided into groups, such that every node in a group is connected to at least one other node within the group. The reason for operating on groups of connecting nodes instead of individual nodes is that it simplifies the creation of consistent and continuous terrain meshes for the nodes. For every node group, one temporary mesh is first created, which is a superset of all terrain meshes that the node in the group will be assigned. Every triangle of this mesh is then associated with a node, and all triangles associated with one node create the terrain mesh for that node. First creating the temporary mesh ensures that the terrain meshes created for neighbouring nodes do not contain any holes or duplicate triangles. The temporary mesh is created in a separate area of memory from the node terrain meshes, and contain the same data that a node does, such as triangle connections and a list of new vertices. Every group of nodes is independent, and is processed in parallel.

The first part of this step of the algorithm is to create enclosing triangles, which are two triangles in a rectangular formation, large enough to contain the terrain areas associated with the group of nodes with an additional margin. The main reason for the enclosing triangles is that the Delaunay triangulation algorithm used, presented in Section 3.2.4, only functions properly when the triangles it operates on creates a convex shape while projected onto the horizontal plane. Concave areas result in triangles not being removed properly, and unwanted triangles that stretch across the concave area. An example of an unwanted triangle along a concave mesh border is illustrated in Figure 3.10. The use of the enclosing triangles ensures that the created mesh is convex for the duration of the initial triangulation step.

The next step is to add vertices to the temporary mesh. These are the vertices that will eventually be used in the node terrain meshes. Vertices added are part of a predetermined grid pattern that is added for every node in the group. Additionally, vertices from neighbour nodes that already contain a terrain mesh are added. These vertices are added in order to ensure that the mesh will match up with the meshes of already existing terrain. The vertices are added to the mesh using the triangulation

Figure 3.10: Example of a part of a concave surface that produces an unwanted

triangle (marked red) along its border (thick lines) after triangulation.

(39)

3.2. Algorithm 25 refinement algorithm presented in Section 3.2.4, resulting in a mesh containing all added points.

Next, triangles in the temporary mesh need to be moved into the appropriate node and form the terrain mesh associated with the node. Not every triangle in the temporary mesh will be used in a node, as some are invalid, e.g. any triangle that includes vertices used for the enclosing triangles. These invalid triangles are not explicitly removed, but because they are not added to a node, they will not be used for mesh refinement or rendering, and are eventually overwritten in future iterations of the algorithm.

Associating triangles from the temporary mesh with a node is performed over two steps. The first step is performed for every node in the group. Triangles whose centerpoint lie within the square area represented by the node are valid, and added to the node. Triangles that connect to these valid triangles, but whose centerpoint do not lie within the current node are marked for use in the second step, but are not added to the node. The second step is performed for every marked triangle, not for every node. Marked triangles that have not already been added to a node are added to the node that marked them.

The last part of the initial triangulation generation step of the algorithm is to ensure that triangle connections and border triangle lists are correct for all nodes that had a terrain mesh generated in this step. The algorithm for this step is presented in Algorithm 3, and is discussed in greater detail in the following sections.

Temporary Mesh Creation

The first part of the initial triangulation generation step is to create the enclosing triangles which enclose the group of nodes whose terrain meshes are being created.

These triangles ensure that the mesh takes on a concave shape when projected onto the horizontal plane for the duration of the initial triangulation generation step.

This is because the extents chosen for the enclosing triangles enclose the group of nodes, as well as any vertex that will be added during this step. The extents for the enclosing triangles are found by identifying the minimum and maximum positions on both horizontal axes for any terrain area associated with the group of nodes. These positions, with an extra added margin, are used as the minimum and maximum positions of a rectangle, which encloses the group of nodes as a result. A vertex is placed in every corner of this rectangle, and connected to form two triangles in a quad formation (Algorithm 3, line 9). This process is illustrated in Figure 3.11. The square areas represent the extent of three invalid nodes that will have a terrain mesh generated, and the dashed lines represent how the world is split into square terrain areas. The dashed, gray shape is the outline of the triangle mesh belonging to a valid node that already contains a terrain mesh, and will therefore not have a terrain mesh generated in this iteration of the algorithm. This valid node is connected to the top left invalid node, and the algorithm must ensure that the edge of the triangle mesh generated for the top left invalid node matches that of the valid node. In Figure 3.11b, the rectangle enclosing the group of nodes has been created, and is represented by a dashed green line. Next, in Figure 3.11c, two enclosing triangles covering this rectangle have been created.

The next step is to create the vertices that will be a part of the final terrain

(40)

26 Chapter 3. Method

Algorithm 3 Initial Triangulation Generation

1: // Nodes is the list of nodes to generate a terrain mesh for.

2: procedure GenerateInitialTriangulation(nodes Nodes)

3: // Organize the list of nodes into groups, where every node in

4: // a group is a direct or diagonal neighbour of at least one other

5: // node in the group.

6: Groups ← Nodes organized into connected groups

7: for each group G ∈ Groups do

8: TM ← storage for temporary mesh

9: TM.Triangles .append(triangles enclosing all nodes in G)

10:

11: // Add vertices to the temporary mesh

12: for each node N ∈ G do

13: // For every node, add the predetermined grid

14: TM.NewVerticesList .append(vertices in predetermined grid)

15: // If any node surrounding N already has a terrain mesh,

16: // find the border edges that should connect to N and add

17: // the two vertices of that edge. The node a border edge should

18: // connect to is stored in the node’s triangle connection data.

19: for each node A adjacent to N do

20: for each edge E ∈ A.BorderTriangles do

21: if E borders to N then

22: for each vertex V ∈ E.Vertices do // 2 vertices per edge

23: if V / ∈ TM.NewVerticesList then

24: TM.NewVerticesList .append(V )

25:

26: // Add the vertices to the temporary mesh currently containing the

27: // enclosing triangles. Uses the triangulation algorithm presented in

28: // Section 3.2.4.

29: DelaunayRefinement(TM ) // See Algorithm 2

30: TM.Triangles .remove(enclosing triangles)

31: // List of triangles that will be marked in MoveInternalTriangles,

32: // and references to the nodes that marked them.

33: // Used for border triangle association in MoveExternalTriangles.

34: Marked ← ∅

35: for each node N ∈ G do

36: // Move internal triangles from temporary mesh to node

37: MoveInternalTriangles(N, TM, Marked ) // See Algorithm 4

38:

39: // Move leftover valid, marked triangles from temporary mesh to node

40: for each marked triangle structure M ∈ Marked do

41: // See Algorithm 5

42: MoveExternalTriangles(M.Triangle, TM, M.Node)

43:

44: for each node N ∈ G do

45: update triangle connections

46: find all border triangles

References

Related documents

Respondent A also states that if a current client makes changes in the ownership, a new credit assessment process will be initiated and if the bank does not get to know

The project management triangle is a framework generally used for controlling three main factors that have proven to affect the total success of a project; time, cost and scope..

Evelina Dovsten, Test session 1; Microscopic slides prepared with wine glass feet, 2017, blown glass, microscope slides, box for microscope slides, cut glass, marker pen, 90 x 90 x

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

The community Triangle - Success factors for leading Purposeful communities 26.04.2008 4.. Approach / strategies

We have in Section 3.3 presented an initialization algorithm for modes with derivative causality at one storage element and shown that the algorithm yields initial values for the

Thanks to the pose estimate in the layout map, the robot can find accurate associations between corners and walls of the layout and sensor maps: the number of incorrect associations

In a number of examples we show how to stabilize the zero dynamics of dierent systems by switching between dierent output zeroing controllers, where no continuous stabilizing