Wednesday, May 8, 2019

The canyons of your mind

I previously explained that when rivers are carved at the regional level, they are placed lower than the base level of their tile's elevation. The amount by which they are lowered is a constant throughout the whole world - I've found 20 metres to give generally good results.

This gives us some variety, as depending on how wide the river valley and how mountainous the area is, we get quite different-looking valleys. But still it would be good if we could vary the constant itself, to give, say, really deep valleys sometimes - and some epic canyons:



But doing this is tricky. For one thing, if the constant varied, then there might be cases where a river runs uphill (if it moves from one tile to another which is only slightly lower but has a much smaller constant). For another, lake surfaces are calculated on the basis of this constant, and if it varies then all sorts of complications would arise.

So how can we get really impressive canyons? My cunning answer to this is: instead of lowering the river, let's raise the land around it. Suppose, during the global map creation phase, we introduce artificially raised areas. These will be superimposed over the normal elevation map - that is, the "real" elevation will be retained on the standard elevation map, but there will be a new array which has, in some places, higher elevations marked. We'll use those when calculating climate and so on.

As always, the rivers will still be calculated on the basis of the normal elevation map (without mountains), not these higher elevations. And when we go to the regional level, the rivers will still be given elevations based on that normal elevation map, lowered by the same constant as usual, just as they are now. But the terrain elevation around them will be based on the higher elevations from our new array (if any are present for that area). This should give the effect of rivers (and river valleys) that are significantly lower than the surrounding terrain, and we might get some nice canyon systems as a result.

