TREES - A Tutorial on Variables

Last Modified: May 3, 1997

Initial TreeI have now completed version 3.0 of the "TREES" plug-in, changing it from a .POV file to a true .INC file. This greatly simplifies the use of the plug-in; instead of having to create a seperate copy of the tree.pov file for each different tree you want, you can now declare as many or as few variables as you'd like, #INCLUDE the trees.inc file, and repeat as many times as you like. Please see the seperate tutorial on the usage of trees.inc for detailed instructions and examples on including the file. This current tutorial provides a detailed description of the use of the many variables available to affect the appearance of the completed tree objects.


Unless otherwise noted, all examples
throughout will be illustrated using the tree
shown to the left as a base, with only the
variables under discussion at the moment
changed from this original definition.

Overview of Tree Generation

Tree with Red FruitTo begin with, I'd better take a second to define some terms; the trees are created using random numbers and five nested loops, resulting in five levels of structure - these can be thought of as the trunk, limbs, boughs, branches, and twigs, and will be referred to by these terms in the rest of the document. When limbs branch off of trunks and boughs off of limbs and so on, I'll be referring to that as "splits" so as not to get it confused with the other meaning of "branch". The twigs are the only part of the tree that have leaves, fruits, or flowers; the remainder of the structure is bare. Also, fruits and flowers only appear at the tips of the twigs. This can be seen in the image to the left, where I've turned on "fruit" and made the color of the fruit be a very bright red. To make it easier to see where the twig tips are (and how many of them there are), I'll leave the "fruit" option enabled for the remaining examples.

The overall structure of the tree is controlled by a number of different variables; these can be divided into three categories - the random numbers used to create the tree, the allowable angles of splittings, and the numbers and sizes of components.

Random Numbers

There are three different random seeds used by the utility: SD1, which is used to control all of the splittings of the tree, SD2, which is used if the user want to switch from a fixed distribution of the leaves to a random one without the overall shape of the tree changing (more on this later), and SD3which is used for any other function requiring random numbers. The overall shape of the tree can be easily changed by simply altering the seed number used for SD1. The following three trees are created with settings that are identical, except for this single seed value:

Three Similar Trees

As you can see, not all seed values will produce equally believable and attractive trees; the centre tree in particular looks rather lopsided. As the actual shape of any given tree is formed from a complex interrelationship between all three of the categories listed two paragraphs back, you will often find that you need to experiment with a variety of different values to obtain the effect you're looking for.

Angles of the Splits

This brings us to the second category - the allowable angles of the splits. This is a fairly complex category, and tends to have the biggest effect on the shape of the tree. There is a maximum and minimum angle setting for each of the three major axises (X, Y and Z). There is a multiplier that can be used to increment or decrease these angles as the limbs branch. And there is the previously mentioned PlusMinus variable, used to control the change of direction of the terminal split of each section. To understand how these variables work, you'll need to understand how the utility creates the tree.

To begin with, the file uses a series of random numbers to follow a hypothetical splitting from the trunk thrugh a limb, a bough, and a branch, finally reaching the cluster of twigs that will be attached to that branch. It then begins assembling this structure in reverse, from the twigs back down to the trunk, re-splitting out to the twig level as necessary. You could simulate this decision-making process with a die; roll it once to determine how many limbs there will be. Roll it again to decide how many boughs the first limb will have; and again for how many branches the first bough will have. And a final time to determine how many twigs that branch will bear. Draw this many twigs and the branch they're attached to, then roll again to figure out how many twigs there are on the next branch over (or if there's only the one branch, how many branches on the next bough). The following diagram illustrates this decision-making process - the brighter parts have been "drawn in", the dimmer one are the ones yet to come:

Cartoon Tree

Small AnglesLarge Angles When "drawing" the tree sections, the file begins by creating a section so that it is running in the +Y direction with it's base at the origin. It is then rotated around the X-axis to move it off of the vertical, by an angle which falls between stated MinXDeg and MaxXDeg values - these values can be any number, but realistically speaking you'll probably find you get the best result with values falling somewhere between 10 and 90 degrees, that are at least 10 degrees apart but not more than 30 or 40. The tree shown to the left illustrates a tree with small minimum and maximum angles; the tree to the right shows one with large angles.

The section is next rotated around the Y-axis, again by an angle with MinYDeg and MaxYDeg values, which determines it's orientation about it's parent section. Unless you want to achieve a "windswept" or bonsai-like appearance, you should leave these values with a minimum of 0 and a maximum of 360. Allowance has been made for an additional rotation around the Z-axis, but it is strickly optional and you can get along just fine with both MinZDeg and MaxZDeg left at 0. Finally, the section is translated in the +Y direction by a distance that leaves it somewhere along the length of its parent section, which at this point has not yet been created. Once the necessary number of sections (and any relevant sub-sections) have been created, they are unioned together with the parent section, which then itself goes through the rotations, translation, and union described already.

Rotation and Union of Twigs and Branches

It should be noted that there are two exceptions to this Min/Max rotation rule: the topmost subsection (terminal branching) of any set of subsections will only be rotated by plus or minus the number of degrees stated in the PlusMinus variable; this is what causes the splits to continue on in more-or-less the same direction as their parent splittings did (or, more correctly given the drawing order, "will do"). Values from about 5 to 30 degrees generally work best.

Droopy Tree One interesting and usefull tip should be brought up at this point. Because of the way in which it is used to calculate the range of values (rotate x*((rand(SD1)*(PlusMinus*2))-PlusMinus)) you can force the terminal branches to always bend in the negative direction by specifying a negative PlusMinus value; please be aware that if you do so, it's maximum angle is as a result three times the size of the value actually used. This -PlusMinus method can be used to created "droopy" trees like the one shown to the left.

Bonsai-like Tree The second exception is that all limbs (initial splits off the trunk) are always allowed a full 360 degrees of freedom for their rotation around the trunk, as otherwise you get some EXTREMELY odd-looking and unbalanced trees if you start changing the MinYDeg and MaxYDeg from their defaults of 0 and 360 (they look wierd enough even with this caveat, see the interestingly odd example at the right). If you are actually aiming for an unusual, windswept, or bonsai-like appearance, then this is something you'll probably want to play around with. It's also one of the few times the ability to do Z-rotations may be useful.

Increasing AnglesReturning to all the MinXDeg, MaxXDeg, and so on variables, you may find that you'd like to do a tree whose branchs curve either more or less towards the tips. To allow for this, there are an additional three axis-specific variables - IncXDeg, IncYDeg, and IncZDeg. These allow you to specify an additional few degrees of angle to be added on to the initial minimum and maximum values. For example, suppose you want to increase your X rotation. Your initial values are MinXDeg=35 and MaxXDeg=55, and you specify a IncXDeg of 10. The tree will look like that shown to the left, and the actual values used for the minimum and maximum X angles at each of the levels will be as follows:
Decreasing Angles

You can, of course, also use this value to make the allowable angles smaller, by simply stating a negative value for it - the tree to the right is an example of this. And, of course, you can use the IncYDeg and IncZDeg on the other two axis if you're experimenting with values other than the defaults for these two rotations.


Should look familiar :)
Just as a reminder, here's our
original example tree again.
Except for the addition of the
fruit, all of the trees you've
seen so far have only had the
variables under discussion at
the moment changed from this
original definition.

How Many and How Big?

Number of Splits

We have now reached the question of how this routine figures out just how full a tree to build. This is mainly controlled by two variables, MaxSplits and MinSplits. These specify the maximum and minimum times that a section can subdivide into subsections (ie., how many twigs can split off a branch, branches off a bough, boughs off a limb, etc.). The higher these values are, the more "bushy" the tree will get. Of course, a little elementary math will also show you that every time you increase these numbers, the number of objects making up your tree will also likely increase exponentially. The original example tree, for instance, has maximum and minimum values of 4 and 3. It's made up of about 1340 objects. Here it is with two more trees, created with values of 5 and 3, and 5 and 4.

Three Increasingly Bushy Trees

