A small post about trees

Thu 12 Apr 2018

Author: Sam Pickett

As requested by @MutateGames on Twitter, here is a small explanation of how we generate the trees in First Light. To begin with, each tree is generated from three floating point numbers, generated with simplex noise. The first two define its location in the chunk. The tree is only generated if this location is suitable, i.e. correct surface type, within slope constraints. The third number is actually 'split up' into multiple numbers by shifting the decimal point and discarding the whole number amount. Not sure if that makes sense, but just look at the picture. This step isn't important. The purpose is to save us generating a bunch of extra noise values.

 

So, each type of tree has a number of different constraints (min height, max height, min radius, max radius, etc.). The numbers we just made are used to scale between these constraints to give us the height values, etc. for this particular tree. Generating the tree trunk is very simple. Its just a straight column that extends a certain distance on each axis, and also has a maximum Manhattan distance to let us give the trunks rounded corners without actually constraining it to a radius (because we like the square-ish look). The roots are added simple by setting a particular pattern of blocks at the base. There's no trick to this. The leaf clumps (I need to think of a better name for those...) are laid out at angular steps around the trunk. The angular step between consecutive leaf clumps is always the same for a given tree. There is also a vertical step between each leaf clump, which also remains the same per tree. In the tree pictured below, the angle is quite small, so the leaf clumps form a spiral around the trunk. Larger angles tend to give a more random look. There is one final leaf clump added at the top of the trunk.

The distance of each leaf clump from the trunk varies with its height. The leaf clumps are furthest from the trunk in the middle, and closest at the top and bottom, giving the tree a rounded shape overall. Generating the leaf clumps themselves is trivial. Its simply squashed sphere.

To generate the branches, we find the distance along each axis from the centre of the trunk to the leaf clump. The branch is formed by traversing the longest horizontal axis first, then the shortest, and finally the vertical axis.

And that's pretty much it! There are slight variations here and there, but the general idea is the same.

Back to blog