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.

5 comments:

  1. I really like the effects you can generate from warped fractals.

    ReplyDelete
    Replies
    1. Aren't they lovely? I was just waiting for a good use for one in this project.

      Delete
  2. Got a problem? Add more fractals and noise! My immediate thoughts now after being introduced to the diamond-square algorithm (thank you!), is to use another deterministic noise like Perlin to determine the random numbers of the diamond-square to make that deterministic, and then use another Perlin noise as a mask map to determine the strength of the result, then mix it with other some other finished noise/fractals, and normalize the result.

    ReplyDelete
    Replies
    1. METANOISE!!

      I think my project must be one of the very few terrain generators that doesn't use Perlin noise or any of its relatives at all. This is mainly because I don't understand it, whereas I do understand diamond-square, although it's surprisingly fiendish to implement.

      Delete
    2. If it helps you i recomend this website https://catlikecoding.com/unity/tutorials/noise
      it is in c# but you can put it into the language you are using. I can't say I fully understand perlin noise now but it sure helped me in the implementation.

      Delete