Foliage Technology

From Mod Wiki

Wolfenstein Enemy Territory adds a new feature to the Quake 3 engine's shader repertoire, the ability to automatically place detail models directly onto map surfaces in an algorithmic fashion. They are designed primarily for foliage, hence the name, but can be used for adding pebbles or rocks scattered randomly around terrain. One key feature of foliage is that it will fade out over distance, but this can cause a problem looking at players at a distance. It is suggested that additional trees and tall bushes are added to the landscape to offer other forms of permanent cover.

When creating foliage, there are 3 things to set up: the foliage model, the foliage model's shader(s), and changes to any existing shader where foliage is desired on.

Foliage is compiled into the BSP hence it is static . If you need to change the foliage in your map, it must be recompiled. This is done for performance reasons -- when foliage is loaded by Enemy Territory it is compiled into a list for fast rendering.

To compile foliage into a map, SDMap2 (Q3Map2) 2.3.32 or higher is required.

Adding Foliage to Existing Shaders

There is a new shader directive 'q3map_foliage' that specifies how SDMap2 applies foliage to a surface. It takes this form:

q3map_foliage <model> <scale> <density> <odds> <use inverse alpha>

q3map_foliage models/foliage/grass_5.md3 1.0 16 0.025 0
model: models/foliage/grass_5.md3
scale: 1.0. This is normal size, 0.5 would be half size, 2.0 would be double
density: T16 units. This is the smallest chunk Q3Map will divide a surface up into before it tries to place a foliage instance.
odds: 0.025. This means that a random 2.5% of the potential spots for foliage will be placed. Typically you want to use small values for this; otherwise you will end up with ridiculously high polygon counts.
inverse alpha: 0. this means to use the straight vertex alpha as a scaling factor against the odds of appearing. This is so that terrain shaders with multiple blending layers can have different foliage on each style and have them fade/blend properly together.

If you have brush on terrain0 and grass on terrain1, then the blend shader would have two q3map_foliage directives like this:

q3map_foliage models/foliage/brush.md3 1.0 16 0.025 1
q3map_foliage models/foliage/grass_5.md3 1.0 16 0.025 0

Where the higher-numbered terrain layer/shader uses normal vertex alpha to modulate the odds-of-occurring and the lower-numbered layer uses inverse alpha.

Creating a Foliage Model

Foliage models should be kept simple and small. Since they're entirely decorative and non-solid, you should avoid making a foliage model that looks as if it could block the player.

For best results, make your models in Max or Maya as a single object (multiple objects will slow down rendering) with a single texture/shader, and try to keep the polygon count as low as possible. Our initial test foliage models were only 6 triangles apiece. When there are a few thousand foliage instances on-screen, the small numbers can add up, so be thrifty.

Foliage Model Shaders

    surfaceparm trans
    surfaceparm pointlight

    cull disable

    // distanceCull <inner&rt; <outer&rt; <alpha threshold&rt;
    distanceCull 256 1024 0.4

        map models/foliage/grass_tan.tga
        alphaFunc GE128
        rgbGen exactVertex
        alphaGen vertex