28
Survey of Terrain Generation and Approximation Algorithms Carleton University School of Computer Science COMP4905 - Honors Project By: Po Kong Lai Supervisor: Prosenjit. K. Bose April 12, 2011 1

Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Survey of Terrain Generation and Approximation Algorithms

Carleton University

School of Computer Science

COMP4905 - Honors Project

By: Po Kong Lai

Supervisor: Prosenjit. K. Bose

April 12, 2011

1

Page 2: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Abstract

Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is

therefore the problem of how to generate terrain such that it meets certain criterion. For example,

we could want to generate realistic looking terrain, that resembles the terrain we see on Earth, or we

could want to generate terrain that is suited for other worlds like Mars or the worlds inside a video

game. A realistic or detailed terrain usually contains millions of data points and thus we may want to

approximate the terrain using fewer data points yet still have the terrain maintain its shape. In this

project we explore how terrain can be represented, how terrain can be generated, the applications for

such a generated terrain and finally we look at a way to approximate terrain.

2

Page 3: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Acknowledgments

Firstly I would like to thank Prosenjit. K. Bose for his patience, guidance and constant source of

inspiration. Secondly, I would like to thank the many people who created tutorials for Java3D which

allowed me to get started on 3D programming quickly despite having no prior experience. Lastly I would

like to thank Boaz Ben-Moshe for making his implementation of the Delaunay triangulation available

to use.

3

Page 4: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Contents

1 Introduction 6

2 Implementation of Terrain Generation 7

3 Random Fractal Terrain Generation 8

3.1 1D Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3.2 Height Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3.3 2D Case - Diamond Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.4 Other Applications of Height Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 3D Model Creation 14

4.1 Tessellation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.2 Voronoi diagram and Delaunay triangulation . . . . . . . . . . . . . . . . . . . . . . . . 14

4.2.1 The Voronoi diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.2.2 Duality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.2.3 Delaunay triangulation and Terrain . . . . . . . . . . . . . . . . . . . . . . . . . 17

4.3 Java3D and Model Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

5 Levels of Detail 22

5.1 Hierarchy Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

5.1.1 Selecting Very Important Points . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

5.1.2 Hierarchy Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

6 Conclusions 27

4

Page 5: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

List of Figures

1 Screenshots of the main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Random fractal terrain in 1D with iterations i = 1→ 4. Note a rounded hill at iteration 4 9

3 Diamond Square at varying stages. (3a) shows the intial four corners. (3b) demonstrates

the first diamond step. If the terrain was rendered now we would see four diamonds

all converging at E. (3c) demonstrates the first square step. The computed midpoints

between the four corners are represented by blue dots. (3d) is the result of the first pass.

Now we have four squares so we repeat the diamond step for each square. (3e) shows the

result after applying the diamond step to all squares. Now we need to apply the square

step. The points for the first square are the blue points. The lines extend to K and L as

we need those points to wrap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Height maps at varying roughness levels . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5 Fractal Clouds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6 Voronoi regions bound by solid lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

7 Delauny triangulation is in black while the Voronoi diagram is in red. Source: Wikipedia 16

8 A violation of Circumcircle Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

9 Empty Circle Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

10 Local Maximum Miniumum Angle Property. . . . . . . . . . . . . . . . . . . . . . . . . 18

11 Some triangulations created by TerrainGenerator using Boaz Ben-Moshes Delaunay

triangulation library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

12 An example of a height map generated by TerrainGenerator using the Diamond

Square algorithm (iterations=6, roughness=0.5) and the accompanying 3D view of the

terrain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

13 The 3D terrain when we add sunlight and Gouraud shading. . . . . . . . . . . . . . . . 21

14 Height map that will be used to generate the hierarchy of terrains in the next figure. . . 25

15 Example of terrain with a hierarchy of levels of detail. . . . . . . . . . . . . . . . . . . . 26

5

Page 6: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

1 Introduction

Formally a terrain is the graph of a continuous function that assigns to every point on the plane an

elevation. Inituatively we can imagine terrain as a natural landscape which includes various features

like mountains, lakes and plains. Terrain in general is not limited to the natural Earth like landscapes

we are so accustomed to. It can also represent the landscapes of other planets with would thus bring

in different features unique to the chemical, and thus geograhical, structure of that world. Terrain

