Monday, April 12, 2021

Mountains, Gandalf!

About a million years ago I designed a system for generating mountains that would allow for the creation of vaguely convincing ridges and valleys at the regional level. Now this was much better than just using diamond-square to add detail to the global heightmap, and in fact I was so impressed with my mountains that it spurred me on to try to make all the other elements in Undiscovered Worlds as good as they were. But the system does really leave a fair bit to be desired, compared to reality.

For example, here's the regional map I put at the end of my last post:


Those mountain ridges look superficially OK. But they're far too wide, really, given that one pixel is one kilometre, and they don't have any proper sub-ridges coming from them. When I initially made this system, I had difficulty doing that, and so I just added random lines of ridges sticking out in random directions from the main ridges, which makes them look a bit fuzzy but doesn't really make much sense.

Compare the Himalayas:

and the Pyrenees:


These are far busier than my mountain ranges, with all those little sub-ridges and valleys in between them.

So it's time to try to improve the mountains a bit. First, we make our main ridges thinner, and get rid of additional fuzziness. This is straightforward:


Now how do we go about adding buttresses to these ridges that make sense? I decided that the best way would be to mark key points along the ridges while drawing them, and then go through the map tile by tile. For each cell in each tile, we work out which of the key points is closest and how far away it is. It's then straightforward to identify all the ones that are a key maximum distance from the nearest key points. These form an outline some distance from the ridges. Also, any cells that are closer to their nearest key points than that, but which do not have any neighbour which (a) has the same closest key point and (b) is further from it, are cells that form the boundary between two watersheds, as it were.

The map probably explains it better. The ridges are in turquoise, cells that are the maximum allowed distance from their key points are dark pink, and the cells that are equidistant between two ridges are lighter pink:


Now all we have to do is to go over all of those marked cells and choose some of them to be the end points of buttresses. Buttresses are drawn from the key points on the original ridges out to the end points, with perhaps a bit of swerving along the way, and a gradual decrease in height.

Then we do all of that again, to create smaller, secondary buttresses that emerge from the first set of buttresses.

The result isn't as elegant as the real mountain ranges shown above, but it doesn't look totally unreasonable:


The relief map of this area looks like this:


I think that looks pleasingly rugged. Here's how the region I showed at the start of this post looks now:


There are a few other differences here, because I've been fiddling about with the grid-concealing elements that I talked about in my last post. But the main thing is that the mountains are looking a little more believable, I think.

Another range from the same world, showing how complex the ridges can sometimes get:


And finally, of course, where there are low mountain ranges, we have hills. These are now looking like this:


As I always say, it's not perfect, but it's an improvement. There will probably be endless tinkering to be done with this approach, and I wish I were able to get it more realistic in detail, but I'm quite pleased with the general effect for now.

Monday, April 5, 2021

Going off-grid

At the end of my last post I pointed out some grid-like artefacts, probably something to do with roughness. Here's a clearer look at them:


As it turns out, these have nothing to do with roughness, because I turned that off and they're still there. They're something to do with the rivers, because if I turn the rivers off, they disappear.

Part of the issue is the river valleys. If rivers are large and they have wide valleys, then these will often tend to have straight edges because even though the river wiggles about, those wiggles will tend to cancel each other out as far as the edges of the valley go. Still, I did find that there are quite a lot of straight river sections, so I spent some time adding extra routines to detect and remove these. They are working very nicely and the rivers are that much wigglier now, but it doesn't make much difference to these artefacts.

A simpler approach is just to add a routine that identifies long straight cliffs on the regional map and gets rid of them by pasting irregular-shaped areas of low/high land over them. That gives us this:


That is definitely a big improvement, but we do still have some grid artefacts remaining. Annoying, the use of the diamond-square algorithm to create detail on the regional maps does sometimes create artefacts of this kind. They don't appear all the time, but when they do they're quite annoying. What can we do about this?

I decided the best way to tackle this was to disrupt the terrain - just a little - with another source of detail. First, I created yet another global-scale fractal as part of the world generation process. However, this one gets some extra processing. First, I used a simple warp technique to distort the fractal. Basically, two additional fractals are generated. Then, going through the original, we look at each point in turn. We take the corresponding points on the other two fractals to shift the x and y coordinates on the original fractal, and copy whatever point we find there over to the original point. I did this twice, and got this rather nice marbling effect:


Definitely no bias towards vertical/horizontal lines there.

Now, at the regional level, we can use this to disrupt the terrain a little. After terrain has been generated, we go through each tile in turn. In each one, we sample a few random points. For each one, we compare it to its neighbours. If the height difference between them is above a certain threshold, we take a random small circle of that noise map and paste it on, blending it with the existing terrain to make a smooth transition.

That gives us this:


Not perfect, but a lot better than what we had.

As a bonus, this new system of terrain disruption creates some really nice texture to the land in various places. Look at this, for example:


Here you can see rougher terrain near the mountains and in parts of the arid region, gradually giving way to smoother terrain elsewhere. I think this is a nice contrast that helps the map look that much more believable.