3D Procedural Terrain

Started by
9 comments, last by Leo_E_49 17 years, 11 months ago
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.
Advertisement
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.
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
"There are 10 types of people in the world... those who understand binary and those who don't."
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.
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];
Quote:Original post by NickGravelyn
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.

1. Why would you need to add new vertices to the terrain ? I can`t 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 won`t occupy some additional memory as STL does. To avoid memory leaks, just put deallocation into destructor and you don`t have to worry about it.

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

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

Quote:Original post by VladR
Quote:Original post by NickGravelyn
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.

1. Why would you need to add new vertices to the terrain ? I can`t 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.
Google Perlin noise. Its what's used in alot of games.
Quote:Original post by Ezbez
Google 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)
Try the following links:

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

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

hope it helps :)

This topic is closed to new replies.

Advertisement