Skip to content

Foliage tools ​

The Foliage group of the strip on the left of the 3D viewport paints more or less of an entry of the foliage library: grass, weeds, pebbles, bushes, trees. The terrain draws it in the editor and in the game.

Where it comes from ​

There are two sources of what grows on the ground, and they add up:

  1. The textures. A terrain texture lists the entries that grow on it, with a weight each. Paint grass and the tufts appear; paint a path over it and they go. Nothing to place by hand.
  2. Your brush. On top of the textures, the foliage tools paint more of an entry (even where no texture grows it, a lone tree on bare rock) or less (a clearing in the grass).

Every cell of 2 m remembers one number for each entry you painted on it: as the textures give (the start), more, or less down to none. The scatter reads it, so the same ground always gives the same plants. Nothing is stored for each plant.

The tools ​

Turn the terrain mode on, choose a foliage tool and pick the entry in the foliage bar that shows above the tool's settings. The bar has the ground scatter and the foliage with their pictures, a filter and a menu for the kind.

ToolWhat it does
Add foliagePaints more of the chosen entry where you go. Ctrl at the start of the stroke takes it away
Remove selected foliageTakes the chosen entry away where you paint (also what a texture grows). Ctrl at the start adds it
Remove all foliageTakes every kind of foliage away where you paint, what the textures grow and what you painted by hand, with no entry chosen (the foliage bar is not shown). It works on all the entries that are drawn there at once, and one Ctrl+Z gives them all back. Ctrl at the start gives the foliage back: every entry goes to what the textures give
Remove ground clutterTakes away only what the textures grow (the entries in the ground clutter list of the texture painted there: grass, weeds, pebbles) and leaves the trees and bushes you placed by hand. No entry needs to be chosen. Ctrl at the start restores it
Restore ground clutterGives back what the textures grow where you took it away (those entries go back to what the textures give). Ctrl at the start removes it
Reset foliagePuts the chosen entry back to what the textures give: what you painted by hand is forgotten

The paint tools have a box in their bar, Clear hand-placed foliage (on at first): where you paint a texture, the foliage you painted by hand goes back to what the textures give, so the clutter of the new texture grows there. Turn it off to keep a tree you placed when you repaint the ground round it. The paint and the clearing are one undo action.

The tools work on one entry at a time, the one you chose (Remove all works on every entry). Radius, strength and hardness are the ones of the bar at the bottom, and the shape of the Cursor bar works here too (a square brush, a ring, a spray of spots). Strength is how fast it grows or goes away; hardness is how much of the brush works fully. A stroke is one undo action.

The amounts are saved in the tiles, with the rest of the painting, when you save the scene.

How much grows, and where ​

Many numbers meet in the foliage, so here they are in the order they are used. Each answers one question, and each lives in one place.

QuestionThe numberWhere it is
How thick can it be at most?Density: the most plants in a square metre (short grass 55, long grass 12, a tree 0.02)the foliage entry (a group has one for all its scenes)
Where do the textures grow it, and how much of the density?Weight of the entry in the Ground clutter list of a texture: 1 = the full density, 0.2 = a fifththe terrain texture
Where do you add it by hand?The foliage brush: painting up to the full density, never morethe brush
Which scene of a group is placed, how often?Weight of each scene in the group (2 = twice as often as 1, 0 = never)the group
How much of the ground is left bare?Patchiness: 0 none, 0.5 half, 1 allthe foliage entry
How big are the patches and the gaps?Patch size in metresthe foliage entry
How close can two stand?Spacing in metresthe foliage entry
What can the player turn down?The clutter setting of the game's settings: it only takes some away, nothing movesthe player

In words, for one square metre of ground: the density is the most there can be; the texture weight or the brush decides how much of that there is; patchiness and patch size cut patches out of it; spacing keeps neighbours apart; the player's setting can thin it out further.

A worked example. Short grass with density 55, on a texture with the weight 0.5, patchiness 0.3 and patch size 10 m: about 27 blades a square metre where it grows, in patches of about 10 m, with about 30% of the ground bare between them. Paint the same grass by hand with the brush at full and the bare parts stay bare (patchiness applies to the brush too), but where it grows it is the full 55, not more. A tree with density 0.02 and spacing 4 m: one tree in 50 square metres at most, and none closer than 4 m to another.

Things that are easy to mix up

  • Density is how thick, weight is how much of that grows here. A weight never makes it thicker than the density.
  • Patchiness is how much is bare, patch size is how big the patches are. They work together: patchiness 0.4 and patch size 20 m is groves of about 20 m with clearings between them.
  • Spacing only keeps plants apart, it does not make a forest thinner by itself. If it takes too many away, raise the density.
  • A group has the density, spacing, patchiness and patch size; its scenes only have how they look, and their weights in the group say how often each is placed. A tree in a group never has a density of its own.

