DevLog #007 – Adding Trees

Part of a series of posts in which we write a voxel engine from scratch for Android.

No terrain would be complete without trees, so we’re going to add a way to grow procedurally generated forests in grassy areas. There’s nothing too complicated about this, but getting them to look right will take a bit of patience as we try different trunk heights and canopy sizes.

We can use our noise function to decide where patches of trees will grow, but they’ll always be limited to grass blocks, and the heights will be chosen randomly between 3-7 blocks tall.

The canopies follow a fixed-pattern depending on the trunk height, with some randomness around the edges and corners. We also have different leaf and trunk types to add some variation.

The only real challenge here was the fact that although trees are generated on a per-chunk basis, they can often extend outside the chunk bounds, so we had to come up with a way to add tree-blocks to neighboring chunks which may not have been loaded yet.

Another challenge that we’ll have to tackle later, is avoiding situations where a tree-trunk is destroyed, leaving the tree floating in mid-air. That might be good enough for some games, but we don’t want it in ours. We’ll probably have some kind of upward block-traversal to make sure entire trees are felled in one go.

Well this one was short & sweet, but as the engine progresses, we’ll be posting more about creative changes and less about technical stuff, so I guess we’ve hit something of a milestone.

Share this