With apologies to the late Bob Ross. His work has been widely criticized, but this project shares a certain kinship with his work: We’re not trying to make Great Art, we’re trying to make “Pretty Good Art” in 10% of the time. I imagine that if paintings could somehow cost as much to produce as videogames, the “Bob Ross method” would be the only way to get anything done.
Hopefully my tree-making skills are better than my photoshopping skills.
Minecraft has proven that a large number of people are capable of accepting a stack of one-meter cubes as a tree, both visually and as a gameplay conceit. Perhaps even a majority of the people are capable of embracing this sort of abstraction. I imagine there are people who are not like this. There are those who look at Minecraft and scoff, who refuse to enter a world of such low fidelity. I am not interested in attempting to entertain those people. I don’t think I can. It’s too expensive. I’ll leave them in the hands of id Software and Crytek.
For those who can look at a pile of blocks and see the the emergent cubic beauty, I hope to create something a bit different. Not cubic, but… chunky. Low poly, colorful, vibrant, and varied. Somewhere between Minecraft and World of Warcraft in its first years.
Now, there are a LOT of techniques for making trees out there. Check out this one, which does complex maths on… geeze. I duuno. There’s a lot going on there. The point is, if those trees are under 10k polygons I’ll eat my mouse. Still, there is a lot to think about in that post. (And some of the other things people have linked. Thanks.)
I actually wrote a tree generator way back in the last few months of 2000. Like a lot of the experimental work I did for my employer at the time, it was met with polite admiration, followed by indifference. “That’s really cool, Shamus. Seriously. Nice work there. But it is completely useless to us. Thanks anyway, though.”
The source for it is long gone, but I still have most of the concepts in my head. That tree builder accepted three pieces of information:
- Properties: This was a huge list of fiddly little details like: How tall is the (fully grown) tree overall? How far between the roots and the lowest branch? How many branches overall? How straight is the trunk? How wide is it? What colors are the bark, and the leaves? How much do the branches lift or sag from their origin?
And so on. This list of properties could be thought of as the template for the species as a whole.
- Seed: Not “seed” as in “plant seed” but “seed” as in “random number seed”. (Although the two concepts overlapped here in a way that greatly amused me.) Basically, change the seed and you’ll change a bunch of numbers like the shape of the bending and the branch positioning. Create two trees with the same properties but with different seeds, and they’ll look like two different trees of the same species.
- Age: On a scale of 0.0 to 1.0, how close is the tree to full grown? You could manipulate this number to smoothly grow a plant from sprout to full-grown. Very slick.
Now, the “smooth growing” thing added a lot of complexity. I don’t think I’m going to need that here, so I’m going to leave that out for now.
My polygon budget in 2000 was somewhere between 50 and 100 polygons. Now, given the massive increase in computing power since 2000, I’m sure trees today are many times heavier than that. I wouldn’t be surprised to find out the average Crysis tree clocks in at 1,000 triangles.
However, I need a lot of trees. Most games are focused on delivering a highly polished, high-detail scene of very limited size. I’m aiming at lower platforms AND trying to extend the view distance at the same time, which is like trying to make a car that burns less fuel and goes faster. This is usually an either / or arrangement. If you’re making gains in both of these areas, odds are you’re making big sacrifices elsewhere.
The thing about view distance is that it gets ridiculously expensive to make even small increases, because it’s based on area. If you have a view distance of 100 meters, that means you actually need a 200×200 meter area of viewable stuff, with the player at the center. (Unless you can persuade the player to never turn around. Let me know how that works out.) That’s 40,000 square meters. Now let’s say you want to increase your view distance to 150 meters. That means you need an area of 300×300 meters, for a grand total of 90,000 square meters. A 50% increase in view distance resulted in a 125% increase in resources. I don’t care how much computing horsepower you throw at a problem, sooner or later those numbers will kill you.
While a lot of games sprinkle a few trees at the edges of the map and call it a day, I might have hundreds of them in view at once, so I can’t afford to spend too much on them. I think 200-300 polygons is a good starting point.
So my trees are dead simple: When a new map is generated, it creates a selection of trees for various climates. It actually makes a table of them. One axis of the table is for moisture, the other for temperature. So, once the climate is decided for a region, it looks up in the table for the most appropriate tree. Here is an example map:
|The grey circles are mountains, the blue circles are “lakes”. The light squares are plains. I’ll be showing these off in a later post. For now, just note the climate. The coloring tells us that the arctic climate is to the south, and the tropic climate is to the north. The land gets drier (more brown and yellow) as you go east, which means the wind is from the west.|
For development, I’m using a 5×5 table of trees. (5 different moisture settings, times 5 different temperature settings, for a total of 25 different trees. Er, actually, 24. “Tree zero” is for areas with minimum moisture and minimum temperature, and means “no tree at all”. We can argu about whether or not that should count as a “type of tree”, but that’s a problem for a philosopher, not a programmer.)
Here I’ve given each tree a random unique color. Areas with the same color will have the same tree type:
If I up the tree grid to 10×10, I’ll have 100 species of trees. It end up looking like this:
I like the complex shapes I’m seeing here. That’s not random. That’s emergent, based on the cheapo climate simulation I outlined before.
You might be worried that these hard lines will look odd, “You mean you’re walking along and suddenly you come to an invisible line and all the trees are different?” But the trees use the same scattering code that I used on the grass back in part 3, so the change is not instant. It’s staggered enough to hide the boundaries, at least.
The trees draw their foliage color from the same palette as the grass. So, tropical trees will be deep greens, and desert trees will be pale greens and yellows. Trees in cold climates will have a bit of blue in them. Similarly, the bark color draws from the dirt palette. Note that I’m not forcing the tress to always match the grass. I’m just drawing from the same palette. This means trees will still stand out, but the two together will still look like a good thematic match.
Next time I’ll actually get down to talking about how the trees are constructed.
Secret of Good Secrets
Sometimes in-game secrets are fun and sometimes they're lame. Here's why.
What did web browsers look like 20 years ago, and what kind of crazy features did they have?
Pixel City Dev Blog
An attempt to make a good looking cityscape with nothing but simple tricks and a few rectangles of light.
A look at the main Borderlands games. What works, what doesn't, and where the series can go from here.
The Death of Half-Life
Valve still hasn't admitted it, but the Half-Life franchise is dead. So what made these games so popular anyway?