generation is a series of steps or an algorithm which may or may not take in parameters and the output

is a represetionation of a terrain. The main application for terrain generation would be anything in which

a terrain is needed. Thus the main application would be as geographic modelling as terrain generation

can create a random terrain which may include features that the user desires (such as mountains).

These generated terrains would then be used in aircraft simulations, video games and various other

applications such as Google Earth.

This report will start by describing several techniques to generate random fractal terrain and how

it was implemented in practice. For an object to be fractal it must display the self-similiar property on

all scales. In nature we can see many examples of fractal objects such as trees and thus fractal terrain

would represent natural looking terrian. To create a realistic looking terrain one would need millions of

points and triangles to recreate the level of detail needed. Hence once we examine how to create terrain

we will look at some techniques to approximate terrain so that it will retain it’s shape using less points

and triangles. This sort of approximation can be used to speed up terrain generation and rendering so

that it can be used for real-time applications or it can be used to allow zooming in and out of a terrain

to a more or less detailed terrain. The report will end with a summary of results obtained using the

different terrain generation and approximation algorithms along with what was learned in the process.

6

Page 7: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

2 Implementation of Terrain Generation

A terrain generator program, which will henceforth be refered to as TerrainGenerator, was

written to help study terrain generation. TerrainGenerator was coded in Java and utilizes Java3D

to display 3D models of generated terrain. The algorithms used in the program are outlined in the next

section. An example of what the program looks like can be see in Figure 1.

(a) Each button launches a new frame with the respective

generation technique

(b) Height Map (c) Rendered 3D terrain using height map from (b)

Figure 1: Screenshots of the main program

7

Page 8: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

3 Random Fractal Terrain Generation

A fractal is an object or quantity that displays self-similarity on all scales [1]. This self-similarity

property in the strictest sense does require that the object exhibit the exact same structure on all scales.

We can see this sort of self-similarity property all over nature in the trees, how the rivers are shaped

and even in our blood viens. Thus it is natural to use fractal generation technqiues to create terrain

which would serve as models for a given geographical world. However in nature the self-similiarity

property is more relaxed and allows for for small variations in the structure at different levels unlike

the purely mathematical fractals such as the Mandelbrot set. The main technique we will use to create

random fractal terrain utilizes midpoints and displacements the midpoints by a random factor. First

we will examine the 1D case and then we will look at the 2D case which will be the basis for a 3D

representation.

3.1 1D Case

Terrain in the one dimensional case would be a line which reaches from one end of the bounding

universe to the other. All we need to create a line are two points and thus any line can be considered

as terrain. Hence in general a terrain in one dimension can be seen as a set of lines such that the end

point of a line Li is the starting point for the next line Li+1. To generate a random fractal terrain in

1D we will use a midpoint displacement method. Thus if we let S be the set of all line segements which

represent the terrain and N be the number of steps we run the midpoint displacement method, the

algorithm to generate a fractal terrain in Algorithm 1.

While in essence a very simple algorithm the resulting terrain can be very complex. This is the

nature of fractals as a few simple instructions can create a rich and detailed terrain. The reduction in

the range of random numbers (line 7) is what gives the generated terrain is a measure of roughness.

That is to say if we reduce more with each pass of the loop we will have a smoother terrain and inversely

if we reduce less with each pass of the loop we have a rougher terrain. Examples of the generated 1D

fractal terrain can be see in Figure 2.

8

Page 9: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Algorithm 1 Random Fractal Terrain in One-dimension

1: Start with a single horizontal line segment L0 and add it to S.

2: for i = 1 to N do

3: for line L in S do

4: Find midpoint of L and let it be known as M .

5: Displace M by a random amount.

6: Let A and B be the start and end points of L, insert lines AM and MB in the place of L.

7: Reduce the range of the random numbers.

8: end for

9: end for

(a) Iteration 1 (b) Iteration 2 (c) Iteration 3 (d) Iteration 4

Figure 2: Random fractal terrain in 1D with iterations i = 1→ 4. Note a rounded hill at iteration 4

3.2 Height Maps

A common representation of a computer generated terrain is usually in the form of a height map. A

height map, in general, maps some indices to height values. Thus in the 1D case we can represent the