The third tree is very bushy - lots and lots and lots of twigs and leaves and fruit. There is, however, a better way to achieve this same result; if you look at a tree, you'll notice that it usually has more twigs on a branch than branches on a bough and so on. To simulate this, there is a multiplier for the MaxSplits variable called IncSplits. When in use (ie., set at values higher than one) it will be used to multiply the maximum number of splits - and it "compounds", so be careful when setting it; as a little math will show you, even quite small increases to it can increase your maximum number of splits (and resultant number of objects) dramatically. For example, with our original MaxSplits value of 4, the highest possible number of twigs is 4 to the fourth power (not the fifth power, as even though there are five levels, the first, the trunk, is limited to having only one object):

4*4*4*4 =256 twigs
And the maximum number of objects in the tree (not counting leaves, fruit, or flowers, which tend to make up the bulk of the tree) is:
1+4+(4*4)+(4*4*4)+(4*4*4*4) = 341 objects
Of course, the random number generator would have to get a result of "4" every single time to get this many twigs.

A Nice Full TreeA Nicer Full Tree Suppose we set the IncSplits to 1.25? Now the number of possible splits at each level will be increased by a factor based on this value (converted to an integer as you can't have a fraction of a split). It would change our equations to read as follows:

4 * INT(4*1.25) * INT(4*(1.25*1.25)) * INT(4*(1.25*1.25*1.25)) = 840 twigs

1+4+(4*5)+(4*5*6)+(4*5*6*7) = 985 objects
Or, to put it another way, our trunk can still only have up to 4 limbs, but our branches can now have up to seven twigs. This tree is shown to the left. This, by the way, is the kind of place where being able to increase the spread (angle) of the splits as your approach the tips can come in very useful, as otherwise you end up having a tree with lots of leaves and twigs all crammed into a fairly small volume. The tree to the right illustrates the combined use of IncSplits and IncXDeg.

Size of Objects Being Split

The overall size of the tree is based on the variables BaseLen and LengthInc. The former variable is used for several purposes - it is the length of a twig, the radius of the base of the trunk of the tree, and the scaling factor used to scale the leaves and fruit to fit the size of the tree. It's default value is 1. To easily scale your tree up or down in size (thereby avoiding later rescaling an object that may be built of thousands, or even hundreds of thousands of objects), scale this variable.

Chunky TreeElongated Tree LengthInc is yet another multiplier - this one is used to determine how much longer a branch is than a twig, a bough is than a branch, a limb is than a bough, and the trunk is than a limb. You can make a compact, chunky tree by setting it to just a little over 1 (see left) or an elongated airy tree by making it closer to 2 (see right). You'll get very elongated trees if you go beyond 2 - and even 2 is pushing it.

And now it's time to explain just what objects are being used in the creation of the tree. Overall, it's an assemblage of cones, with spheres to smooth the joins. These spheres can be turned on or off using the BallJoint variable, or restricted to only working up to a specific level of detail in the tree by setting BallLevels equal to any value from 1 to 5. DON'T bother using 5 (or even 4, really) unless you're rendering an extreme close-up view of the tree; it'll basically double the number of objects making up the tree (exclusive of whatever's stuck to the twigs), as every section would then be made of a sphere-and-cone instead of just a cone. If the tree is in the distance, then you can probably get away with turning BallJoint off altogether.

Leaves, Fruits, Flowers and Finishes

Unless you're doing an early spring or late fall scene, you'll probably want to have leaves on your tree, and possibly fruit or flowers as well. There are a number of pre-defined shapes you can use for these, or you can use your own user-defined shape. There is also an assortment of pre-defined textures available for the leaves, fruit, flowers, and bark of the tree.

The selection of whether twigs are to terminate with a leaf, a fruit, or a flower is done using a variable called Tip, which can be given the values of 1 for leaf, 2 for fruit, or 3 for flower. There are also, for each class of object, variables that allow you to select the shape and texture of these objects. The following summarizes these variables and their options:

