Ask HN: How to generate random terrain
When I was a kid in the 1980s, I read a library book on the topic of writing military strategy sim games, and it had an entire chapter on producing random terrain. It started with the usual fractal techniques for producing contours, but then it went on to use weighted random walks to produce roads and rivers, lakes, bridges, and cities.
I've tried recreating the algorithms from what little I remember of them, but they never produce anything that looks very good. Online I've found plenty of references to ways of generating the contours, but never realistic-looking roads, rails, and waterways...
Does anybody know an online reference to that sort of thing?
Thanks!
33 comments
[ 3.5 ms ] story [ 79.5 ms ] threadSeriously, I'm all for discussion of particular techniques, but your question is way too broad right now. Go read some papers or even just online tutorials or descriptions of how other software does it, and then lets have a discussion.
My googling always just found me more and more ways of generating the height-field data - it's the roads and so on that interest me. I tried tinkering with weighted random walks (eg, given the desire to continue a road from a given point, pick an adjoining cell with a weighting that prioritises having the same altitude and being closest to continuing the existing direction), but this fails to capture things like the fact that roads tend to run along valleys and mountain passes - the hard part, it seems, is in choosing initial points. Likewise, a river can be continued by finding the most downhill adjacent cell, until you find a minimum then starting a flood-fill algorithm to create a lake, until you reach a boundary pixel that "goes downhill", whereupon you can start a new river going down from there - but this fails to realistically account for the widths of rivers (you can just make the river wider as you go down, and sum the width of rivers that meet, but that simple model looks wrong: real rivers are deeper when in narrow canyons and the like).
Read up on L-Systems, too. They're great for creating organic structures, be they leaves, trees, or river-tributary systems.
Oh and this may be useful: http://roguebasin.roguelikedevelopment.org/index.php?title=C...
This is an interesting search problem. The fact that a description like this still doesn't help in locating a book (when you think about it the set of all books published is a small one compared to say the domain of web pages on the internet), shows how much work still remians to be done in search.
1. Add rain in random locations 2. Have the rain absorb some of the soil from the square it starts in. 3. Let the water flow in the direction of the gradient. 4. Deposit som e of the picked up soil (maybe only with some probability based on the flow velocity?) 5. Repeat
If you just want rivers and lakes you can skip the erosion step and just simulate the water flowing. If you wanted you could add sources manually and have water always flow from there.
I got some stuff I rolled here http://flywheel.be/examples/
All random generated. But probably not what you're looking for.
1) Randomly pick center points of territories, guarantee a minimum distance for best looks
2) Compute the Voronoi raster, i.e. for each pixel find the nearest territory center
3) Figure out which territories border which, based on the Voronoi raster
4) Compute borders for each territory by taking the midpoints of edges in the territory neighborhood graph. Use a couple special tricks for coastal territories.
5) Split up those borders into finer segments
6) Add noise to the border segments
7) Fill in the pixels according to the borders
http://flywheel.be/wouter/maps/
For more discrete-looking maps.
http://www.gamedev.net/reference/list.asp?categoryid=45#188 http://www.gamasutra.com/search/index.php?search_text=terrai...
Project link: http://code.google.com/p/charack/
http://steveasleep.appspot.com/pyworldgen
If this is what you're looking for, I can try to explain it.
Similar in concept, I guess. What technique are you using? I always start from fractal + voronoi but I think that's fundamentally flawed; going from raster to vector is silly when you could have gone straight to vector.