Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411507 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 05:10:03 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Random/procedural 3D terrain generation
Pages: [1]
Print
Author Topic: Random/procedural 3D terrain generation  (Read 5953 times)
shrimp
Level 5
*****


View Profile WWW
« on: June 14, 2008, 07:44:29 AM »

Hi, since I couldn't find an existing one, here's a thread about procedurally generated height-field terrain.  Wink

I've been toying with the idea of some kind of lo-fi Morrowind/Oblivion meets Rogue game for a while now, and I seem to keep getting bogged down in the map generation.

One iteration of this project was using fairly conventional height map generation algorithms, including

* The classic: Diamond-square algorithm, via this tutorial: http://gameprogrammer.com/fractal.html. I think I rejected this at the time because I wanted something I could tune more easily.

* A non-fractal method: http://www.robot-frog.com/3d/hills/index.html - very nice and simple, natural looking enough, easy to tweak.

With both of these I hit problems when trying to "erode" it to add river valleys. If anyone has a nice erosion algorithm that runs on an existing heightmap, or some generation process that has valleys built in, I'd really love to hear it!

Terragen has a fairly decent Erode operation, but I've no idea how it does it...

(Another approach I'm playing with is something tile-based, like Civilisation or the overland map in Dwarf Fortress... I'll leave that for now, but can post info/pics/demo if it's of interest to anyone)
Logged

bateleur
Level 10
*****



View Profile
« Reply #1 on: June 17, 2008, 12:57:40 AM »

can post info/pics/demo if it's of interest to anyone

Always good to see pics. Smiley
Logged

Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #2 on: June 17, 2008, 02:22:27 AM »

Well, I still think the way I suggested would work well, even though I haven't tried it.

Simulate erosion by dropping rain drops over the whole map. a rain drop hits the terrain and moves down the slope with some random variation, lowering the terrain slightly as it goes. In this way you will get rain drops collecting in the valleys and the valleys will get deeper. If a rain drop can't go further down then it makes a lake.

Rivers would be a good addition to this as they would naturally create their own valleys and serve as a data point where you could say ok, this is a river, so i will erode the terrain all the way along this river while i'm simulating the rainfall erosion.

You could even simulate the whole landscape with voxels, and give each voxel a density that would affect whether it would collapse down a given angle. That way you could simulate smooth mountainous terrain with fairly soft rock and canyon stuff with rivers and really hard rock.
Logged

ravuya
Level 7
**


Yip yip yip yip yip


View Profile WWW
« Reply #3 on: June 17, 2008, 04:36:38 AM »

When I did it, it was cheap and sleazy. I just randomly adjusted the height map then averaged each control point with its neighbors. Closer to a box blur than anything resembling not-suck.
Logged

FARTRON
Level 4
****


the last man in space


View Profile WWW
« Reply #4 on: June 17, 2008, 07:01:30 AM »

Quote from: Tarn Adams
Let's talk about the world generator for a bit. If you wouldn't mind giving us a general overview of the process the game goes through? No need to go into great detail.

TA: Sure. The first overall goal of the world generator is to create enough information to produce a basic biome display. A lot of initial attempts at a world generator will start with things like "I need to lay down some forests, and some mountains, and some rivers, and some deserts..." and then when you end up with a jungle next to a desert, or a desert next to a swamp in an unlikely way, it's difficult to fix.

So the idea is to go down to basic elements. The biomes are not the basics, they arise, at least in DF, from several factors: temperature, rainfall, elevation, drainage. First, it uses midpoint displacement to make an elevation map.

It also makes a temperature map (biased by elevation and latitude) and a rainfall map (which it later biases with orographic precipitation, rain shadows, that sort of thing). The drainage map is just another fractal, with values from 0 to 100. So we can now query a square and get rainfall, temp, elevation and drainage data.

This is where the biome comes from. There's an additional vegetation field so it can alter the amount (from logging for example), and there's also a "savagery" and a "good/evil" field. So for instance, if rainfall is >=66/100 and drainage is less than 50, then you have a swamp.

The nice thing about having the fractally-generated basic fields is that the biome boundaries all look natural. Part of the trick was to differentiate things like swamps and forests. There's also a salinity field, to differentiate fresh and saltwater marshes, etc. Just lots of basic information, so you don't try to shoehorn anything into place. Just let it happen and these fields can all potentially be altered.

I guess oceans get high salt as a special step?

TA: Yep, for now, it just sets the salinity to 100 at the oceans (oceans are just all the low elevation spots), and tapers it off quickly over the land squares.

You still get some artifacts from the midpoint displacement. It tends to like vertical and horizontal lines, so the next step is the erosion phase.

It picks out the bases of the mountains (mountains are all squares above a given elevation), then it runs temporary river paths out from there, preferring the lowest elevation and digging away at a square if it can't find a lower one, until it get to the ocean or gets stuck. This is the phase where you see the mountain being worn away during world creation. I have it intentionally center on a mountain at that point so you can watch.

This will generally leave some good channels to the ocean, so it runs the real rivers after this. However, some of them don't make it, so it forces paths to the ocean after that, and bulges out some lakes. Then it loop-erases the rivers, and sends out (invisible on the world map) brooks out from them. During the loop-erase it also calculates flow amounts and decides which rivers are tributaries, and names the rivers.

This gives us a world with biome data and rivers, but no actual life. So now it actually looks at the general biome groups of each square (what I call a region type) and forms regions, giving them names. So you can have the "Silvery Forest" which is taiga in the cold regions and a jungle in the warm region, as long as it is connected.

At this point, it looks at the biomes available in each region and sets up plant and animal populations. This gives you a canvas for world history.

And from there I imagine it's just looking up the combinations of circumstances and looking them up in a table of random possibilities.

TA: Yeah, I'd like to do more with ranges for animals, so that it's not so scattered. So that many of the northern forests have certain critters, and many of the western forests have others to kind of set up more of a geographical image. Right now, it goes strictly by biome type. It also sets up all the seed information around this time. There are some additional structures it sets up, for features like cave rivers and so on. So it could set up a non-local feature like a world-wide cave tunnel like this.

It wouldn't be so complicated to have the computer generate the races itself, though the lack of familiarity could be jarring. Armok 1 did this.

The Making of Dwarf Fortress
Logged

Everything that was once directly lived has receded into a representation. - debord
shrimp
Level 5
*****


View Profile WWW
« Reply #5 on: June 18, 2008, 04:14:32 AM »

Awesome stuff, thanks chaps - I think I must have missed that DF article somewhere along the line. What's described in that quote is very similar to what I was aiming for in the second approach, including making species ranges. I suspect I may be delusional in trying to match or beat DF even just in this area Wink

@ravuya - Yeah that is more of a smoothing operation, if I understand what you're saying. If you have an initial landscape with an un-geological basin in it, you'd just get a slightly smoother shallower basin.

@haowan - Yeah yeah alright (since you are pretty keen on this idea Tongue) I think I should probably try that next, I've just got the fear about strange emergent effects and feedback loops, but it does sound very cool on paper.

I'll post some pics later, when I have access to the files...

Pics!

From the Civ/DF version:

("normal" view)


("geology" view - same map but zoomed out one step)

From the heightmap version:

(the lo-fi look is kind of deliberate - the final renderer is/was intended to be a kind of collage-based thing... big spritey voxels or something)
« Last Edit: June 18, 2008, 10:00:40 AM by shrimp » Logged

Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #6 on: June 18, 2008, 10:06:21 AM »

sizzling red hot image action!  Evil
Logged

ravuya
Level 7
**


Yip yip yip yip yip


View Profile WWW
« Reply #7 on: June 18, 2008, 11:44:40 AM »

The voxel-ish one looks really impressive. Smiley
Logged

shrimp
Level 5
*****


View Profile WWW
« Reply #8 on: June 18, 2008, 01:20:43 PM »

I should say that it isn't actually voxels, just very low-res textures, but thanks!
(also runs like a dead dog and has all kinds of other problems...)
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic