Trees for my voxel world

Started by faustdonner, January 04, 2015, 19:04:22

Previous topic - Next topic

faustdonner

Hello there!

I am writing a voxel game right now and got the problem that I don't know how to place trees. I'm just talking about the placement. I tried using Perlin Noise, but it doesn't really work. Are there some techniques where i can enter the X and Z coordinate of my world to know if a tree should spawn?

Greetings faustdonner

Kai

Hey,

I am not a botanist, but from what I know it depends on the soil (alkaline to acid), the temperature and the amount of sunlight reaching that spot (for photosynthesis).
Of course trees also do not grow on plain ocean.

According to [http://www.waldwissen.net/wald/baeume_waldpflanzen/oekologie/wsl_waldgrenze/index_EN] trees do not grow where the temperature is below a certain limit.

So, you need to evaluate the kind of soil you have, the temperature there as well as the sunlight. If they are within certain limits, let some tree grow.
Also, certain types of trees have different requirements for these parameters, such as a cactus requires sun light but much fewer nutrient and water in the soil.

Also take care that trees have enough space between each other.
This affects the amount of sunlight each tree gets and the share of nutrient it can aquire from the soil.

Regards,
Kai

TaylorR

I have just completed that function in the voxel game I am making, it wasn't a simple task to come up with the plan.

Are you using "chunks"? i.e. generating the world small sections at a time, or simply generating everything as you go?

Also, are your trees going to be built of voxels, or will they be stand alone models rendered at a voxel location?

I'm not sure if my solution is the best solution but it works for me, I use chunks, and build them via voxel.
I can explain my solution if you are doing the same as me, well even if you are not my solution could give you ideas?





quew8

That's awfully pretty @TaylorR. Nice one.

And to add my own little bit to @Kai, whilst trees shouldn't be too close to one another, they do tend to be quite close because of the way their seeds/acorns are spread around. Ie forests/copses. But on the same token, some types of tree (like Yew trees) you will rarely find close together unless they are put there by human intervention. The reason for that is (I guess) to do with their somewhat odd lifecycles.

TaylorR

Thanks @quew8, always nice getting positive feedback :)

No reply yet from @faustdonner but I think I will outline my solution in case anyone else views this thread.

I have thought about all of the items that @Kai and @quew8 have stated around distribution and such, and my idea was to precompute a distribution map following the rules that I came up with.

I have generated a 512x512 png file, white background, and different pixel colors representing tree types.
When generating this image I added in all the distribution rules, and eventually built up a good one.

On game start up, the image is parsed and the data is saved in memory.

My chunk sizes are 32x32x32, so out of the 512x512 map I create 256 data containers (16x16).

The trees have a max x,z (y is height, don't need to worry about that at this point) of 9x9, and these may cross over up to 4 chunks so I have to take that into account.

Once the containers are created, I parse the map, create a data structure for each tree, and place them into all of the chunk data containers that they will intersect with, so one tree may be in up to 4 chunk data containers.

I plan to extend this to contain more than just the trees, this map can contain a lot of data, its just a png so there is 3 color channels each with a ton of values that can represent anything you want.

I don't think this is the most optimal solution, but it works great for me, and I do believe pre-computing the distribution rules is saving a bit of processing time.

@faustdonner, good luck with the project, feel free to ask more questions if you have them.


Below is the first basic map that I generated, it has 3 shades of green representing 3 sizes of trees, as you can see its very simple.

Note that this doesn't contain any information on, what you call in minecraft, "Biomes", I have done that separately, and this map only comes into play when within a biome that contains the trees.