# 3D Procedural Terrain

This topic is 4420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 :)

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631429
• Total Posts
3000035
×