I’ve been wondering for a while now what is the best way to add trees to Train Game. Trees seem fairly important for a train game seeing as trains mostly travel through the countryside where there are trees. (Except for my daily commute to work through Slough where there are no green things.)
Anyway my first attempt was to use flat quads with an alpha-blended tree textured onto them. These are commonly called “billboards” if you didn’t know. The quads are then oriented to always point at the camera, hopefully giving the illusion of a fully 3D tree. While the maths to calculate the billboard orientation is a bit tricky, these trees are incredibly cheap at runtime. Blodgett was kind enough to use its artistic talents to produce some tree pictures for me:
While these trees look quite good from a distance, when you get up close and especially when look from above the rotation and obvious flatness is a bit disconcerting.
So next I tried a completely different approach to tree rendering. Inspired by examples of procedural plant generation e.g. here and here I implemented an L-system tree generator – albeit a much simpler one than in those examples. Here’s a screenshot showing some examples of trunks and branches:
I think these look rather good. Unfortunately there are two problems: rendering them is incredibly slow, and I found it very difficult to generate decent looking leaves. Since trees are only scenery and I’d like to have a lot of them on the screen at once, it’s not really acceptable to have them use more of the render-cycle budget than the train itself. Simplifying the branch structure and using square leaves, plus some OpenGL performance tricks, gets them running at a reasonable speed, although they don’t look nearly as good:
Incidentally, these screenshots are showing the new map editor which ditches FLTK and replaces it with my own home-made XML GUI toolkit. I’m rather pleased with it design-wise and it plays much nicer with the rest of the game (it renders directly onto an OpenGL texture).
Anyway, back to trees and my conclusion from the L-system experiment is that I didn’t like them that much, they were expensive to render, and perhaps most importantly, they didn’t fit in with the rest of the artwork in the game (in the “childishly cartoonish” style). So I abandoned the code in a git branch and went for the simplest option: make some models of trees.
Thus far I’ve made two tree models – a pine tree and an apple tree – both around 80 polygons. They are very cheap to render – cheaper in fact than the billboard trees since I have an optimised VBO-based mesh renderer.
I really do like these trees! I think they’re cute but I’m a little worried other people will think they’re daft. Anyway, I’m sticking with them for the time being.
In a month or so I will tidy up the code in git and release another demo/preview version. Hopefully there will be some useful features by then ;). In the meantime you could look at my gitweb if you’re curious or clone
Thank you muchly to blodgett for assisting with tree evaluation!