2D Forest Generation

Started by
13 comments, last by Cornstalks 11 years, 11 months ago
Heya, i'm making a 2D game with rogue-like terrain generation, and was wondering what is the best way to generate a forest? I've looked into generation via perlin noise, but I couldn't find a good tutorial that thoroughly explained all the concepts. Is there a simpler way that creates perlin-noise like generation?
Advertisement
Actually, perlin noise may not be the ideal way to generate a 2D forest. Depending on how large your world is (or is it infinite?), you may be better off with a biological model, e.g. start with a few trees scattered around the place, and apply a rule (similar to a cellular automaton) that says, that, for instance if the area next to a tree will become a tree if it has sufficient light or is flat enough, etc... (you can use any sensible condition that would make sense in the real world), or that a tree will die if certain conditions are met, then iterate it a few times to "generate" the forest. It will probably look more realistic than a perlin noise algorithm if done right.

Otherwise, if you want/need to use perlin noise, in general the simplest way is to generate it, and then have the terrain become a tree if the value of the perlin noise at that point is greater than some arbitrary number (tweaked as needed). Many variations are possible, such as having the tree height (or type) vary according to the perlin noise value, you can also combine more than one noise value to make interesting patterns, etc...

Or do you need help actually generating the perlin noise in the first place?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

I once scripted a messy tree system, where each tree grows (growth slows down the bigger it grows) and once in a while the tree drops some apples, which then fall in a 45 degree angle (yes, i know) and take a while before they spawn a small sapling where they are, but only if there is no other trees nearby.

because trees grow fast at the start, it leads to few small trees and many variable height big trees. It will take a very long time to get big old trees, but a young forest will grow fast. When the trees reach a certain age they will fall and disappear after a while.

Probably not useful at all for your situation, but it did make some nice small forests that didnt look that ugly apart from the fact that they were made of blocks.

o3o


Or do you need help actually generating the perlin noise in the first place?


Yep, that's what baffles me. A lot of articles deal with implementing your generated perlin noise, but none of them explain perlin noise well enough for me to understand, nor do they show you how to create perlin noise.


Actually, perlin noise may not be the ideal way to generate a 2D forest. Depending on how large your world is (or is it infinite?), you may be better off with a biological model, e.g. start with a few trees scattered around the place, and apply a rule (similar to a cellular automaton) that says, that, for instance if the area next to a tree will become a tree if it has sufficient light or is flat enough, etc... (you can use any sensible condition that would make sense in the real world), or that a tree will die if certain conditions are met, then iterate it a few times to "generate" the forest. It will probably look more realistic than a perlin noise algorithm if done right.


Wouldn't that cost a lot of speed though?

Wouldn't that cost a lot of speed though?

Yes, well, nothing is free, if you want good stuff you need to put work into it, and that applies to computational work too smile.png But depending on how you generate your map, you should be able to precalculate it efficiently. You can also the same kind of stuff with water, which would look very realistic (put a little water source in the flank of a mountain, and use a rule that says that a point next to water becomes water if it has a lower elevation - and add some random variation for good measure, it will produce a nice river down the mountain which may evolve into a lake depending on the topology at the bottom of the mountain). So you can use it for a lot of different situations (another I can think of is procedural weather).

Yep, that's what baffles me. A lot of articles deal with implementing your generated perlin noise, but none of them explain perlin noise well enough for me to understand, nor do they show you how to create perlin noise.[/quote]
Have you looked at this? It's a good start. The basic idea is to convert white noise (which is mostly unusable directly for all purposes as it is way too unpredictable) into something that looks and feels more natural and regular while still retaining irregular patterns. There are many ways to achieve this, and Perlin Noise is just one way of doing it. There are many others (such as fractional brownian motion, FFT-based approaches, etc...). The layman's definition would be "smoothed random noise" but that is not quite accurate.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


Actually, perlin noise may not be the ideal way to generate a 2D forest. Depending on how large your world is (or is it infinite?), you may be better off with a biological model, e.g. start with a few trees scattered around the place, and apply a rule (similar to a cellular automaton) that says, that, for instance if the area next to a tree will become a tree if it has sufficient light or is flat enough, etc... (you can use any sensible condition that would make sense in the real world), or that a tree will die if certain conditions are met, then iterate it a few times to "generate" the forest. It will probably look more realistic than a perlin noise algorithm if done right.


Hmmm, I guess i'll go with this method then. Perlin noise is way too complicated. I just have one more question, you said that I could place a tree next to another tree depending on whether the terrain is flat enough, or has sufficient light. How would I calculate those values in the first place without using perlin noise? =(
Hmmm, I guess i'll go with this method then. Perlin noise is way too complicated. I just have one more question, you said that I could place a tree next to another tree depending on whether the terrain is flat enough, or has sufficient light. How would I calculate those values in the first place without using perlin noise? =([/quote]
How did you generate your terrain? I assumed you had terrain generation working since you were on to forest generation, that would allow you to use terrain elevation data easily. Please correct me if I was wrong, for terrain generation there are some alternatives to perlin noise, of course (and you will find lots and lots of information about that online, just type "procedural terrain" and you're set for hours of reading!)

As for the lighting condition, it can be as simple as looking at what's in the neighbouring terrain e.g. if a spot is completely surrounded with trees it will get less light, so it's less likely to grow a tree there (this directly relates to forest density, as various tree types are more or less tolerant to lack of sunlight). But the lighting condition isn't necessary for now, you will get an already good result if you only use flatness, you can improve it later on.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Take a look at LibNoise (http://libnoise.sourceforge.net/). It's a library that can also generate fractal-based noise, which might be what you are looking for.

[color=#515357][font=Arial, sans-serif]


In procedurally generated or procedurally augmented scenes, a common problem is how to scatter something around in a way that looks natural. For example, a landscape might have trees that are evenly scattered, either sparsely as on an African savanna or densely as in a forest. Also, trees are generally surrounded by other vegetation, which is also scattered.[/font][color=#515357][font=Arial, sans-serif]


Suppose you are tasked with developing algorithms to facilitate this scattering. This article looks at various approaches and problems you might encounter.[/font]
[color=#515357][font=Arial, sans-serif]

[/quote]

[/font]

http://software.inte...tic-landscapes/

okay , lest say:
-1 once the forest is generated it is reproduced to player no matter what scene he is actualy in active.
-2 player cannot get back in space (thus in time) and see what he has been generated originaly, and gets regenerated it back
-3 player is seeing to large differentiations in space of forest, detail and enormous.
.......
take these desing patterns and decide what you can simulate on 500mhz cpu and 500mhz12x gpu.

This topic is closed to new replies.

Advertisement