terrain as a one dimensonal height map which maps the x values to y values. Thus a height map in the

2D case would map the indices (x, z) to some height values y. This height map can be implemented

as a N × N array of values each of which represent an elevation given a particular position (i, j) in

the array. This is the main data structure which will hold the elevation values for the terrain in the

Diamond Square algorithm. Given a height map H and indices x and z, the elevation would have a

value of H[x][z]. Thus the indices of the height map provide us with the horizontal position in the

terrain where we would apply the elevation H[x][z]. Now that we know what a height map is. . . how

does one render it? A common way to render the height map is as an image and thus the N ×N array

which makes up the height map will produce an N × N image. We can color the values of highest

9

Page 10: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

elevation the brigthest colors while the values of lower elevation darker colors. This height map will

also be useful later when we create 3D models of the generated terrain.

3.3 2D Case - Diamond Square

Now that we have a definition for the height map let us examine the Diamond Square algorithm

which will produce a height map. We start with a large empty N ×N 2D array, denoted as H, which

will be completely filled and thus be a height map once the algorithm is complete. The dimension of

the array should be a power of two plus one and thus we have N = 2m + 1 where m will be refered

to as the step size. If we take the four corners of H and set their elevation values equally we have a

square. This is the starting point for the algorithm which is a two-step subdivision routine which will

be refered to as the DiamondSquare routine. The two steps are aptly named diamond and square

and are outlined below:

Diamond Step

Take the square shape produced by four points and generate a random value at the square midpoint

where the two diagonals meet. This midpoint value is calcuated by averaging the four corner values

plus a random amount. This step produces diamond shapes in the grid we we have multiple

squares.

Square Step

Take each diamond shape produced by four points and generate a random value at the center of

the diamond. The mindpoint value is calculated by taking the average of the four points plus

a random amount. This random amount is in the same range as the diamond step. This step

produces squares which will be used in the next diamond step.

Suppose we take our starting square again, with each of the corners seeded with the same value,

and we make a single pass through the subdivision routine. The result would be four squares. Run the

subdivision routine again on this output and we would get 16 squares. Once more and we would have

64 squares and thus we can see that the number of squares genereated is exponentially proportional

to the number of times we run through the subdivision routine. Figure 3 illustrates how the Diamond

Square method works visually.

Initially looking at the DiamondSquare routine we may be inclined to implement it recursively.

However, there are advantages to implememting DiamondSquare iteratively. Algorithm 2 and algo-

10

Page 11: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

(a) Initial square. (b) First diamond step. (c) First square step.

(d) Now we have four squares. (e) Extension for wrapping.

Figure 3: Diamond Square at varying stages. (3a) shows the intial four corners. (3b) demonstrates

the first diamond step. If the terrain was rendered now we would see four diamonds all converging

at E. (3c) demonstrates the first square step. The computed midpoints between the four corners are

represented by blue dots. (3d) is the result of the first pass. Now we have four squares so we repeat

the diamond step for each square. (3e) shows the result after applying the diamond step to all squares.

Now we need to apply the square step. The points for the first square are the blue points. The lines

extend to K and L as we need those points to wrap.

rithm 3 describes a recursive implementation and an iterative approach respectively. While algorithm

2 is a simple implementation it requires that some points be generated with insufficient data. This can

be seen after the first pass since we will need to do a square step before having all four corners of a

diamond. This problem can be avoided with an iterative approach such as the one below.

This iterative approach fixes the problems found in the recursive approach but the problem of

missing data will occur once again if we are generating a point on the edge of H. This is only an issue

in the square step and is solvable by taking into account that one of the four diamond points is wrapped

11

Page 12: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Algorithm 2 Recursive Diamond Square

1: Do diamond step.

2: Do square step.

3: Reduce random number range.

4: Call Recursive Diamond Square four times.

Algorithm 3 Iterative Diamond Square

1: while Length of the side of the squares > 0 do

2: Run through H and perform the diamond step for each square present.

3: Run through H and perform the square step for each diamond present.

4: Reduce random number range.

5: end while

around on the other side of H.

In line 5 of the Iterative Diamond Square we reduce the random number range and this reduction

can be encapuslated in constant which we denote as r. That is to say that r will determine how much

