Trees and how to make custom ones
NOTES TO EDITORS:
Ok, parts of the tut up to "Editing the particles themselves (size etc):" (working on this one now) can now be edited. Sorry for before.
greebo: Sorry, didn't realize you were still working on the article.
Dram: Nah it's cool, thanks for fixing the bits :) I learnt a little bit more :) I'm grateful you maintain the wiki :)
Using, and creating TDM trees with particle leaves
There are currently two types of trees in TDM: model trees which use a model for the leaves, and model trees that use particles (like sprites) as the leaves.
Main differences between them:
- Model trees which use a model for the leaves: This is the standard way of making trees in games and is what everyone is probably used to. The problems are obvious, in that they tend to not look "bushy" and of course looking at the tree from different angles can look pretty bad, mainly due to each leaf face being lit differently.
- Model trees which use particles for the leaves: This method gives the tree a more "bushy" look because the particles are oriented to the player's view. This means that from whichever angle you look the leaves always look good. Of course, there is a problem with the particles being oriented to the player's view, and that is that they rotate to math the angles of the player's view, resulting in a "kaleidoscope" effect when viewed from the bottom or top and rotating the view.
This article covers how to use the TDM trees with the particle leaves and how to make custom leaves. Since this involves editing them through the particle editor, this doubles up as a tutorial on using the particle editor, but only covers the parts of it that are relevant to editing the leaves.
Adding a tree with particle leaves to your map
For this we need 2 things - a tree "skeleton" model, and the particle leaves.
- For the tree "skeleton", make a func_static in the editor and select the model (choose a tree skeleton without leaves in it).
- That makes our base, now make a func_emitter and select the particle (for example tdm_leaves_01).
- Now select the particle emitter and set a key/val pair "shaderParm7" in the key and a value in the val. This controls how fast the movement of the texture is. When this is on 0 (which is default), there is no movement (which looks like there's no wind at all and the leaves stand still like in a screenshot). 1 would be some quite slow ambient movement while 2 would be a light breeze. 4 would be a windy place and about 8 would be a very windy place. Adjust the number to your liking. Note that this is only for the currently selected emitters, which means you can have no leaf movement for leaves in one part of the map, while in another part you may want them to be swaying like mad, for example.
To quote the material file:
//Note: parm7 controls how fast the leaves sway and by default it is 0, so for each leaf emitter, a key/val pair must be set. // Example: for ambient movement put key: shaderParm7 Val: 1 but for windy weather put the val to about 8 or so.
Now align the particle emitter to the middle of the branches, as the particles form a rough sphere around the emitter. Done.
Note: The particles do not cast shadows (and cannot, even if you remove the noshadows line in the material file) but accept shadows being cast on them (even if you remove the noselfshadow line in the material file), which means that branches from the tree do cast shadows onto the leaves, which is nice, but means that the leaves do not cast a shadow onto the floor beneath them.
Making custom particle leaves
Making a custom leaf material:
To simplify the process, open tdm_leaves_materials.mtr and look at one of the leaf types. For this tutorial we will look at textures/particles/tdm_leaves_01.
textures/particles/tdm_leaves_01 { qer_editorimage models/darkmod/nature/leaves_d noshadows nonsolid { blend diffusemap map models/darkmod/nature/leaves_d rgb 0.5 alphatest 0.5 scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] } { blend specularmap map models/darkmod/nature/leaves_s scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] } { blend bumpmap map models/darkmod/nature/leaves_l scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] } { blend add rgb 0.075 map models/darkmod/nature/leaves_d scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] } }
Now let's go through what each part of that material does.
qer_editorimage models/darkmod/nature/leaves_d noshadows nonsolid
The first line is the image that is displayed in the editor, the other 3 lines disable shadow-casting for the material and collision with the material. Note that these are actually not needed as you cannot collide with particles anyway, and particles cannot cast shadows either. The lines are there mainly for if the texture is used on a brush, patch or model.
{ blend diffusemap map models/darkmod/nature/leaves_d rgb 0.5 alphatest 0.5 scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] }
This is the diffusemap, basically the actual texture that gets shown in the game.
The first line defines that this is a diffusemap.
The second line is the path to the texture itself (note that it does not use an extension, such as JPG or TGA. This is so it can use DDS versions of the textures also).
The third line is how much it should be affected by lighting (rgb stands for Red Green Blue, and 0.5 is normal diffusion of light. rgb 1 would be overbright). Note that rgb affects all 3 colour channels, but you can specifically change each channel (by using "red <value>" [without quotes] in one line and then green in the next etc), for example making it more red or more blue etc. This can be useful if you have a leaf texture and want to make 2 materials, one with the leaf green and another with the leaf yellow, without making a new texture.
The fourth line is the amount by which to make the alpha channel within the image file transparent by (0.5 is a good value). Alpha channel settings for the image itself will be covered further down.
The fifth line scales the image by 2 in both the x and y directions. this means that each particle-face will have 2 by 2 of this image (so 4 in all) and is mainly so that less particles are needed to achieve the same effect. In other words, normally to achieve the same amount of bushiness you'd need 4 times the amount of particles (which are also half the size), which is visibly better, but more taxing on the renderer, thus lowering performance.
The sixth line is the movement of the material, or in other words, the "windiness". Basically it is a sinusoidal movement which is scaled by parm7, which is shaderParm7 in the editor (which, as I mentioned earlier, changes how much the leaves move by).
The specularmap and bumpmap are the same thing except that the paths define a specularmap texture and a bumpmap texture respectively. Also, in the above example they don't have rgb set, but this can be used to do a material-level change on their colour/brightness).
Also note that specular and bump maps cannot use alpha channels as they have a neutral colour in their texture for "no specular" (black in the specular map) and "flat" (for the bumpmap).
{ blend add rgb 0.075 map models/darkmod/nature/leaves_d scale 2,2 translate 0.022 * sintable [ time * (0.06 * parm7)], 0.022 * sintable [ time * (0.03 * parm7)] }
This adds an ambient brightness to the leaves, which means that in a pitch-black map these will be slightly glowing, but in a map with a mild ambient light this will make it slightly brighter in shadows or when facing away from the light. Adjust this to your liking, 0.075 is generally good for TDM maps.
So, to make a custom leaf material, copy the material shown further above and modify the relevant parts of it (such as name, paths to the texture etc).
Editing the particles themselves (size etc):
So, firstly make a tree as above and use one of the default leaf particles (this is the simplest way). Now open your test map in Doom3Ed and press F2 (this brings up the game in windowed) and in the console type EditParticles. This will bring up the particle editor in Doom3Ed and allows you to make changes, as well as see the result of them in the renderview.