If you've been following this blog, I've been writing about modelling a large game world for some time. Ideally I'd like that world to be largely procedural, so that I can have a lot of explorable environment without having a huge amount of painstakingly handcrafted models; but I also want it to look natural. And in making a landscape look natural, one of the first key things is to model how rain falls and how water drains.
So I've been playing with some experimental code to model this. It isn't yet doing even nearly what I want, but it's beginning to show the first hints of promise.
My assumptions are: my game area is in the northern hemisphere of it's planet, which spins eastward just as the Earth does; coriolis winds blow rain in from the west, and it falls mainly on rising slopes. From where it falls it drains downhill, and once it's joined with sufficient other water, it makes a watercourse, forming a dendral river system. Got all that? Good.
Here is a height-map - actually, the height-map I'm using for testing. A height-map is just like a contour map: darker colours have lower elevation, with black representing sea level and white representing the highest mountain peaks.
As you can see, my continent has a mountain range running round its west and north; a large crater in its south-east corner; and a large area of fairly flat land, intended as steppe, in the centre. The expectation was that the western littoral should be wet and forested, the north and south littorals fertile, the steppe fairly arid, and that the crater should catch a certain amount of rain water - enough to make it reasonably fertile. The eastern littoral was expected to be dry.
You'll note that, as a hack on the map, there's a little black spot - literally a plughole - in the south-western corner of the steppe, to let the water out.
Now, here's the terrain map from the first sort-of successful run of the irrigate process:
Now, let me be first to confess there's a lot wrong with this map, and where it is working it's partly for reasons of artifice. Also, there are some artefacts which I simply don't understand.
Firstly, it's too wet in the west. There are huge lakes which are not draining and I don't know why. The littoral is fairly flat (you can see this from the height-map) but lakes should not be forming on flat land. I need to understand why my drainage algorithm is not working there. Similarly, the east is too dry - it's intended to be drier, but not wholly arid. The crater had a hand-drawn valley system, and it's unsurprising that rivers are forming in those hand-drawn valleys. I don't understand what has caused the two visible dykes which extend out to see from the south-western corner of the continent. There is too strong a tendency for rivers to follow diagonals - it's a very visible artefact, and again I'm not sure why.
However, I'm really pleased with the drainage of the steppe, and on the southern littoral. It's a (good) start. I'm not yet prepared to publish the code that does this, because it is still much too messy. But I am feeling encouraged.
Having said that I'm not yet doing nearly as well as people who generate landscapes entirely procedurally without any attempt to model real physical processes.