3D Terrain Generation - Department of Electrical Engineering

download report

Transcript 3D Terrain Generation - Department of Electrical Engineering

3D Terrain Generation
Pablo Saldarriaga
CSE4431
Why virtual terrains?


There are many applications for 3d terrains
Just to name a few








Virtual tourism and travel planning
Education
Civil engineering, urban planning
Weather visualizations
Real Estate
Games
Movies
Placement of communication signal towers
Background

The defense industry created virtual terrains as early as the 1970’s


TINs (Triangulated Irregular Networks) appeared in 1973, developed by
Randolph Franklin at Simon Fraser University


TIN : vector based representation of the physical land surface or sea bottom
In the 1980’s procedural techniques are developed and they are used to
generate artificial terrains


Their purpose were ballistics and training simulations
This was the time Perlin created his noise functions
It was only until the late 1980’s that fractals and polygonal subdivision
techniques started to become more widespread in artificial terrain
generation
Military simulation software SIMDIS
Triangulated Irregular Network(TIN)
Emil Multifractal terrain
by Kenton Musgrave

A virtual terrain generated using Terragen 2 from
Planetside software
Image created by Hannes Janetzko.
http://www.planetside.co.uk/gallery/f/tg2/Hannes-Another+jungle+flyover.jpg.html
How are virtual terrains generated?

Heightfields



games and simulators use heightfields as a rough terrain model

This lecture will be focused in this approach
Voxels


Widespread approach for generating virtual terrain
Volume based values in a 3D grid
Meshes

TIN’s, tesselation schemes such as ROAM (Realtime optimally adapting mesh)
and other LOD(Level of Detail) techniques
ROAM
Voxel Terrain
ROAM : Inventor Projects 2006, http://merlin.fit.vutbr.cz/wiki/index.php/Inventor_Projects_2006
Voxel Terrain: Generating Complex Procedural Terrains Using the GPU,
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html
Topics

Glsl vertex displacement using height maps

Fractal Terrain generation

Midpoint displacement Alg.

Diamond – Square Alg.

Fault Line Alg.

Particle deposition

In Glsl, terrain can be generated relatively easy if



a heightmap texture is available to the vertex shader
the surface that is going to be displaced is tesselated fine enough to show the
heightmap details
If this is the case then add the following to the vertex shader
//make sure your height value is in the desired range (for example from 0 to 1)
float h = texture(heightmap, st).r *Scale + Bias;
//ensures that the displacement happens in the direction of the normal of the current
vertex
vec3 newPos = currentPos + currentNormal * h;
gl_Position = uModelViewProjectionMatrix * vec4(newPos,1.);

Very simple example
Fractal Terrains


first approach would be to generate a heightmap using fBm noise
results look ok but not very realistic

since fBm is homogeneous and isotropic

A better choice would be to use Multifractals


These are fractals whose dimension/roughness varies with location
So how do you generate a Multifractal?
Multifractal terrain by Kenton Musgrave.
Texturing and Modeling: a Procedural Approach 3rd edition, pg 490
“Multiplicative Multifractal”
H controls the
roughness of the fractal

Multifractal terrain patch with an offset of 0.8
The above multifractal function is considered to be unstable


It varies from highly heterogenous (at offset = 0) to flat (offset diverges to
infinity)
Its output usually needs to be rescaled
Other kinds of Multifractals

Hybrid multifractals

Called hybrid because they are both additive and multiplicative multifractals

Ridged multifractals


Similar to Perlin’s turbulence noise
They calculate 1-abs(noise) so that the resulting “canyons” from abs(noise) become
high ridges
Ridged multifractal terrains : taken from Texturing and Modeling: A Procedural
Approach pg 518 (left) pg 480(right)
Midpoint displacement 1D version

Type of polygon subdivision algorithm, also a fractal function
Created to simulate tectonic uplift of mountain ranges

One of its main input parameters is the roughness constant r

Step 0
Displace the midpoint of the line
by some random value between (-d, d)
Step 1
Step 2
Now reduce the range of your random function
depending on r by d* = pow( 2 , -r)
Again displace the midpoint
of all the line segments and reduce your
Random function’s range
Keep iterating until you get the
required detail
Step 3
Always remembering to reduce d
After every step
How does r affect the outcome?
If r = 1
Your d will half each iteration
If r > 1 d increases faster
generates smooth terrain
Nth step
If < 1 d increases slowly
generates chaotic terrain
Diamond- Square


Also called the cloud fractal , plasma fractal or random midpoint
displacement
The 2D version of the original Midpoint displacement algorithm


Therefore it also has a roughness constant
The diamond-square alg. works best if it is run on square grids of width 2^n

This ensures that the rectangle size will have an integer value at each iteration

the algorithm starts with a 2 x 2 grid

The heights at the corners can be set to either zero, a random value or some
predefined value