the random number range is reduced each time and thus will determine the roughness of the resulting

terrain. Hence, r is the roughness constant and at each iteration i of DiamondSquare we have the

following: −ri ≤ X ≤ rn where X is the random amount to be added. Thus as we add finer detail to

our height map H we reduce the scale of the changes we make. Hence small changes at a small scale

are similar to large changes at a larger scale. This is the self-similairy property mentioned eariler that

is found in fractals. Figure 4 displays a few height maps at different roughness levels.

(a) r = 0.25 (b) r = 0.50 (c) r = 0.75

Figure 4: Height maps at varying roughness levels

12

Page 13: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

3.4 Other Applications of Height Maps

While it may be nice generating random fractal terrain sometimes we may want to have certain

features on the terrain such as mountains and lakes. This can be done by seeding the desired location

for the features with the appropriate value in the height map. Mountains would be seeded with their

peak value at the peak location and water basins can be accomplished by seeding as many key points

needed in order to create the desired size of water basin. A threshold height can then be defined so

that we can determine which parts of the terrain will be filled with water.

Given a height map H one can say that the values represent the elevation at a particularly point.

However, if one were to think of the values as representing not height but rather opacity, then we

have an opacity map. Such an opacity map can be used to create fractal clouds as each value in the

map would represent cloud opacity data. A rendering of this opacity map could have the lowest values

colored as blue and the highest values colored as white. This rendering of the opacity map would

produce a texture map which we can apply to the sky. Thus the height map generated with random

fractal techniques can be used to create an entire world with the terrain being the 3D mesh of a height

map and the sky a texture map generated from a height map that was converted to an opacity map.

Figure 5 shows an example of clouds generated by a height map.

Figure 5: Fractal Clouds

13

Page 14: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

4 3D Model Creation

The goal of terrain generation is often to create a 3D model of the generated terrain. Java3D was used

as 3D rendering is not possible in standard Java without having to write your own 3D rendering engine.

Java3D provides a simple way to create a frame which contains an area to display 3D objects with their

SimpleUniverse class. All 3D objects must be contained within what is called a BranchGroup for

it to be rendered onto the screen. Java3D also provides a Shape3D class which allows for creation of

custom 3D shapes given some geometry data. This geometry data would specifiy the points of the shape

and how to build it. The geometry used for TerrainGenerator is a list of triangles which together

create the terrain. We will now look at a few ways to create the triangulation which will represent the

generated terrain.

4.1 Tessellation

A tessellation or tiling of a plane is a pattern of plane figures that fills the plane with no overlaps

and no gaps [2]. Given a height map H one could tessellate using squares which works naturally as the

indices of H would create a grid. We will use triangles however so each square in the grid would be

composed of two triangles. The use of triangles allows for better approximation of the actual terrain

when compared to squares. This is because squares are not flat in 3D space. If we were to consider

four random points in space there is a very low probablity that they will all be coplanar. In contrast

we can guarantee that any three points in space will be coplanar. Therefore we will use triangles for

basic tessellation.

Now that we have decided on what shapes to use in the tessellation of a height map, let us examine

an algorithm which will produce this tessellation. Such an algorithm is outlined in Algorithm 4. Looking

at algorithm 4 we can see it runs in O(k2) where k is the length of the side of the height map or in

O(n) where n is the number of points in the height map.

4.2 Voronoi diagram and Delaunay triangulation

In this section we first introduce the notion of a Voronoi diagram and then give the duality prop-

erties of the Delaunay triangulation. We will then see the Delaunay triangulation can be used with

triangulating terrains.

14

Page 15: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Algorithm 4 Height Map Tessellation

1: Let k be the side length of the generated height map H.

2: Let T be a list which will contain all the triangles.

3: for i = 0 to k − 1 do

4: for j = 0 to k − 1 do

5: T.append(Triangle[(i, j,H[i][j]), (i+ 1, j,H[i+ 1][j]), (i, j + 1, H[i][j + 1])])

6: T.append(Triangle[(i+ 1, j,H[i+ 1][j]), (i+ 1, j + 1, H[i+ 1][j + 1]), (i, j + 1, H[i][j + 1])])

7: end for

8: end for

4.2.1 The Voronoi diagram

Let P = {p1, p2, p3, . . . , pn} be a set of points in the plane. Each point is called a site and a region of

the plane is obtained by assigning every point to its nearest site pi. Such a region is called the Voronoi

cell or region and is denoted as V (pi). Formally we define V (pi) as the following:

V (pi) = {x ∈ R : d(x, pi) ≤ d(x, pj),∀i 6= j

To understand the above better consider the simplest case with two sites, a and b in the plane. If l is

the bisector of the two sites then l divides the plane into two halfplanes. Let H(a, b) be the halfplane

that contains a. Then we have that any point p in H(a, b) would have the site a as its nearest neighbor

and thus we have V (a) = H(a, b). Similiarly we would have V (b) = H(b, a). Thus the Voronoi diagram

V D of a set of sites P is defined as the partition of the plane induced by all the Vonoroni regions V (p)

where p ∈ P [3]. Figure 6 shows this example along with another example with three sites.

The Voronoi diagram has many applications with its innate geometric proximity properties. It can

be computed in O(nlogn) with a planer sweep algorithm [3] with n being the number of sites. The

Delaunay triangulation also arises naturally from a Voronoi diagram which we will describe in the next

section.

4.2.2 Duality

In 1934, Delaunay proved that the dual graph of the Vonroni diagram produces a triangulation of

the Voronoi sites P [4]. The trianglation is now better known as the Delaunay triangulation. The dual

of a planar graph G(V,E) is a graph where each face in G is represented by a vertex and for each edge

15

Page 16: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

(a) P = (a, b) (b) P = (a, b, c)

Figure 6: Voronoi regions bound by solid lines.

e ∈ E we draw an edge between the verices that represent the faces which share e. Given a list of

sites P we denote V D(P ) as the Voronoi diagram of P and DT (P ) to be the Delaunay triangulation

of P . Listed below are the duality properties which links the Voronoi diagram and its dual graph the

Delaunay triangulation into a one to one correspondence between vertices, edges, and faces.

1. DT (P ) is the dual graph of V D(P )

2. Every vertex in V D(P ) is linked to a triangle in DT (P ).

3. Every edge of V D(P ) is linked to an edge in DT (P )

4. Every region of V D(P ) is linked to a vertex in DT (P )

5. The convex hull of P bounds DT (P )

6. No triangle of DT (P ) contains within it a site of P .

Figure 7: Delauny triangulation is in black while the Voronoi diagram is in red. Source: Wikipedia

16

Page 17: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

4.2.3 Delaunay triangulation and Terrain

There are some interesting properties of the Delaunay triangulation which would be useful to dicuss

before looking at the applications to terrain. These properties are described below:

Circumcircle Property

Let (pa, pb) be an edge that is incident to triangles ∆papbpc and ∆papbpd as show in Figure 4.3.1.

The edge is considered illegal if pd lies in the interior of the circumcircle of ∆papbpc or pc in that

of ∆papbpd. No illegal edges are allowed in the triangulation and thus the circumcircle of any

triangle in the Delaunay triangulation is empty (contains no sites of P ).

Figure 8: A violation of Circumcircle Property

Empty Circle Property

If an empty circle can be formed in such a way that it passes through sites pa and pb, then the

edge (pa, pb) is in the triangulation DT (P ). This is true since if two sites pa and pb are incident in

the Delaunay triangulation, then their cells are incident in the triangulations dual graph. Thus,

given any point pi on the Voronoi edge between pa and pb, a circle centered at pi passing through

pa and pb cannot contain any other point (since they must be closest).

Figure 9: Empty Circle Property

17

Page 18: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Local Maximum Miniumum Angle Property

Suppose we have a triangulation T and let (pa, pb) be an edge in T such that it is shared by

triangles ∆papbpc and ∆papbpd. Let M be the quadrilateral formed by the two triangles and for

1 ≤ i ≤ 6 let θi be an the ith angle in M and αi be an the ith angle in M ′ where M ′ is formed by

flipping the diagonal of M . We say the edge (pa, pb) satisfies the local min-max angle property if

min(αi) ≤ min(θi)∀1≤i≤6.

(a) M (b) M ′

Figure 10: Local Maximum Miniumum Angle Property.

With respect to terrain, the Delaunay triangulation allows for a non-grid like triangulation of points.

Thus the terrain is not limited to a height map but rather a list of points (and from those points a

list of triangles which form the triangulation). The local maximum miniumum angle property works

well with terrain since it reduces robustness problems and aliasing problems when rendering [6]. The

triangulation can also be computed in O(nlogn) and some of these algorithms are described in the

lecture notes by David M. Mount [5]. In TerrainGenerator the main data structure is still the

height map for the highest level of detail even if the triangulation method is Delaunays. Varying levels

of detail is discussed in the next section. The Delaunay triangulation used in TerrainGenerator is

computed using the implementation by Boaz Ben-Moshe[7]. The reason for using an external library

is because many of the O(nlogn) algorithms are difficult to implement and require lots of code. The

implementation by Boaz Ben-Moshe also handles triangulations of size 105 vertices in a few seconds and

thus would be ideal for generating detailed terrain. Figure 11 shows two examples of triangulations.

18

Page 19: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

(a)

(b)

Figure 11: Some triangulations created by TerrainGenerator using Boaz Ben-Moshes Delaunay

triangulation library.

19

Page 20: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

4.3 Java3D and Model Implementation

Now that we have described regular triangular tessellation and the Delaunay triangulation we can

describe how the model was created in Java3D. As stated eariler, Java3D provides us with a Shape3D

class which allows us to build 3D shapes assuming have the right geometries. The N ×N height map is

built from algorithm 3 and is used to serve as the point set for tessellation and Delaunay triangulation.

Figure 12 shows an example height map and terrain in 3D built by TerrainGenerator.

(a) Height Map (b) 3D Terrain View

Figure 12: An example of a height map generated by TerrainGenerator using the Diamond Square

algorithm (iterations=6, roughness=0.5) and the accompanying 3D view of the terrain.

While the above is a nice representation of the terrain we are still missing something. Terrain in the

geographical sense is usually lit up by sunlight. The terrain in Figure 4.4.1 shows no such lighting as

there are no shadows. To light up a Shape3D in Java3D one needs to apply a material to the object. A

material describes how different types of light will bounce off the object and the material is set through

the Appearance of the object. One also sets the shading mode through the Appearance which is

used to determine the shading when light is present. Once the material is applied and the terrain is

re-rendered we are left with what appears to be a black blank screen. This is because we have not

added lights to our scene yet! Java3D provides a way to define different types of lights and the one

used in TerrainGenerator is the DirectionalLight which represents a sun ray from a window.

After all the set up we finally have our new terrain rendered with proper light and shading as seen in

Figure 13.

20

Page 21: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Figure 13: The 3D terrain when we add sunlight and Gouraud shading.

21

Page 22: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

5 Levels of Detail

Many applications require not only a detailed and realistic terrain, but one that can also scale. This

need for scaling can be best seen in aircraft simuations where it would be ideal to use less triangles when

viewing terrain from afar (and thus needs less detail) and more triangles we the aircraft approaches the

ground. Detailed in the next section is an approach by Mark De Berg and Katrin T.G.Dobrind based

on a hierarchy of Delaunay triangulations [6].

5.1 Hierarchy Approach

Given a collection of n data points in the plane, each with its own elevation, we wish to automatically

compute a hierarchy of levels with the most detailed level corresponding to the triangulation of all n

data points and the least being a small subset of the points[6]. This hierarchy should have a small

approximation error between each level as we want the terrain to look roughly the same at all levels

of detail. Mark De Berg and Katrin T.G.Dobrind use the Delaunay triangulation for each level as

the triangulation has the local maximum miniumum angle property and the triangulation gives a good

approximation since it links points by proximity. The hierarchy can be represented as a directed acyclic

graph where each node in the graph correspond to the triangles in the hierary. An arc connects to

triangles at one level to the next if these triangles intersect. Figure 5.1 illustrates this. The data

structure used in TerrainGenerator to store the different levels of detail is a hash table with the

indices corresponding to the level of detail and the values being the triangulation of that level of detail.

While this means that more memory is used, the code is less complex and thus easier and quicker to

implement.

Now that we have described what the hierarchy is, we can look at how the hierarchy can be con-

structed. We start with an initial triangulation which will be the most detailed level of terrain and uses

all n data points. To go to the next most detailed level we remove a number of non-adjacent vertices

and the triangulation is retriangulated. By using non-adjacent vertices we can then combine different

levels of terrain into one representation. This can be done by selecting small groups of triangles from

different levels instead of individual triangles. To better help keep the shape of the terrain we can fix

certain vertices such that they are present throughout all levels of detail. Different methods could be

used but the one choosen for TerrainGenerator was the very important points (VIP) method[8].

This algorithm is outlined in section 5.1.1. The algorithm to actually construct the hierarchy is detailed

22

Page 23: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

in section 5.1.2.

5.1.1 Selecting Very Important Points

Given a height map H we know that, without loss of generality, each cell has 8 neighbhor cells.

These 8 neighbouring cells form the 4 opposite pairs up-down, left-right, and the two diagonals. Given

a point a let us denote the set of 4 opposite pairs for a as M(a). Given this we can select some very

important points as outlined in algorithm 5.

Algorithm 5 Very Important Points Selection

1: Let α be a constant that will bound the number of points to be fixed.

2: Let β be a constant that will bound the significance limit.

3: for Each point p in H, examine the set M(p) do

4: Connect each pair in M(p) by a straight line and compute the perpendicular distance from the

central point to the line.

5: Average the four distances obtained from M(p) and label this as the significance for the point.

6: end for

7: while The number of points is < α or all points are < β in terms of significance. do

8: Remove points in order of increasing significance with the least significant first.

9: end while

5.1.2 Hierarchy Construction

A sequence of Delaunay triangulations DTk, . . . , DTi, . . . , DT0 can be considered a hierarchical rep-

resentation if each of the triangulations from level k → 0 progressivly get finer until we reach the finest

level of detail DT0. The bottom-up construction of the hierarchical representation starts with the finest

level DT0 which is the Delaunay triangulation of the given set of n points. Let Vi be the vertices of

DTi. To get the next level of detail we must first find a new vertex set Vi+1. The vertices of Vi+1 is

obtained by removing a maximal independent subset Ii of Vi where each vertex has degree of at most d

where d is a constant. The constant that Mark de Berg and Katrin T.G.Dobrindt use is d = 12 which

is the constant TerrainGenerator uses. The maximal independent subset Ii is the set of pairwise

non-adjacent vertices of Vi and if no other vertex of Vi can be added to it while keeping all vertices

pairwise non-adjacent. The set Ii thus contain vertices that, when removed, would leave ”holes” in the

23

Page 24: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

original triangulation. Hence DTi+1 can be obtained by finding Ii, removing all v ∈ Ii from Vi. Then

the new Vi becomes Vi+1 and all we need to do to get DTi+1 is to re-triangulate DTi and thus fill in the

holes. We stop the recursive construction of the hierarchy when the set Vi is c times larger then the set

of fixed points. Thus we can see that there is a trade off between accuracy and vertex reduction - the

more vertices are fixed, the more accurate the representation and thus less vertices are removed.

Given a terrain T that is represented as a Delaunay triangulation of a set of vertices V and a set of

fixed vertices Vfixed ⊂ V , the hierarchy construction algorithm is described below [6].

Algorithm 6 Construct Terrain Hierarchy

1: Let i = 0, Vi = V and DTi = DT (V )

2: while |Vi| ≥ c× |Vfixed| do

3: Vi+1 = Vi

4: DTi+1 = DTi

5: Determine a maximal set Ii of non-adjacent vertices of Vi \ Vfixed such that each vertex has at

most degree d.

6: for all vertices v ∈ Ii do

7: Remove v from Vi+1.

8: Remove v and all its incident edges and triangles from DTi+1.

9: Retriangulate the surrounding polygon so that the Delaunay properties still hold.

10: Add new edges and triangles to DTi+1.

11: Create an arc of the hierarchy between a triangle of DTi incident to v and a new triangle if

their interiors intersect.

12: end for

13: i = i+ 1

14: end while

The algorithm used in TerrainGenerator is roughly the same but does not create arcs as the

data structure which stores the hierarchies is not a direct acyclic graph but a hash table HT where

HT [i] = DTi∀i>0 assuming there is a DTi constructed. The external package which computes the

Delaunay triangulation for TerrainGenerator does not contain with in it the possiblity of removing

vertices, triangles or edges from the triangulation. Thus the algorithm was adpated and triangulation

DTi+1 is not created by re-triangulating just the polygon but is created anew from the new set of vertices

24

Page 25: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

Vi+1. This leads to a slower runtime but makes the algorithm easier to implementation. Examples of

different levels of detail for a terrain is show in Figure 15 along with the height map which was used to

produce the 3D model.

Figure 14: Height map that will be used to generate the hierarchy of terrains in the next figure.

25

Page 26: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

(a) Triangulation of terrain (b) Initial Terrain (8190 triangles)

(c) Triangulation of Level 3 (d) Level 3 (5958 triangles)

(e) Triangulation of Level 5 (f) Level 5 (1852 triangles)

Figure 15: Example of terrain with a hierarchy of levels of detail.

26

Page 27: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

6 Conclusions

This project has covered the main techniques used to create random fractal terrain that can scale

to various levels of detail. The terrain geneator program, TerrainGenerator, was writen for this

project to helps study the techniques and can serve as a learning tool for others who are interested.

While the code for TerrainGenerator is not optimal, it is sufficiently fast for a decently sized height

map. It was found that number of iterations for ”best” results in terms of speed and terrain detail is six.

This is because if we increase the number of iterations the number of cells in the height map increases

exponentially. Generating the height map itself is relatively fast even for iterations of 10 or more. It

is the computation of the triangulation and creating the 3D model which is the cause of performance

issues. This is because the triangulation takes O(nlogn) where n is the number of points. After 10

iterations we would have 210 + 1 as the side length of the height map and thus the number of points

is (210 + 1)2. This performance issue is especially noticable when one uses over 7 iterations for the

height map and then contructs the hierarchy of levels of detail. Since each level must re-triangulate

a sub-set of the entire point set as TerrainGenerator uses a slightly diferrent approach explained

in section 5.1.2. However once the model and hierarchy is created we have the hash table of all the

triangulations and switching levels of detail becomes O(1). Java3D handles the rendering well even

with a large number of triangles and so along with the hast table approach moving from one level of

detail to another is nearly seemless.

Overall this project was very enjoyable to work on and over time I look forward to improving

TerrainGenerator. Future work could include using a height map to generate fractal cloud texture

maps which we can apply to a polygon to give the apperance of a sky, adding a threshold limit so that

we can add water, wrapping the generated terrain around a sphere and thus we could generate planets

with random terrain (or if we so choose to we can fix a number of vertices to get the features we want).

27

Page 28: Survey of Terrain Generation and Approximation Algorithms · Abstract Terrain, in nature, is a vertical and horizontal dimension of land. Terrain generation problem is therefore the

References

[1] Weisstein, Eric W. ”Fractal.” From MathWorld–A Wolfram Web Resource.

http://mathworld.wolfram.com/Fractal.html, Retrived April 2011.

[2] Weisstein, Eric W. ”Tessellation.” From MathWorld–A Wolfram Web Resource.

http://mathworld.wolfram.com/Tessellation.html, Retrived April 2011.

[3] Smid, Michiel. ”Voronoi diagrams and their construction using plane sweep”, 21 October 2003.

[4] Wikipedia, ”Delaunay triangulation.” From Wikipedia Web Resource.

http://en.wikipedia.org/wiki/Delaunay triangulation, April 2011.

[5] Mount, David M., ”CMSC 754 - Computational Geometry” From Department of Computer Science,

University of Maryland, 2005.

[6] Mark de Berg, Katrin T.G.Dobrindt, ”On Levels of Detail in Terrain.”, 29 October 1997.

[7] Ben-Moshe, Boaz. ”Delaunay Triangulation in Java” Web Resource. http://www.cs.bgu.ac.il/ ben-

moshe/DT/Delaunay Triangulation in Java.htm, Retrived March 2011.

[8] Chen, Z., and J.A. Guevara, 1987. ”Systematic selection of very important points (VIP) from

digital terrain models for construction triangular irregular networks,” Proceedings, AutoCarto 8,

ASPRS/ACSM, Falls Church, VA, pp. 50-56. A description of ESRI’s VIP approach to constructing

a TIN.

28