# 3D Procedural Terrain

## Recommended Posts

I recently became interested in 3d fractal terrain. I started with a 2D version. I coded it using the STL list class so I could easily add points into it for subdivisions. I have a very nice little 2D terrain generator. My question is: how should I approach moving to 3D? What structures should I use for the point data? Currently I'm using a Point structure (just holds (x, y)) and an STL list as a container of Points. Any suggestions, links, or other constructive comments? Thanks.

##### Share on other sites
Most 3D terrain generators work with heightmaps (eg. Terragen, unless they have changed something recently), which are straightforward and give good results. To generate heightmap you can use procedural texture generation techniques, like combining 2D Perlin noise using various math operations. More advanced terrain generator can use physics based modeling and modify heightmap more or less like wind and water would do.

If you just want a fractal terrain, heightmaps do their work here too. Just render Mandelbrot, Julia or any other 2D fractal to the heightmap.

##### Share on other sites
i agree with Krzysiek K that a heightmap would be the way to go.
hmm i had a nice article about Diamond Square Fractal for terrains but i can't find it now :(

regards,
m4gnus

##### Share on other sites
I have read papers about the various algorithms to create the terrain, I simply wondered what was an efficient container for the data? The STL list class was nice for 2D because of the insert function, but no such class exists or would be easily usable in 3D.

##### Share on other sites
I would just use an array created with new. And if you need bigger create a new array, copy stuff into it and free the old one.
Maybe use a point structure with x,y,z (generate the heightmap first then convert it to vertices for rendering)

Then to access a point x,y (just like a 2d tilemap):
point = myPointArray[y*width+x];

##### Share on other sites
Quote:
 Original post by NickGravelynI have read papers about the various algorithms to create the terrain, I simply wondered what was an efficient container for the data? The STL list class was nice for 2D because of the insert function, but no such class exists or would be easily usable in 3D.

1. Why would you need to add new vertices to the terrain ? I cant think of a gameplay scenario that would exploit such behaviour reasonably. Because, with a regular heightmap, if you add new Vertex to terrain, you must update VB and IB. So there must be a very good reason to do it. Maybe you are thinking of using such feature only during initial creation of the terrain ?

2. As for your original question, definitely go with dynamic arrays (as xDan said). They wont occupy some additional memory as STL does. To avoid memory leaks, just put deallocation into destructor and you dont have to worry about it.

Also, you might want to consider importing heightmaps from programs like Terragen that can create a nice random terrain.

##### Share on other sites
Quote:
Quote:
 Original post by NickGravelynI have read papers about the various algorithms to create the terrain, I simply wondered what was an efficient container for the data? The STL list class was nice for 2D because of the insert function, but no such class exists or would be easily usable in 3D.

1. Why would you need to add new vertices to the terrain ? I cant think of a gameplay scenario that would exploit such behaviour reasonably. Because, with a regular heightmap, if you add new Vertex to terrain, you must update VB and IB. So there must be a very good reason to do it. Maybe you are thinking of using such feature only during initial creation of the terrain ?

I used it simply to generate the 2D heightmap. Obviously I wouldn't be adding things during runtime, only during computation.

Quote:
 Also, you might want to consider importing heightmaps from programs like Terragen that can create a nice random terrain.

I already can do that, and it defeats my purpose. I want to learn the algorithms behind procedural generation of terrain, trees, clouds, etc. I figured terrain would be the easiest to start with.

##### Share on other sites
Google Perlin noise. Its what's used in alot of games.

##### Share on other sites
Quote:
 Original post by EzbezGoogle Perlin noise. Its what's used in alot of games.

These books have code samples for GPU-based Perlin noise implementations:
GPU Gems, chapter 5: "Implementing Improved Perlin Noise", Ken Perlin (New York University)
GPU Gems 2, chapter 26: "Implementing Improved Perlin Noise", Simon Green (NVIDIA Corporation)

##### Share on other sites

http://www.gameprogrammer.com/fractal.html

http://www.lighthouse3d.com/opengl/terrain/

hope it helps :)

##### Share on other sites
I did this for a coursework in my degree about 6 weeks ago. I used summed and scaled perlin noise, it works nicely. One thing you've got to do is make sure you multithread the generation of the terrain, otherwise your program will halt every time you generate a terrain tile.

One thing you'll probably need is LOD on each tile of your terrain. So look up dynamic LOD systems (I just used scalable diamond-square with linking pieces). Also, you've got to calculate the normals from every adjacnt triangle (averaged), so you're going to have to figure out how you want to go about doing that. :)

Edit: Oh, I mistook your quesion, I thought you were referring to infinite fractal terrain, which is what I did for my degree 6 weeks ago. :p In the case of finite terrain, streaming in new terrain won't be a problem for you. :)

A diamond-square algorithm can be found here: clicky

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628379
• Total Posts
2982344

• 10
• 9
• 15
• 24
• 11