The brush numbers do not say how much grows, only what one stroke does:

  • Radius: the size of the brush on the ground, in metres.
  • Strength: how much one stroke does, as a share of the way to full. At 1 a stroke puts down (or takes away) everything under the core of the brush at once; at 0.3 it goes 30% of the way, and you paint again to add more. Holding the mouse still adds nothing more.
  • Hardness: how big the full-strength core is, as a share of the radius. At 1 the brush is at full strength right to its edge; at 0.5 it is full in the inner half and fades to nothing at the edge; at 0 only the centre is full. A soft edge makes your strokes thin out into what is round them.

What you see ​

While you paint, the cells of 32 m near the camera are made again behind the scenes and swapped in when they are ready, so the picture does not flicker. Entries are drawn up to their view distance (40 m for ground scatter, 250 m for foliage by default: both are set in Terrain Settings; the player's Foliage distance and View distance settings scale them). A cell is made in a worker thread, so a big brush costs frames, not seconds.

The edge fades. The last quarter of the view distance of an entry fades out in a circle round the camera, and what comes into range fades in: the foliage thins out and is gone, it does not switch off a square cell at a time. The Foliage fade property of the Terrain node (Drawing, default 0.25) is the share of the view distance the fade takes; 0 turns it off. It is done by the material: the materials of the entries are copied with the Distance Fade of a StandardMaterial3D set to Pixel Dither (cheap, and nothing has to be sorted). A material that already has a distance fade of its own is left as it is, the foliage shaders (the ones the trees, bushes and plants of the toolkit use) fade by themselves: the copy of their material gets two numbers, fade_start and fade_end (metres from the camera), and the shader dithers the pixels away between them. A material with another shader of your own does not fade unless it has the two uniforms fade_start and fade_end (copy the few lines of foliage_tree_core.gdshaderinc), or it is cut off at the view distance.

How far foliage is drawn is set in three places: the defaults of Terrain Settings (40 m for ground scatter, 250 m for foliage), the View distance of each entry (Assets > Foliage; 0 = the default of its kind, any other number overrides it) and, for the player, the Foliage distance option (a share the game sets) and the View distance option of the video settings, which scale it (Ground clutter sets how much grass and pebbles there are, not how far).

Trees are solid, and the navigation goes round them ​

  • Collision. The shapes of the StaticBody3D nodes of a foliage scene are made real near the player and the party members (about the same distance as the ground's collision) and taken away when they leave. A tree you paint is solid in the game; in the editor nothing collides.
  • Navigation. When you bake the navigation, every tree takes its footprint out of it, so NPCs walk round trunks. Painting trees makes the tiles out of date.

The Inspect tool and the foliage ​

The Inspect tool's box in the corner of the viewport has a line Foliage: how many instances are drawn in the tile under the mouse and the biggest entries (1205 drawn in this tile: Grass tuft 900, Weed 300, Oak 3, ...). Only what is near the camera is drawn, so it counts the cells that are there now.

The player's setting and the project's switch ​

  • Ground clutter is a video setting of the player: Off, Low, Medium, High. Off draws no grass, weeds or pebbles; the other three are percentages you set in Terrain Settings (35, 65 and 100 at first). The scatter keeps that share of every entry, so nothing moves when the player changes it. Trees and bushes are level design: the setting does not touch them.
  • Clutter grows on textures (Terrain Settings) turns the texture lists off for the whole project: only what you painted by hand is drawn.

Foliage shaders: wind, walking through, and light ​

Plants sway in the wind of the world and bend away from whoever walks through them, and a plant made of flat cards can be lit well. This is done by the shader of the material, not by settings on the entry. The shaders are in the folder assets/shaders of the plugin: one for small plants and one for trees and bushes, each in three ways of lighting.

ForLit per pixel (the usual)Lit per vertexUnshaded
Grass, flowers, weeds, small plantsfoliage_plant.gdshaderfoliage_plant_vertex_lit.gdshaderfoliage_plant_unshaded.gdshader
The leaves, needles, branches and trunks of trees and bushesfoliage_tree.gdshaderfoliage_tree_vertex_lit.gdshaderfoliage_tree_unshaded.gdshader

To use one, give the entry's mesh a ShaderMaterial with the shader. Plant height (or Tree height) is how tall the plant stands in the world, in metres: the root stays put and the tip moves most. Heights are measured in the world from the foot, so it does not matter whether the model was made Y-up or Z-up, in metres or centimetres, or scaled in its scene; if the origin of the model is not at the foot (it is in the middle of the tree, say) set Origin above foot to how many metres above the foot it is. A material is made for one height, so a mesh of another height needs a material of its own.

Why plants light badly, and the fix ​

A plant made of flat cards is lit by the way each card happens to face the sun: one blade bright, the next one black, and a field looks patchy. A crown of leaf cards looks like a heap of shards. The shaders fix it in two ways:

  • The normals are not the ones of the mesh. For a plant they are turned up to the sky (like the ground it grows on); for a crown they point away from the middle of the crown, as on a ball, so the whole crown is lit like one soft shape. This is the Normal mode and Normal soften.
  • The light wraps round the card (Light wrap), light shines through a thin leaf seen against the sun (Translucency), and there is no shiny highlight.

The three lightings:

  • Lit per pixel: the soft light described above, with shadows. Use this one unless you have a reason.
  • Lit per vertex: the light is worked out at the corners of the triangles, which is cheaper and softer still. There is no wrap of the light (turn the normal mode towards the sky or the crown to soften it).
  • Unshaded: no light at all: the colours as they are, a flat painted look, the cheapest. It gets no sunlight and no shadows, so night is as bright as day: Flat brightness sets how bright it is.

The settings ​

Both shaders (and all three lightings) have the same settings, in groups in the material:

GroupSettingWhat it does
LookAlbedo textureThe picture (alpha cuts out the shape). Empty = plain colour: grass blades
Root color, Tip color (plants) / Tint (trees)The colour at the root and at the tip; the tint of a tree. The vertex colours of the mesh and the tint variation of the scatter are used too
Alpha cutoffPixels with less alpha than this are not drawn
UV scale (trees)How often the picture repeats (a trunk: 1 by 2)
Use normal map, Normal texture, Normal strength (trees)The bumps of the bark. The mesh needs tangents, as an imported model with a normal map has
Roughness (trees)How rough the surface is
MovementPlant height / Tree heightHow tall it stands in the world, in metres
Origin above root / Origin above footHow far above its foot the origin of the model is, in metres (0 = at the foot)
Wind amount / Sway amount0 = still, 1 = as the wind says, 2 = twice as much
Stiffness0 = bends from the ground up, 1 = only the top bends (a thick trunk)
Flutter amount (trees)How much the leaves flutter by themselves (0 for a trunk)
Brush amountHow much a body that walks through bends it: 0 = not at all (a tree), 1 = as much as it can (a low bush)
LightingNormal modePlants: Mesh normals, Up, or a Mix of mesh and up. Trees: Mesh normals (a trunk), Canopy (a ball: leaves made of cards), or Up
Normal softenHow far the normals go towards the sky or the ball (0 = the mesh, 1 = all the way)
Canopy center, Canopy radius (trees)Where the middle of the crown is (a move in metres from 65 percent of the tree's height) and how big it is in metres (0 = 40 percent of the height)
Inner tint, Outer tint (trees)Leaves deep in the crown are darker: the colour is mixed from one to the other by how deep the leaf is
Light wrapHow far the light wraps round a card (lit per pixel only)
TranslucencyHow much light shows through a thin leaf
Flat brightnessHow bright the plant is without light (unshaded only)

For a trunk use the tree shader with Normal mode = Mesh normals, Flutter amount = 0 and a high Stiffness, so the trunk sways with the crown (the whole tree follows one bend that grows with the height; the trunk and the leaves move together).

Wind in a shader or in an animation? The shader. Ambient sway of trees that are drawn thousands at a time as instances cannot have an animation player each, and a bend that grows with the height is exactly what a vertex shader does for free. Use an animation for what happens once or to one tree: a tree that falls, is cut down, or is hit.

The trees and bushes of the demo ​

The tree and bush scenes of the asset pack (birch, common, maple, palm, pine, twisted, dead and burnt trees, the common bushes) already use the tree shader: each scene has its materials in assets/foliage/pack_materials/<folder>/ (a bark and a leaves material, and a flowers one for the bushes with flowers), set as the material overrides of the scene's mesh nodes. Each material has the height, the origin and the crown of its own scene (measured, not typed), the picture and the colour of the pack material it replaces, the bark's normal map where the pack had one, a stiff trunk with no flutter, and leaves that are lit as a ball and flutter. The look of a kind of tree (how much it sways, how much its leaves flutter) is in the table LOOKS of tests/tools/make_pack_materials.gd: change it and run the tool again to make every material of that kind again:

bash
Godot --headless --script res://tests/tools/make_pack_materials.gd

It works on a pack of your own too (give it the folder of the scenes after --): it measures each scene, makes the materials and writes them into the scene text, and a second run replaces what the first wrote. Leaves with soft edges in the original (alpha blend) are cut out by the shader, so a crown looks denser and a little more solid than before: raise Alpha cutoff of a leaves material to thin it.

The wind and the push ​

  • Wind. The gusts travel over the ground, so a field moves together. The wind is the Wind of the Environment config of the world (a breeze at first); a weather with its own wind takes its place while it lasts. A script can set it with FoliageWind.set_wind. More in Shader globals.
  • Walking through. The players and the entities near the camera (at most 8 at once, within 40 m) press the plants near them down and aside. A mounted or flying entity is above the plants and pushes nothing. The plants spring back when the body has gone.
  • A shader of your own can read the same global parameters, world_wind and foliage_pushers, with foliage_wind.gdshaderinc (the list of shader globals the plugin adds to your project).

Not here

Wind and walking through need the shaders above: a plant with an ordinary material stands still. A scatter-by-rules brush (fill a tile by its rules) may come later.

See also ​