Tutorial: Foliage
Foliage is usefull when you want a lot of bushes or grass into your map without to much cost of fps.
Before you add foliage to your map be aware the models are:
- non-solid.
- randomly placed on a face (triangle).
- invisible when there are far away from the player.
The foliage-system needs 3 parts:
- a model used as foliage (such as grass or a bush)
- a shader for the texture used in the model.
- a shader for the terrain the model is placed on.
We will create a foliage in 3 steps.
Step 1
- Chose a model (grass or bush) you want to use. (If it’s correct GtkRadiant installed a models folder into your etmain folder. Go to models/mapobjects/plants_sd/ to find a good foliage.)
[We use the model “models/mapobjects/plants_sd/grass_low.MD3”]
- Rightclick on the model and chose “open with > notepad”.
- Now press Shift+F and search for the word “models” or “textures”. Keep the path of the texture in mind or save/write it somewhere.
[For the grass_low model you need to search to the word “models” to find the texture. We found “models/mapobjects/plants_sd/grass_green1”]
Step 2
Now we’re going to create a shader for the texture we found in the model.
(If you have already a shaderfile for your map you can use that one in stead of creating a new one and skip the next line)
- Create a new text-file into the folder “scripts”. Rightclick > New > Textfile. And save it as xxx.shader (xxx is a random value you chose).
[We will create a “wk_foliage.shader” file]
- Now we are going to write a shader for the texture of the model. For foliagemodels we use this shader:
models/mapobjects/plants_sd/grass_green1 //name of the texture
{
surfaceparm trans //The texture will be transparant.
surfaceparm pointlight //This will cast shadows on your terrain.
cull disable //The texture will be visible from both front and backsides.
distanceCull 256 1536 0.5 //(256) Distance between the player and the model before scaling down, (1536) Distance to not be drawn anymore (scale = 0), (0,5) Fluency (0,5 = most fluency).
{
map models/mapobjects/plants_sd/grass_green1.tga //path to the texture
alphaFunc GE128 //Every pixel equal to and greater than 128 in the alpha-channel will be visible
rgbGen exactVertex
alphaGen vertex
}
}
You can copy this shader into your shaderfile and modifie the texturepaths and then save it.
- (If you had already a shaderfile you can skip this step.) Now we will let GtkRadiant read the file by opening the shaderlist.txt file into the “scripts” folder and typing the line “your-shader-file-name”
[For example we add the line “wk_foliage”]
Step 3
At last we will add the foliage to our terrain.
Open the shader of your terrain and just add the following line into the shader:
q3map_foliage models/mapobjects/plants_sd/grass_low.md3 .6 90 .2 2 //scale, distance between the models, percent filled (decrease for less foliage), 2(unknown variable, for now use 2)
[For example we use this shader:]
textures/folder/terrain
{
qer_editorimage textures/folder/terrain.tga
q3map_foliage models/mapobjects/plants_sd/grass_low.md3 .6 90 .2 2
surfaceparm landmine
surfaceparm gravelsteps
{
map textures/folder/terrain.tga
}
{
map $lightmap
blendFunc GL_DST_COLOR GL_ZERO
rgbGen identity
}
}
Compile your map
Now open gtkradiant and compile the map. If you get randomly triangles of non-foliaged and foliaged terrain you will need to increase the distance between the foliage.
I hope you understand it and I didn’t make any mistakes.