











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












ii
Figure 2-1 Midpoint Displacement in 1D when h=0.0, n=5, height range=100................. 9 Figure 2-2 Midpoint Displacement in 1D when h=1.0, n=5, height range=100................. 9 Figure 2-3 Wire frame image of a terrain generated using the Midpoint Displacement algorithm, number of subdivisions= 8 and the maximum height range= 500 .......... 12 Figure 2-4 The first step in fault formation algorithm [3] ................................................ 13 Figure 2-5 Terrain generated using fault formation, the number of faults=64 and height scale=20 .................................................................................................................... 15
This document provides a description of the work carried out in the first phase of the project. The time line from July 2007 to October 2007 comprised the first phase of the project in which terrain generation techniques were explored as well as implemented. In the course of this exploration the concept of Solid textures was encountered. Using Solid textures we think of a virtual object as it is carved out of a virtual solid material defined by the procedural texture. Natural terrains have an infinite detail i.e. small rock edges resemble the sky line of a mountain; therefore Fractal geometry is used to define terrain geometry because Fractal Geometry incorporates dilation symmetry i.e. an object is invariant under change of scale. In short there is an infinite detail in the geometric model itself. While the simplest model for the terrain is the two dimensional height map, the problem does not lie in defining the exact terrain model rather the visual detail that can be added to the terrain is a problem. There exists a limit up to which a phenomena can be modeled i.e. we cannot define each and every feature of the terrain in a single model for example it is difficult to model the grass grown on a terrain. Much of visual detail is defined by applying textures, but ordinary textures only add a pattern of colors to the terrain. A type of textures called the procedural textures or solid textures is used to add enough roughness to the terrain model or any model in general. This roughness is a controlled parameter. We can control how much and in what appearance the roughness should be applied.
This section describes the modeling approaches used for terrain generation.
There are two polar extremes in approaches to modelling:
Our world is visually complex. Reproducing this complexity in synthetic images is a major task in computer graphics. Fractals represent the natural phenomena in terms of equations that efficiently encapsulate lots of complexity found in nature. This encapsulation is usually in the form of recursive routines: a way that is exquisitely suited to the capabilities of the digital computer.
Although fractals can be used to model much of the complexity found in nature they are not the end-all for creating realistic synthetic images. Fractal geometry is mathematics, but it can be approached entirely heuristically: no understanding of the underlying formulas is required. A fractal can be defined as a geometrically complex object whose complexity arises through the repetition of a given form over a range of scales.
frequency = 2i amplitude = persistencei It is not necessary for an object to have infinite detail to qualify as a fractal: as long as something displays self-similarity over some, albeit small, range of scale, it may qualify as “fractal.” There exists a size limit above which self-similarity ceases to manifest itself; this is called the upper crossover scale. Similarly, there is a smaller size limit below which self-similarity no longer is manifest; this is the lower crossover scale. All fractals in nature are band-limited i.e. they are fractal only over some limited range of scales. For example, Earth has many mountain ranges that are quite fractal but when seen from a distance in space the earth appears smoother than a glass marble. All fractals for computer graphics must also be bandlimited, for two reasons: First, spatial frequencies that are higher than half the pixel frequency (the screen width divided by resolution) may violate the Nyquist sampling limit and cause aliasing Second, it is a poor programming practice to use an infinite loop that would be required to construct non-band-limited fractals.
1.3 Fractional Brownian Motion (fBm)
Fractional Brownian Motion is a random fractal function which resembles the skyline of a mountain range. This similarity between fBm and the skyline of mountain peaks was first observed by Benoit Mandelbrot. Pure fBm is by design homogeneous and isotropic. These two properties of pure fBm are in contrast with the properties of the real terrains, which are non homogeneous and an-isotropic. However it is possible to control the fBm to generate terrains which have the same properties as the real terrains. Two such fractal techniques called the monofractals and multifractals exist. fBm is characterized by its power spectrum, which shows exactly how amplitude relates to frequency.
V(t) f
(^) Af^ rfH^ sin(2πr-f^ t f )
This is a Weierstrass-Mandelbrot function which describes the fractional brownian motion. Here A is a Gaussian random variable, r is the lacunarity, θ is a uniform random
viable in the range [0,2π ] providing a random phase, and H is the Hölder exponent, which determines the fractal dimension. The Weierstrass-Mandelbrot defines the fBm as an infinite sum of sine waves at discrete frequencies and with random phase, with a certain size gap between successive frequencies (the lacunarity), and an exponent H which scales amplitude by frequency. Amplitude relates to frequency f by the plot of the power spectrum SWM ∝ 1/f H+ and hence the result is referred to as 1/ f noise.[1]
1.4 Origins of Fractal Terrain Models
The fBm was chosen as a model for representing the terrain phenomenon. This choice was based entirely on the ontogenetic approach to modeling i.e. fBm resembled the skyline of a terrain. There is no known generative link between the shape of fBm and that of real landscapes. Fractal descriptions of natural phenomena are usually defined this way, using the ontogenetic approach.
1.5 Limitations of Fractional Brownian Motion
On the large scale real terrains are heterogeneous: mountains can rise out of flat plains, preceded by rolling foothills. Moreover there exist distinctive terrain features generated by erosive processes. In real terrains there is asymmetric across the horizontal plane as mountains and valleys have different roughnesses. In short real terrains are non homogeneous and an-isotropic. Pure fBm properties are totally contrary to the properties of real terrains so it can be concluded that pure fBm is only an approximation of real terrains. Pure fBm provides the randomness that can be observed in real terrains, but a keen observation reveals that the non homogeneous and an-isotropic properties of the terrain cannot be modeled using pure fBm.
1.6 Monofractals
Using monofractals it is possible to create fBm by successively adding the basis function with the condition that the frequency of the basis function is reduced by an amount H, at
Midpoint displacement as the name implies is a technique used for creating Fractal Mountains using a recursive subdivision scheme. The technique was developed by Fournier, Fussell, and Carpenter. In midpoint displacement we take a line segment along the x-axis and divide it into two equal halves. The mid-point is displaced along the y direction. The midpoint divides the line segment into two and each half is treated as a single line segment. In the next step the two halves are divided and their mid-points moved in the y direction. We repeat the process a number of times to achieve the desired effect. :
xnew = (xi + xi+1)/ ynew = (yi + yi+1)/2 + Rand*2(-H)
H is the roughness constant whose value can vary from 0.0 to 1.0 and R is a random number. If we set H=0.0 then 2(-0.0)^ would give us 1 and the random number range would not be reduced at all, and if we set H=1.0 then 2(-1.0)^ would result in 0.5 and the random number when multiplied with 0.5 will be halved. An extension of this algorithm is called the diamond-square algorithm.[9]
Midpoint Displacement in one dimension has been implemented using the technique explained above. I have created a function which divides the initial line segment and then calls itself in a recursive manner to divide each resulting line segment that is created. The number of times the recursion takes place is controlled by a variable whose initial value is set outside the function and every time the function is called the value of this variable is reduced. When the value of this variable becomes zero the display function is called which displays the perturbed line, which was initially a horizontal line.[9]
2.1.1.1 Pseudo code
In this section I present the pseudo coed for the function that actually calculates the midpoints and displaces them in the y direction and which controls how many times the function should be called. Here n is the parameter which controls the number of recursions and h is the roughness constant; the amount by which the random number range is reduce in every function call.
Initialize n //number of subdivisions Initialize h // roughness constant Divide_Segment { while (n>0) { divide line segment raise the midpoint in y direction=rand () %random number range reduce random number range = (rand ()%random number range )*2(-h) n=n- call Divide_Segment } display } As discussed in the previous section if we set H=0.0 the result generated is shown in Figure 2-1. Here the subdivisions are performed 5 times and the maximum height range is 200.This is a very jagged result because the height range (from 0 to the maximum height) is not reduced at all, meaning that totally random values are selected from the height range resulting in a jagged output.
Number of divisions n
n=
n=
n=
n=
n= Result The height range is not reduced at all thus resulting in a jagged output
The height range is reduced by half every time the subdivision routine is called thus resulting in a mountain like output Table 2-1Comparison of the Effect of the Roughness Constant H
Note that the midpoint generated after the first pass is visible throughout the rest of the passes, the reason for this is that when the initial horizontal line is divided this value remains the same throughout and it is never changed. This is known as the creasing problem.
In diamond-square algorithm or the plasma fractal algorithm we perform midpoint displacements on a two dimensional array containing the height values. Initially the four corner values of the array are assigned height values. A 2D midpoint displacement is performed in two steps i.e. the diamond step and the square step. In the diamond step we average the four corners of the square which gives us the midpoint of the square. Then this midpoint is displaced in the y direction. This results in imaginary diamond shapes. The diamond step is followed by a square step. In the square step we calculate the center of each diamond by averaging the height of each corner and displace the result in the y direction. This results in imaginary square shapes. The displacements in the y direction are calculated by multiplying a random number with 2(-H)^ where H is the roughness constant. This completes one pass. In the next pass and in each successive pass the random number range is reduced by the factor 2(-H). If we start with a square and make a single pass through the subdivision routine, we would end up with four squares. Running it twice would yield 16 squares. A third pass would result in 64 squares. The number of squares generated is equal to 2(I+2), where I is the number of iterations through the recursive subdivision routine.[9]
Iterations=1 Iterations=2 Iterations=
Table 2-2 Number of Squares Generated in Each Pass of the Diamond-Square Algorithm
2.1.2.1 Pseudo code
Initialize k //number of subdivisions
2.2 Fault Formation
Fault Formation algorithm generates fractal data by repeatedly dividing the terrain with a faulting edge. A height difference along the fault edge is created by raising the terrain on one side of the fault edge and lowering it at the other side. Figure 2-4 shows the first step in fault formation. We begin by adding a random line to the height field and then adding a random height to any one of the two sides of the line. We evaluate only one side of the line and raise the height value of every point on that side of the line. This random height decreases linearly with every fault pass.
Figure 2-4 The first step in fault formation algorithm [3]
To raise the height value of every point on one side of the line, we loop through all of the height values for the entire height map. We define a vector that goes in the direction of the line, this vector is defined by Dirx1=randx2-randx Diry1=randy2-randy We define another vector from the initial random point (randx1, randy1) to the current point in the loop (x, z). Dirx2=x - randx Diry2=y - randy Then we take the cross product of the two vectors: (Dirx1, Diry1) x (Dirx2, Diry2) =iDirX2iDirZ1 - iDirX1iDirZ
For all values of x and y for which the above cross product is greater than zero are assigned a random height which is calculated from the following formula. Height = (h_max+1)-(((h_max - h_min)*Current fault pass)/total number of faults)
2.2.1.1 Pseudo code
divide_terrain (2Dpoint pt1, 2Dpoint pt2, k) { 2Dpoint dir1, dir k=Number_of_Faults h=h_max a[D][D]; while (k>0) { dir1=pt2-pt1 //direction vector along the fault edge for( i=0; i<D; i++ ) { for( j=0; j<D; j++ ) { dir2= (i-pt1[0], j-pt1[1]) //another vector from every x, y // point to the initial point pt Cross_Product=(dir1dir2) if(Cross_Product >0) { a[i][j]+=h } } }// Completes one fault Edge h= (h_max+1)-(((h_max-h_min)k)/Number_of_Faults) //reduce height k=k-1; pt1= (random, random)//choose two random points for the next Fault edge pt2= (random, random) }
2.2.1.2 Results
Table 2-3 shows the height maps generated using the fault formation algorithm. A height map is a two dimensional image which defines the height for every vertex in the terrain.
[1] F. Kenton Musgrave, “Methods for realistic landscape imaging” , 1993 [2] David S. Ebert, F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, Steven Worley, “ Texturing and modeling a procedural approach” , 3rd^ Edition , Morgan Kaufman, 2002 [3] Trent Polack, “Focus On 3D Terrain Programming” , 2003 [4] Peter Sbarski, “Deformable Terrain Generation for Real-Time Simulation” , [5] Christoph Hormann, “Christoph's page - Terrain Simulation Links” http://www.imagico.de/terlinks.html [6] Hugo Elias , “Perlin Noise” http://freespace.virgin.net/hugo.elias/models/m_perlin.htm [7] Matt Zucker, “The Perlin noise math FAQ” http://www.cs.cmu.edu/~mzucker/code/perlin-noise-math-faq.html [8] Ken Perlin, “Making Noise”, http://www.noisemachine.com/talk1/index.html [9] Paul Martz, “Generating Random Fractal Terrain” http://www.gameprogrammer.com/fractal.html Wikipedia