0
\$\begingroup\$

I'm currently researching the techniques of generating a procedural map. I've already found some methods regarding the mesh generation (e.g. variations of noise like perlin, simplex and cell, midpoint displacement and diamond square).

The next step for me is to determine the terrain type. The most easy way is probably matching a static value to the height value (e.g. everything below 0.2 is water, everything between 0.2 and 0.3 is sand, everything between 0.3 and 0.5 is grass, etc.). To make a more advanced version I can use temperature and moisture values for the biomes. I'd very much like to know other techniques to determine this.

I also want to place objects (like rocks, trees, plants) on the map, however I can not seem to find different techniques to research/implement this. I probably just don't know the name of the global technique to find specific techniques. I found the use of fractal noise with a variable for the probability, but I'd like to know more techniques.

So, let me know some of your techniques.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Right now this is phrased in a very open-ended way - "list any techniques related to this problem domain" - and questions like this tend to be closed as "too broad." I recommend narrowing the scope by specifying a particular target: "I want to achieve a generated result like [example]" or "I want my generated result to meet these [criteria] and not exhibit these [cases to avoid]" - this can help you get more focused answers, tailored to the results you want. (After all "Just generate some random numbers" is a technique - but maybe not one that gives outputs desirable for your use) \$\endgroup\$
    – DMGregory
    Feb 21, 2018 at 16:27
  • \$\begingroup\$ Well in terms of research it is not necessarily a broad question. He wants to know the different techniques so he can research them on his own. For a specific implementation however: yes, this is a broad question. But I think OP is pursuing the former of the 2. \$\endgroup\$
    – Starfish
    Feb 21, 2018 at 16:44
  • \$\begingroup\$ This question is broadly asking for more than one thing. As is, the questions are "what are techniques for determining terrain type?" & "what are techniques for placing objects?" \$\endgroup\$
    – Pikalek
    Feb 21, 2018 at 17:32
  • 1
    \$\begingroup\$ @Patrick2607 I would say that StackExchange Q&A isn't a great format for initial/exploratory research of that type, which is why we consider "how do I get started" and other broad questions off-topic here. Expert Q&A works much better once users have done a little legwork/background reading, identified one or more options of interest, and need expert input on a particular question or problem they've encountered regarding those options. For a case like this, you can get a decent survey of techniques used in the wild just by googling terms like terrain / biome generation / procedural placement… \$\endgroup\$
    – DMGregory
    Feb 21, 2018 at 17:57

1 Answer 1

1
\$\begingroup\$

If you want to place 100 trees per square-kilometer, then the easiest solution would look something like this (pseudocode):

for (int i = 0; i < 100; i++) {
     position.x = randomValueBetween(0.0f, 1000.0f);
     position.y = randomValueBetween(0.0f, 1000.0f);
     placeTreeAt(position);
}

This will usually give you results which look sort-of-OK at first glance. However, there are a few problems here:

  1. There will be exactly 100 trees per square-kilometer. This might or might not matter for your game.
  2. Clustering illusion. While the distribution of your trees will be perfectly randomly distributed (assuming you use a good RNG), it might not look random. This might not be so bad with purely cosmetic trees, but it might be worrisome with objects where tight clusters are bad for gameplay (like player start locations in a battleroyal game).
  3. It will place trees where there shouldn't be trees. You might see trees sticking out of rocks, growing on steep slopes, in the middle of a lake or even two trees so close together that their trunks intersect each other.

The first point is rather easy to fix if necessary: Just add a random number to the number of trees you want to generate:

int numberOfTrees = 100 + randomValueBetween(-10, 10);

for (var i = 0; i < numberOfTrees; i++) {
     position.x = randomValueBetween(0.0f, 1000.0f);
     position.y = randomValueBetween(0.0f, 1000.0f);
     placeTreeAt(position);
}

The last two points can be fixed by checking if the randomly generated position is actually a valid position to place a tree:

  • are there already enough trees in an x meter radius around it?
  • is it physically possible for a tree to exist at this position?

When the position is not valid, one option is to just skip it. This means you can no longer rely on the number of trees per chunk to be constant. Biomes which have a less "tree-friendly" geography will have less trees than the number of trees says it should have.

Alternatively you can run the loop until you found 100 valid positions, but keep in mind that this might take a while in very tree-unfriendly terrain (or even forever if there aren't 100 valid tree-positions at all in the chunk). So you might also want to set a maximum number of retries.

const int numberOfRetries = 10;
int numberOfTrees = 100 + randomValueBetween(-10, 10);

for (var i = 0; i < numberOfTrees; i++) {
     for (var j = 0; j < numberOfRetries; j++) {
         position.x = randomValueBetween(0.0f, 1000.0f);
         position.y = randomValueBetween(0.0f, 1000.0f);
         if (treeCanBePlacedAt(position)) {
             placeTreeAt(position);
             break;
         }
     }
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .