Raytracing: Grass and Trees

[June 2001] The first thing I did was trees. Trees are hard, and I was looking for a challenge. The branch structure is generated by a Perl script. We start with the trunk and move along it in discrete intervals. At each step, the trunk gets smaller, either linearly or exponentially, by a certain amount. There is also a certain probability of there being a branch, which will be in a random direction if it occurs. The branch will be a certain fraction of the trunk's radius. The branch is then recursively modelled just as the trunk was, to provide sub-branches. Once a branch has reached a certain size, it stops. Leaves are added to branches at regular intervals once they are under a certain size (so as to avoid leaves on the trunk).

The second thing I did was grass, which was actually quite a bit easier than the trees. Each blade of grass is simply made of two triangles; think crabgrass shape and you'll understand. They're then just distributed on a grid with random rotations and position variation, and random color fluctuation. The results, in my opinion, look quite reasonable.

The image on the right shows the first actual scene. It is, unsurprisingly, trees and grass. The grass doesn't go all the way to the horizon because it becomes computationally infeasible to model the grass that far.

Most raytracings, it seems, have complicated and tedious-to-render textures, but relatively simple shapes for the actual objects. These scenes are quite the opposite. The textures are simple (the leaves and grass are all solid colors), but the number of objects is high. The scene on the right has several hundred thousand, and the most complicated scene I've done so far had over one million. Thus, the actual limitation is not processor time (these scenes render in under an hour, and several days is not unusual for raytracings) but memory.

Thus, some sort of hack for faking the grass was required. It was suggested to me that it might be possible to space the blades farther apart as distance increases without much loss. I did that, and also increased their size as distance increses. On the left is shown the results. The trees are not exactly the same as before, but they were generated from another run of the script with the same parameters, so they have an approximately similar shape.

The horizon is faked; I darkened the image with a gradient in the Gimp. This was much easier than screwing around with fog the equivalent effect, and in my opinion it looks fine. As fine as a completely black sky above illuminated trees and grass can look, anyway.

The image to the right takes the same trees and grass, but looks at them from much closer. It also adds a sky. The leaves here are more complex than the ones in the other images, with distinct stems and veins. You can also see the bark on the trees; I'm not really happy with the bark, but I've yet to figure out how to improve it much.

There are only six distinct trees in this one, but they're used multiple times with different orientations. It's hard to tell that they repeat. I couldn't use any more; this image was pushing the complexity I can render as it was. I used a machine with 768 MB of RAM to raytrace it, and it used the entirety of its available memory.

I've used some other cute tricks. In my first attempt, the bottom of the leaves was all the same color - none of the direct light was hitting them, so they were illuminated with ambient light only, and since they were all the same material, they showed up all the same color. I didn't want to actually change the leaf color, so I added a dim shadowless light from the bottom, so that the leaf color would vary depending on angle. I like the result.

The large version of this image is actually in PNG format instead of JPEG, and it's half a megabyte. The JPEG version, while significantly smaller, had visible compression artifacts between the sky and branches; if the quality was increased enough to remove them, it became larger than the PNG version.

This picture is nothing new, it's just a top view of a forest made of the same trees I've been using all along. I wanted to do one view like this before I finished with the "grass and tree" theme. This one doesn't have any actual grass, because it was up to around 800,000 objects with just the trees, and it wasn't very practical. It doesn't really matter, though, because there's almost no light hitting the ground and you couldn't see it anyway.


[October 2001] While working on the normandy picture, I rewrote the grass and trees to use a mesh of triangles, reducing memory requirements significantly. However, I have yet to make any grass/tree images which take advantage of this improvement.
This page most recently modified on: Friday, 03-Sep-2010 04:52:09 EDT

the w3c sucks, but this page is still valid
Copyright (C) 2010 by Terran Melconian. You may mirror this page for personal use. Images may be downloaded and printed. All other rights reserved.
For questions, purchasing prints, etc, email