For our second RPP game, we wanted to make a game about practicing meditation. One of our ideas was to have a bonsai tree grow as the game is played, having it react according to the player’s performance. We thought it would be great feedback for the player and it could serve as the centerpiece for our visual stage.
Since we only had two weeks to finish this project, I looked online for any starting points for making a tree procedurally. I happened upon this great resource. I love reading blog posts like this for inspiration, and in this case, it also included some source code to start from!
Growing in Realtime
The main issue with the tree is that it was not generated in realtime. Each branch of the procedural tree is made up of rings, much like a real tree. Starting from the base, the ring will shrink and modulate every iteration. To get the tree to grow gradually over time, I spawned the next ring at the same position and size as the previous ring, and I had each vertex interpolate to its intended location over a set time. This provided the illusion that the tree is growing gradually instead of in discrete chunks, and allowed us to keep the number of triangles on the tree at a reasonable level.
The order that the branches grow are a result of the recursive nature of the algorithm. Each branch represents the result of a single function, which then calls itself repeatedly for each different branch. For every ring on the tree, there is a probability that it will spawn a new branch. The exit conditions of the function are if the radius of the branch ring is below a threshold, or if the maximum number of branches has been reached.
One thing that the reference did not touch on was leaves for the tree. Given our team’s time constraint, we had to quickly come up with an option that we all liked. One of our artists came up with the idea of using a billboarded texture for our leaves. The implementation is quite simple: whenever a branch ends, spawn a leaves sprite at that location. The results were fairly compelling, and I believe the leaves add a whimsical nature to the tree’s overall aesthetic.
You can watch some of the gameplay below: