My tree-building code is a lot less sophisticated than I planned. This is really rare in programming. (And, I expect, in most other forms of engineering. Problems usually become more complex as you examine them in greater detail.) Still, this is in keeping with the spirit of this project, which is to solve 90% of the problem with 10% of the effort.
The first step in creating trees is to generate the trunk. I’ve got a few parameters governing how much they bend, how tall they are, the width of the base, and a few other minor details.
Most trees have branches. (Two exceptions: Conifer trees have their foliage affixed directly to the trunk. Trees intended to form a canopy simply have one huge umbrella of foliage at the top of the trunk.) Branches reach upward from their point of origin, but there are two ways of doing this. On the left you can see branches that reach outward, then upward. On the right you can see ones that go up, then out. The latter makes the branches look “droopy” and heavy. The former makes the tree look strong and vibrant.
I originally had branches that extended down from their point of origin, or ran level. Those looked wrong, or boring, so I removed that option.
Branches all end in a cluster of foliage. Foliage shapes vary. Some are roughly (VERY roughly) spherical. Some are bowl-shaped. Some are umbrella shaped. Some are big droopy things. I used to have foliage clusters that were made of intersecting panels (like the grass) but they were kind of hit-or-miss. Even the “good” ones seemed poor compared to the other types.
The last step is to hang some moss or vines on the branches. This is only done to trees that will grow in the hottest, wettest climates. As it builds the branches, it keeps track of the points along the underside of the branch. If the tree ends up flagged for moss, it uses these points to hang a “curtain” of polygons under the branch.
This was intended to be my prototype. I was going to build this much, see how things looked, and then add to the system once I saw what was needed. It turned out that my prototype looked good enough. I’d hit the right style on the first try. The only real improvement I’ve made is to remove the various options that made boring trees. (Level branches, etc.) The process was more about taking away options than adding features.
What I quickly discovered was the the whole thing more or less hinged on the texture and coloring. That’s what makes these trees work. See, each tree has it’s own texture:
When a species of tree is generated, the program creates a texture just for that tree. The texture is 1024×256, and is divided into four panels. The first is the bark, the second is the foliage, the third is the hanging moss / vines, and the fourth is a picture of the tree itself, which I’ll talk about in a minute. Doing things this way allows me to draw an entire tree with a single pass, since there’s no need for any sort of texture-switching. Panel three is a bit wasteful, though. It’s mostly transparent empty space. I guess I can pretend that empty space is reserved for future use, and not wasted. Doing so doesn’t make the program perform any better, but it lets me stop feeling guilty about it.
Here is how it makes that texture:
These are the available bark textures. The first two I made by hand, by scribbling in Paint Shop Pro. The second two are just filters built into PSP. Like the trees themselves, I designed these quickly, planning to replace them with “real” art later on, only to discover the prototype stuff looked pretty darn good.
First, it draws a flat-color box into that first frame, colored to whatever bark color I’ve chosen for the tree. Then it takes one of these bark textures and blends it, darkening it in places.
For the foliage… I’m not much of a pixel artist, but I managed to come up with some assets that get the job done. When a tree is generated, it selects one of these foliage types. Then it renders a whole bunch of them into that second frame. I called these little splotches “leaves”, even though they’re really “pictures of groups of leaves”. Now that I’m writing this post, I’m seeing that a bug has cropped up. I designed it to draw each leaf a slightly different color. It’s supposed to scatter them a bit around a common hue. I can see now that at some point I broke that functionality, because the foliage is a solid color. I wonder when I did that?
The third frame gets a random stripe of moss / vines / whatever this crap is, colored to match the tree itself, but slightly darker. (I tried using a different hue. I mean, it’s another plant, growing on the tree, so it shouldn’t have to be the same color. Surprisingly, it looked wrong. It looked like there was something wrong with the texture, not like the moss was just a different color.)
There are three levels of detail for trees. Up close, the branches and trunk are round and smooth. At a distance, the trunk is reduced to just 3 points around, so it’s sort of wedge-shaped. If you were to chop it down, the stump would be a triangle. The branches are only two segments around, which makes them 2-dimensional. It sounds awful, but they look passable even at thirty meters or so. (And the player will never get that close. I don’t think you can get closer than 100 meters before it swaps out the cheap tree for the good one.)
At extreme distances, it takes the picture of the tree from panel four and just puts it on a billboard. Here is a normal tree:
And here is the same tree in glorious 2D mode:
Wow. You know, seeing these side-by-side, I have to say the cheap trees don’t look half bad, considering. Of course, the player will never be able to get anywhere near these things.
|As requested, a screen shot without the development text. Click for larger view.|
Trees are very much a feature to be tinkered with. Unlike terrain, where my goal was to finish the feature and move on, trees are an informal, self-contained system that I can revisit again and again as I get new ideas or feel the sudden urge to experiment.
I don’t think we’ll have a “week 5” video this Friday. I’m busy with other work, and I haven’t added anything that I can put in a video. (It’s pretty hard to demo “better memory management” in a video.)
Please tell all of your rich investor game publisher friends about my project. Thank you.
Game at the Bottom
Why spend millions on visuals that are just a distraction from the REAL game of hotbar-watching?
The Best of 2013
My picks for what was important, awesome, or worth talking about in 2013.
Silent Hill 2 Plot Analysis
A long-form analysis on one of the greatest horror games ever made.
Crash Dot Com
Back in 1999, I rode the dot-com bubble. Got rich. Worked hard. Went crazy. Turned poor. It was fun.
The No Politics Rule
Here are 6 reasons why I forbid political discussions on this site. #4 will amaze you. Or not.