14

I am looking for some algorithms which allow me to generate a realistic 2D terrain map. By realistic I mean that person will consider such map as a "normal" terrain map, not created artificially. I don't want to create photorealistic map. Just something similar to maps that can be viewed in a geographical atlas.

So far I am using perlin noise for height map and then I am adding lakes, rivers, mountains, swamps and so on. You may look how it looks on the picture below:

Terrain map http://www.freeimagehosting.net/uploads/1f1e9372bf.png

I am not happy with it. It's not realistic but I can't figure out something better on my own. Time is not a matter so the algorithms may be heavy computational.

Thanks for your time.

After edit:

I think I've found one article that can be helpful: http://portal.acm.org/citation.cfm?id=1255047.1255077

However it can't be obtained for free so I am still looking for answers or ideas.

Wodzu
  • 6,932
  • 10
  • 65
  • 105
  • 4
    I can't find the article I wanted, but it basically used a system of locality based hills to generate nice islands. It's possibly linked to on here: http://pcg.wikidot.com/articles But I cba going through them all. – Pod Sep 20 '09 at 16:58
  • 1
    You didnt say why its not realistic, qualify what you are not satisfied with in those renderings, the rivers, the borders, the shapes... i dont like the ratio of green to blue, too much green gives no contrast, and the rivers are lo fi... so at least add more water or some height information like beaches, deltas, peaks etc, and more coastlines. – bandybabboon Mar 05 '14 at 10:06
  • @ufomorace What I've meant by "not realistic" is that when you take a map you see that mountains, hills, rivers, plains, meadows.. everything is connected in logical way. I am having problem with reconstructing this logic. – Wodzu Mar 06 '14 at 18:54
  • @ufomorace and you've made a lot of valid points... the problem is that on 2D it is hard to show height information, or how to show forest on the hills? That is why I've decided to switch my rendering to 3D. First I am drawing a 2D shapes, then I am triangulating them and then I am giving heights to vertices. – Wodzu Mar 06 '14 at 18:59

4 Answers4

6

I've played with terrain generation before. Assuming the objective is a bitmap I found a way to make things like rivers and in general make it look better: Erosion.

Once you have terrain generated by other means erode it a bit: You need the world expressed as heights of pixels. Take a spot on the map and move one unit of height to the lowest neighbor. Move the cursor to this neighbor and repeat until it doesn't move. Repeat for other pixels.

To make rivers count the number of times you pass through a location moving bits down. Spots that get hit the most are rivers.

Followup: I wasn't eroding each pixel so much as simply a large number of random pixels until it weathered enough. The reason for actually eroding them is that this carries bits down and fills in holes. Without that there can be no rivers as there will be dead that trap the flow--the flowing pixels fill in any small holes and make working waterways.

Sorry I can't give any samples, this was many years ago and while the old code is probably around somewhere I don't know where to look.

Loren Pechtel
  • 8,945
  • 3
  • 33
  • 45
  • Thanks Loren. I am not sure I understand you correctly. Do I have to erode each pixel on the map? This is somewhat comparable to just for an example starting on the top of the local hill and than going down in a given direction. By "going down" I mean searching neighbour pixel with less or equall altitude. And continue until the condition is not violated. This is what I am doing now (but I do not lower the altitude) and you may see the results. It would be great if I could see some screenshots from your generator. – Wodzu Sep 20 '09 at 19:29
  • @Wodzu, I think Loren's suggestion is the right direction for you. And no you don't have to erode each pixel; but you should move some (displace them, the sediment is also important for shape). See http://markjstock.org/pages/builder.html image for 'erode'. – Unreason Jun 25 '10 at 09:45
3

Terrain is created by a myriad different causes over many different time-scales. In order to truly create realistic terrain, you'd have to simulate these.

In the "short" term, the hydrosphere determines most of the characteristics. You can probably start with a voxel/particle/heightmap/mesh terrain containing major features (mountain ranges etc.) and treat it as immutable, then post-process it with a plethora of water simulations. You'll need to compute where the rivers and lakes will be, how they erode the base landscape, and where they form deposits. If I had to code this I'd probably start with a 3D voxel world.

This would be a gargantuan task and I'm sure there are lots of tricks available for generating specific terrain types that take milliseconds instead of minutes. What kind of terrain are you looking to create? Mountainous? Lowland? Industrialised? Forest? Desert? Archipelago?

Long story short: if you want terrain that looks realistic to humans (who tend to be, after all, experts on this kind of thing), you'll have to create it by simulating actual geological processes.

David Rutten
  • 4,716
  • 6
  • 43
  • 72
2

My method in Terra3D was to generate random height values, and then make 3 smoothing passes with a little reshaping written into the algorithm. The reshaping causes the terrain under the water line to shift downwards a bit and everything above the water line shift up a bit. The effect though is a lot of hills and small lakes. And that may not be what you're looking for exactly.

However, I'm not convinced that the principal behind my method couldn't be used to get what you want. You may just have to write some more conditions into the reshaping/smoothing algorithm. For example, reducing the amount of smoothing on the terrain at higher elevations will create more of a rocky mountain appearance. And then writing a more involved smoothing (or gaussian) algorithm that stretches out further for the lower elevations could pull those lakes together to form natural rivers.

Here's the code for the terrain generation in Terra3D in case you're interested:

  // GENERATE TERRAIN
  for (i = 0; i < MAX; i++)
  {     
    for (i2 = 0; i2 < MAX; i2++)
    {
        if (i<10 || i2<10 || i>MAX-10 || i2>MAX-10)
        field[i][i2].y=0;
      else
        field[i][i2].y=(GLfloat(rand()%151)-75)/50+(field[i-1][i2-1].y+field[i-1][i2].y+field[i-1][i2+1].y+field[i-1][i2-2].y+field[i-1][i2+2].y)/5.05;
    }
  }

  // SMOOTH/RESHAPE TERRAIN
  for (int cnt = 0; cnt < 3; cnt++)
  {  
    for (int t = 1; t < MAX-1; t++)
    {
      for (int t2 = 1; t2 < MAX-1; t2++)
      {
        field[t][t2].y = (field[t+1][t2].y+field[t][t2-1].y+field[t-1][t2].y+field[t][t2+1].y)/4;

        if (cnt == 0)
        {
          if (field[t][t2].y < -1 && field[t][t2].y > -1-.5) field[t][t2].y -= .45, field[t][t2].y *= 2;
          else if (field[t][t2].y > -1 && field[t][t2].y < -1+.5) field[t][t2].y += .5, field[t][t2].y /= 5;
        } 
      }
    }
  }

It's sloppy code that I wrote about 10 years ago. Terra3D was a long learning process of experimentation and fumbling in the dark to produce the type of effects I was looking for. But maybe it'll help.

Steve Wortham
  • 21,740
  • 5
  • 68
  • 90
  • Thanks Steve for your interest and for the code. I am still working on my generator! Your code is good for a 3D flight simulator becasue in such type of games user is satisfied by having some lakes and mountains. He actualy don't care to much about the terrain structure and its logic. However, I am trying to accomplish something different. If you open an geographic album and you look at the terrain, you see that it is random but also comforms some rules. f.e. a river falls from mountains to some lake or sea, or mountains are arranged in some clusters. – Wodzu Feb 04 '10 at 09:36
  • Also the lakes and mountains seen from the top (with 2D view) will look artificial compared to the lakes and mountains from the geographic atlas. This will not be noticable in 3D flight simulator but it will be in some strategic turn-based games. Once again thanks for your answer. – Wodzu Feb 04 '10 at 09:40
  • @Wodzu - Sure thing. It sounds like you're much further along at this point (I just noticed this question is several months old). Indeed there are many details that I didn't delve into which you're obviously tackling head on. Good luck to you. – Steve Wortham Feb 05 '10 at 23:07
1

I know this is a really old question but I'm answering this for future people searching for a good terrain generator, like I was. Use the free version of World Machine 2. It is a terrain generator that can do exactly what you are asking and more. It has been used by professionals to generate images, 3D world terrain, and even for maps like what you are suggesting. Note that the free version is only for non-commercial uses.

Felipe M.
  • 31
  • 3
  • By the way, the website is www.world-machine.com – Felipe M. Feb 17 '11 at 19:35
  • Free is very limited on map size AND generates the map only once (or how many times you press the "generate" button), which is not very satisfying when you want a randomly generated map in your application :) – Matěj Zábský Feb 17 '11 at 19:46
  • Thank you Felipe M. The question is old, but I am still interested in any help. I am giving you +1 for your answer because the terrain generator for which you gave the link, produces a really nice looking terrain. However, this terrain still doesn't have any logical sense ;) Ok, it can generate you a mountain and a bit of water. But it is generating a "clusters" of the same objects. Where are lakes, rivers and other mountains? Those "objects" must be placed on map in natural way, the way like mother nature would do this :) For example: river flows down from mountain to lake. – Wodzu Feb 21 '11 at 11:21