First, we create the "extra elevation" array. This is just another fractal, but with lower values so that a lot of it is zero (we don't want extra elevation everywhere, and certainly not over sea). That comes out looking like this:


The highest value here is 500. The sharp edges are coastlines (no matter how high the extra elevation over land, it's always zero over sea). I've applied a blur to it so that it's not too sharp at the coasts - we don't want gigantic cliffs all along them, at least not most of the time.

Now we apply this to the global map. The values in the extra elevation map are simply added to the values in the global map (with mountains). We don't add them to the global map (without mountains) though, because that's the one we'll be using to calculate river elevations from.

That gives us a global map that looks like this:


For the most part, the change is very subtle. The only part of this map where you can clearly see the land is raised as a result of the extra elevation is on that large peninsula jutting off the eastern coast of the big continent just to the right of centre. About half of that peninsula has high extra elevation and it does appear notably elevated on the adjusted map.

So we have our extra elevation applied to the map. Now it's just a matter of making it have the desired effect at the regional level. At the moment, the elevations at the regional level are based on the global map without mountains. All we have to do is change it so that they are based on that no-mountains map plus the extra elevation map. The river elevations, meanwhile, continue to be based on the global map without mountains alone. That should mean that where the extra elevation map is substantial, the rivers will appear to be much lower than the surrounding terrain.

So I first had a look at that peninsula mentioned above, and this is the first map I got:


This is pretty much what I was hoping for. The rivers are carving valleys which are much deeper than before. Because UW only marks rivers of greater than a certain size on the relief map, but all rivers carve valleys, you can see some valleys without obvious rivers in them, giving this terrain a very scored sort of look. You can see the effect on the elevation map of the same region too:


Remember, of course, that the larger the river, the wider a valley floor it has around it. So all the rivers are equally prone to carving deep canyons where there is substantial extra elevation, but only the larger rivers will carve really wide ones.

Zooming in, we get tiles like this:


This is a fairly substantial river (flow of around 1000 cubic metres per second). The terrain to the north of the highlighted square is around 1100 metres above sea level, dropping to 620 on the valley floor. The drop is more precipitous on the north bank than on the south, where the land slopes up in a relatively shallow way to the heights. Why is this? Because the terrain of each tile is based on seeds at the corners of the tile. Here, the elevation of the river has been taken directly from the no-mountains global map. The elevation of the corners of the tile has then been taken from that map plus the extra elevation. The computer has tried to smooth the terrain from the corners down to the already-calculated elevations at the river cells. There is less distance to the northeastern corner than to the southeastern corner, so it's steeper in that direction.

This tells us that to get a real Grand Canyon, with precipitous sides all around to a great height, we'd need a tile where we not only have substantial extra elevation but also rivers flowing in from all directions to ensure that the distances to the terrain seed cells are relatively short, creating steep slopes all around.

For comparison, here's a region where rivers from an area with high extra elevation flow to one with none:


So we can imagine that the high ground in the northeast of this region is made of relatively soft rock, where the rivers have worn away deep valleys as they flow to the lowlands.

One more region I thought was interesting. Here's the river map first:


Look at that river with lots of small tributaries in the north that then flows roughly southeast and reaches the coast about halfway down the image. The elevation map shows what's going on here:


Those tributaries are flowing into a fairly wide depression in the surrounding higher land. But the river they form then flows out of that depression in a deep valley through that higher land, until it emerges to the flatter coastal shelf and flows into the sea. The relief map looks like this:


So the highlands it flows through are actually a big desert. We can imagine this wide, relatively fertile valley, several kilometres across and about 300 metres lower than the surrounding desert. Perhaps camel-mounted nomads journeying across the desert might crest the top of a hill and see the welcome valley suddenly emerge into view...?

So overall I'm quite happy with how this has worked. There will probably need to be more tweakings of the settings of this (I suspect that higher extra elevation might produce good results) but the basic principle is working well, which makes a nice change.

Wednesday, May 1, 2019

Sand and swamps

It's been a little bit of a while since I last updated. This is partly because of real-life business, but mainly because I've been bogged down with trying to improve lakes, along the lines described in the previous post. The salt lakes are looking good but I want the freshwater lakes to work similarly - but I just can't get it to work, no matter how many nifty tweaks I make. Infuriating! Well, the existing lake system is OK most of the time, so I'll leave it in place for the time being, because I want to move on.

So enough of lakes - at least for now. Let's add some more new things.

First, ergs. Not the Jacob Rees-Mogg kind, fortunately. I mean the desert kind - large areas of sand dunes of the kind that we normally think of when we think of "deserts". In reality of course deserts vary in terrain type, and dunes cover only some parts of deserts. A large area of sand and dunes is an erg, and they form discrete areas in deserts such as the Sahara:


So let's put them in Undiscovered Worlds. This is pretty straightforward. We already did salt pans, which are also large, flat expanses of unusual terrain that occur in deserts. So all we have to do is to repurpose that code and do dunes in exactly the same way. The result:



Salt pans are lower than the surrounding area, because they're like lakes; this isn't the case with ergs, but otherwise they're functionally pretty much identical to salt pans other than the name, colour, and size/frequency (I've set it so these are more common and tend to be larger). There's no need to try to represent the dunes themselves because the scale is wrong - you wouldn't be able to see them at this scale. If I manage to create a local scale, more zoomed in than the regional, I'll have to find a way to make realistic dunes on these areas.

I think our deserts are looking pretty well stocked now. Time for something quite different: wetlands. These are areas that are not exactly lakes/rivers but not exactly solid land either, either because they are frequently flooded or because there is always standing water there. There are four kinds of wetland, distinguished mainly by vegetation type: swamp, marsh, bog, and fen. Swamps have trees in them, marshes have bushes or grass in them, and bogs and fens have small shrubs, grass, and moss, that turn into peat. (Fens tend to be fed by groundwater while bogs are more dependent on precipitation.) For our purposes, these distinctions don't really matter, at least for the time being. We'll treat them all simply as wetlands, but we will distinguish between freshwater, brackish, and saltwater wetlands, based on proximity to sea/salt lakes/salt pans.

We'll mark wetlands on the specials array. At the global level, it's just a matter of taking into account the following factors: proximity to water; level of precipitation; flatness of terrain; and what I'll call "drainage", following the example of Dwarf Fortress, but is really just another global-scale fractal to add some variation. The higher these factors, the more likely any cell is to be marked as wetlands. Also they are much more likely in tundra areas, because the frost melts in the summer and creates areas of standing water. If a wetlands cell is next to a salty cell of some kind it will be saltwater wetlands, and if it's two cells away it will be brackish; otherwise it will be freshwater.

That yields a world map something like this (wetlands marked in cyan just for the sake of clarity):


At the regional level, for any tile whose source cell is wetlands, we go through it and paste a blob of wetlands centred on each river, lake, or coastal cell. The elevation of each blob is taken from the elevation of the central point, to ensure that the wetlands remain roughly flat. This leads to what I think is a rather nice effect where wetlands cluster around the hydrological features but in quite a "bitty" sort of way. Here's what we get in a large riverine system in a rainforest climate:


For comparison, here is a map of the wetlands of the Amazon basin:


The look I've got isn't exactly the same, of course, but I think it's plausible enough to be getting on with. A little fiddling with the colours to make it all blend in and we get some nice subtle swampy areas like this:


We've also got quite a lot of wetlands in tundra areas, as noted above. Where these coincide with areas with lots of glacial lakes we get some pleasantly interesting looking landscapes:


So that's that. Onwards and upwards!