Plants 2: Secondary Growth
This week was a lot of learning about how plants grow and develop. As I've discovered, botanists know a whole lot about how plants grow, and it is a very deep Wikipedia hole to fall down. Fortunately, the L-system model that I'm implementing fits the natural world quite well, almost as if it was designed to do exactly that.
The major technical addition this week was a basic system for secondary growth. In plants, primary growth is the addition of new features, like new stems or leaves, which pretty much only occurs at the tips of stems and roots. Secondary growth is the enlargement of already existing features, such as leaves growing larger and stems growing longer. Under the strict definition of an L-system, this is accomplished by iterating all the pieces of the plant, e.g. a stem piece in the middle of the plant turns into two stem pieces, and grows the whole plant upwards. Although this has a certain mathematical elegance, it is also quite hard to render nicely and leads to a lot of vertices very quickly. So instead, I just made each individual piece scale itself up over time.
The goal of these plants was to create a generic system that could grow a variety of different-looking and different-behaving plants, without a lot of input from me, as well as dynamically reacting to the world around them. As such, I wanted to make the secondary growth a bit smarter than simply expanding the plant over time. This essentially became a problem of resource distribution. I quite like these kinds of problems, and as such got bored with research much faster, so the system I ended up with is only loosely based on real world mechanism.
For my purposes, the two most basic resources available to plants are sunlight and water. At the moment, the plant pieces I have are stems and leaves, and with the important exception of flowers that seems to cover most bits of quite a lot plants. Leaves gather a lot of sun, but also lose a lot of water. Stems, as far as I could tell, aren't very good for anything in themselves, and act more like infrastructure. If the plant isn't in dire need of anything, it's nice to have more stems, to enable future growth.
Playing this out in very loose terms, this gave me four different environments: high-water high-sun, low-water high-sun, low-water low-sun, and high-water low-sun. Under my system high-water high-sun would produce similar shaped plants to low-water low-sun, just much larger, which I think lines up somewhat well with reality. More interestingly, high-water low-sun environments will lead to very leafy short things, and low-water high-sun environments will lead to very stem-y plants with small leaves. This is somewhat in line with how real plants work, or at least could be rationalized to how they should work. More importantly, it can be a clear and understandable reaction to player interactions, which was the goal.
The actual implementation of this was fairly simple, and mostly came down to tweaking numbers and math to avoid weird things.
Because leaves give more sun based on their size, it's important to scale the cost of growth non-linearly, or else the plant will fully rely on the first leaf, and grow it to become a mega-leaf.
In the end I got something that works fairly well I think. It needs a lot of tweaking, but it'll do for now.