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 http://www.nickg.me.uk/~nick/git/traingame.git
.
Thank you muchly to blodgett for assisting with tree evaluation!
this (travesty) video has some examples of trees in a train game:
http://www.youtube.com/watch?v=TsPFz4h0CUc
February 28, 2010 @ 2:12 pm
They’re using billboards I think. It looks OK because their camera angle is restricted. I found that as soon as the camera is looking down above about 45 degrees orienting the trees to point at the camera looks silly because they appear to be falling over, and leaving them horizontal also looks silly because they’re obviously flat and rotating.
February 28, 2010 @ 2:18 pm
Here’s a similar effect in a more realistic game:
http://www.youtube.com/watch?v=FcO6PkaN36s&feature=related
I think what they’re doing here is putting two billboards with the same cut-out tree photo at right angles to make an X. But not sure.
I think these two youtube videos illustrate the extremes that I would like Train Game to fall somewhere in the middle of :).
February 28, 2010 @ 2:36 pm
looking at that realistic game, i just had a funny thought.
do you think people have ever made a tube train simulator?
one dingy tunnel after another, all pretty much exactly the same. mostly pitch black. occasional flattened mouse.
a cursory search did not find anything surprisingly.
March 3, 2010 @ 3:11 pm
> do you think people have ever made a tube train simulator?
Don’t be silly – of course they have! E.g.
http://www.youtube.com/watch?v=22yya6chB7c&feature=related
http://www.youtube.com/watch?v=nrSGRU6NZwI&feature=fvw
Sadly I was already aware BVE had an underground mode :-/
March 3, 2010 @ 9:09 pm
blodgett find tunnel strangely hypnotic
maybe is naptime
March 3, 2010 @ 11:04 pm