the first step involves calculating the midpoint of the grid based on its
corners and then adding the maximum displacement for the current
iteration
E = (A+B+C+D)/4 + Rand(d)
Rand(d) can generate random values between
-d and +d

This is called the Diamond step ,

Because if you render this terrain you will see four diamond shapes


Next is the Square step
Calculate the midpoints of the edges between the corners
wrapping
G = (A+B+E+E)/4 + rand(d)
H = (B+D+E+E) /4 + rand(d)
I = (D+C+E+E)/4 + rand(d)
F = (A+C+E+E)/4 + rand(d)
Non-wrapping
G = (A+B+E)/3 +rand(d)
same for H,I,F

Since the first iteration is complete, now d is reduced by
d *= pow(2,-r) where r is the roughness constant


Start the second iteration
Again perform the diamond step
B
J = (A+G+F+E)/4 + rand(d)
K = (G+B+E+H)/4 + rand(d)
L = (F+E+D+I)/4 + rand(d)
M = (E+H+I+C)/4 + rand(d)
Remember this d is smaller
than the one in the first iteration
D
C

Perform the square step
wrapping
O = (A+G+J+J)/4 + rand(d)
P = (J+G+K+E)/4 + rand(d)
Q = (J+E+L+F)/4 + rand(d)
N = (A+F+J+J)/4 +rand(d)
Non-wrapping
O = (A+G+J)/3 + rand(d)
N = (A+F+J)/3 + rand(d)

Continue subdividing until you reach the desired level of detail


To summarize,
Diamond - Square alg.
 While length of square sides > 0
 Pass through the whole array and apply the diamond step for each
square
 Pass through the whole array and apply the square step for each
diamond
 Reduce the range of the random displacement
Fault line algorithm

Created to approximate real world terrain features such as escarpments,
mesas, and seaside cliffs
First step in faulting process
Terrain generated
after 400 iterations
Pictures from http://www.lighthouse3d.com/opengl/terrain/index.php?fault

One way of generating fault lines in a height field grid




randomly pick two grid points p1 p2
calculate the line between them
Go through all the points in the height field and add or subtract an offset value
depending on what side of the line they are located
Before the next fault is drawn, reduce the range of the offset by some amount

Height fields generated by this algorithm need to be filtered in order to
look like realistic terrain

A low pass filter is usually used

some variations to the fault line algorithm
Cosine
Sine
Particle Deposition



Simulates volcanic mountain ranges and island systems
drop random particles in a blank grid
Determine if the particle’s neighboring cells are of a lower height



If this is the case increment the height of the lowest cell
keep checking its surrounding cells for a set number of steps or until it is the lowest
height among its surrounding cells
If not increment the height of the current
cell
Generated after 5 series
of 1000 iterations
Issues with using Height fields

They cannot generate overhangs or caves

Some solutions, for example:
 “mushrooming” effects that involve the manipulation of vertex normals
in order to render height field textures with overhangs

the game Halo Wars implemented a new type of height field called a
vector height field which stored a vector to displace a vertex instead of
a height value
Bibliography

De Carpentier, Giliam J.P.. Interactively synthesizing and editing virtual outdoor
terrain.MA thesis. Delft University of Technology, 2007.
http://www.decarpentier.nl/downloads/InteractivelySynthesizingAndEditingVirtualOu
tDoorTerrain_report.pdf

DeLoura, Mark. Game Programming Gems. Charles River Media, 2002.

Ebert, David S., Musgrave, F. Kenton, Peachey, Darwyn, Perlin, Ken and Worley,
Steve.Texturing and Modeling: A Procedural Approach, 3rd edition. USA. Morgan
Kaufman Publishers, 2003.

Martz, Paul. “Generating Random Fractal Terrain.” Game Programmer. Publisher
Robert C.

Pendleton, 1997. http://www.gameprogrammer.com/fractal.html#midpoint

McAnlis, Colt. “HALO WARS: The Terrain of Next-Gen.” GDC Vault, 2009.
<http://www.gdcvault.com/play/1277/HALO-WARS-The-Terrain-of>

Olsen, Jacob. Realtime Procedural Terrain Generation. Department of Mathematics
and Computer Science, IMADA, University of Southern Denmark, 2004.
<http://web.mit.edu/cesium/Public/terrain.pdf>

“OpenGL”. yaldex.com. http://www.yaldex.com/open-gl/ch20lev1sec2.html

Polack, Trent. Focus on 3D Terrain Programming. Cengage Learning, 2002.

Ramirez F., António. “Terrain Tutorial.” Open GL. Lighthouse 3D., 2012.
<http://www.lighthouse3d.com/opengl/terrain/index.php3?introduction>

Tamshi. “RE: Heightmap,Voxel, Polygon (geometry) terrains.” Game Development.
StackExchange Inc., 2011.
<http://gamedev.stackexchange.com/questions/15573/heightmap-voxel-polygongeometry-terrains>

“Welcome to the Virtual Terrain Project.” VTERRAIN.org, 2011.
<http://vterrain.org>