Sign in to follow this  
NickGravelyn

3D Procedural Terrain

Recommended Posts

NickGravelyn    855
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 this post


Link to post
Share on other sites
Krzysiek K    134
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 this post


Link to post
Share on other sites
m4gnus    240
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 this post


Link to post
Share on other sites
NickGravelyn    855
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 this post


Link to post
Share on other sites
xDan    194
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 this post


Link to post
Share on other sites
VladR    722
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.

Share this post


Link to post
Share on other sites
NickGravelyn    855
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.

Share this post


Link to post
Share on other sites
taby    1265
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)

Share this post


Link to post
Share on other sites
novaira    122
Try the following links:

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

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

hope it helps :)

Share this post


Link to post
Share on other sites
Leo_E_49    228
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this