LeafShape
0=Default (Oval)
1=User-Defined (#DECLARE it as Leave)
2=Maple or Ivy (made of triangles)
3=Teardrop
4=Bent Leaf
5=Pine Needles
6=Oak Leaf (Material Map)
7=Gingko Leaf (Material Map)
8=Palmetto Leaf (Material Map)
Please note that since there's no way of the program figuring out if a user-defined leaf is being done using primitives or a material map, you'll have to include your own texture statement within your Leave declaration.
Different Leaves
LeafTexture
0=Default (PaleGreen)
1=User-Defined (#DECLARE it as Leaves)
2=Dark Shiny (Reflective) Green
3=Lime Green
4=YellowGreen
5=Wheat
Different Leaf Colours
FruitShape
0=Default (Small Sphere)
1=User-Defined (#DECLARE it as Fruits)
2=Large Sphere
3=Lemon
4=Banana (more like a sausage, actually)
5=Triple Berry
As with user-defined leaves, you must include your own texture statement as part of the user-defined fruit declaration.
Different Fruit Shapes
FruitTexture
0=Default (Red)
1=User-Defined (#DECLARE it as Fruity)
2=Orange
3=Blackberry
4=Peach and Yellow
5=White
Different Fruit Colours
FlowerShape
0=Default (Five-Petaled Flower)
1=User-Defined (#DECLARE it as Flowers)
2=Trumpet
3=Cup
4=Spiky
5=Spray of Arches
As with user-defined leaves, you must include your own texture statement as part of the user-defined flower declaration.
Different Flower Shapes
FlowerTexture
0=Default (White-Orchid Gradation)
1=User-Defined (#DECLARE it as Bloom)
2=White-Red Radial
3=White
4=Orange-Yellow Gradation
5=Purple-Violet Gradation
Different Flower Colours
BarkTexture
0=Default (Bumpy Brown)
1=User-Defined (#DECLARE it as Bark)
2=Birch Bark
3=Poplar (Greenish Tan)
4=Pine (Grays and Lichen Green)
5=Lighter Bumpy Brown
Different Bark Textures


NOTE - When creating new leaves, flowers, fruits, etc., be careful to make the new object out of as few objects as possible! Your tree will consist mainly of twigs and what's on them - and as your tree will likely have at least a few hundred twigs (see the section with all the math, earlier), every item you place on those twigs will appear multiplied by those same hundreds (or even - *GASP!* - thousands) of times. As a rule of thumb, leaves should be built out of no more than three objects, while fruits or flowers should top out at 5-8 objects.

In addition, there's also several variables that affect the placement and orientation of these objects. These are as follows:

LeafNum
The number of leaves to be placed on the twig - *PLEASE NOTE* that this does NOT include the leaf object at the tip of the twig, if that is the option you have selected for the twig tip (see above). The following shows a tree with the default three leaves, and one with five:
3 versus 5 Leaves
LeafRosette
The default arrangement for the leaves calls for them to be placed in a regular spiral down the length of the twig. For a different look, you can set this option to "True" and have them placed in a circular rosette-like arrangement approximately 40% down from the tip of the twig. Works nicely with fruit and flower tip-objects, but looks kind of silly with a leaf. The following detail illustrates this arrangement:
Closeup of Rosette of Leaves
LeafRandRot
Nope, this has nothing to do with mulching and composting the stuff that drifts all over your lawn each fall. As previously mentioned, the leaves are by default arranged in a regular spiral; this means they're distributed at regular intervals around each twig as well as along each twig. For a more organic look, you can set this to "True" and the leaves rotation around the twig will be turned over to a random number set (the one using the SD2 seed). And here's a detail, showing both the original regular distribution and the randomized distribution:
Closeup of Regular and Randomized Leaves
TipPercent
You might not always want every single twig to have the tip object, especially if it's fairly complex. By setting this variable to a decimal percentage value, you can control what percentage of the twigs will have a tip object.
50% Tip Objects
TipOther
The default tip object to use the remainder of the time is a leaf; if you would rather have it be a fruit or flower, use this variable to set it up, then the regular fruit or flower variables to define it.
Mixed Tip Objects

For examples of the use trees.inc file, please refer to the other tutorial.


My First POV Animation!
Please free to e-mail all comments, questions, suggestions, interesting "Tip" object code, typos, math errors, etc. to sonya_roberts@geocities.com. You are welcome to use, re-use, modify, pass on, pass around, pass up, and generally do whatever the heck you wish with this little .POV file of mine. My only request is that you acknowledge it's use in some way, shape, or form (especially if used for an entry in the Internet Raytracing Competition).

Sonya's Page of POV Stuff
Ms. Barrows' Consensual Reality