Skip to content

Shader globals ​

Godot has a place for numbers and pictures that every shader can read: Project Settings > Globals > Shader Globals. The toolkit uses it to give your own shaders the state of the world: how wet the ground is, which way the wind blows, where the water is. Write a shader that reads them and it follows the weather, the wind and the water by itself.

The plugin adds all of them to your project every time the editor starts (new ones that a newer version of the toolkit brings too), so a shader that uses one compiles at once, even in a scene with no terrain. A game made by hand without them adds the missing ones when it starts. You do not set them yourself: they are written while the game runs.

The list ​

GlobalTypeWhat it isWritten by
terrain_wetnessfloatHow wet the ground is: 0 dry, 1 soakedThe ground weather
terrain_snowfloatHow much cover (snow, sand, ash ...) lies on the ground: 0 none, 1 coveredThe ground weather
terrain_cover_colorvec4The cover of the ground: rgb = its colour, a = how rough it is (0 a mirror, 1 matte)The ground weather (the weather)
terrain_cover_stickfloatHow steep the ground can be for the cover to stick: 0 flat ground only (snow), 1 everywhereThe ground weather
terrain_wet_tintvec4rgb = the colour wet ground is multiplied with, a = how much of it shows on soaked groundThe ground weather
terrain_tintvec4rgb = the colour the ground is tinted with, a = how much of it showsThe ground weather (the tint of the world config)
world_windvec4x, y = the direction the wind blows towards on the ground (x, z) as a unit vector, z = how strong (0 still, 1 a breeze, 2 a storm), w = how fast the gusts goThe wind (below)
world_timefloatThe hour of the day, 0 to 24 (12 for a sun that stays where it is)The sky of the world (every game minute)
world_day_factorfloatHow much of the day it is: 0 at night, 1 in daylight, between at sunrise and sunset (the hours of the Sun config)The sky of the world
world_cloud_coverfloatHow cloudy the sky is: 0 clear, 1 overcast (the cloud density of the sky shown)The sky of the world
foliage_pusherssampler2D8 x 1 float texture: each texel (x, y, z, radius) of a body that pushes plants aside (radius 0 = nobody)The bodies near the camera
weather_groundsampler2DThe height of the terrain around the rain: one float for each cell (very low where there is no ground), so the particles of the weather land on a terrain whatever draws itWeather
weather_ground_rectvec4x, z = the corner of the ground picture in the world, z = its width in metres (0 = no terrain), w = how many cells a sideThe same
weather_skyvec4What the weather does to the sky, for a sky shader of your own: x = how much darker (0 to 1), y = how much of the tint (0 to 1), z = how many more clouds (0 to 1)Weather
weather_sky_tintvec4rgb = the colour the weather tints the sky with (shown by y of weather_sky)The same
water_mapsampler2DThe picture of the water for the wet shore and the caustics of the terrainMovement volumes with shore effects
water_map_rectvec4x, z = the corner of the water picture in the world, z = the size of a texel in metres, w = how far the shore reachesThe same

Using one ​

glsl
shader_type spatial;

global uniform float terrain_wetness;
global uniform vec4 world_wind;

void vertex() {
    // lean with the wind: world_wind.xy is the direction it blows towards, .z how strong it is
    VERTEX.xz += world_wind.xy * world_wind.z * 0.05 * VERTEX.y;
}

void fragment() {
    // wet things are darker and shinier
    ALBEDO = vec3(0.6) * (1.0 - 0.4 * terrain_wetness);
    ROUGHNESS = mix(0.9, 0.2, terrain_wetness);
}

A plant that sways with the wind of the world can use the ready-made shaders instead: see Foliage tools.

The wind ​

There is one wind. The Wind group of the Environment config is the wind of the world: a direction on the ground and how strong it is (0 still, 1 a breeze, 2 a storm; a new config blows a breeze of 0.35). A weather that has its own wind (a storm) takes its place while the weather lasts, and the wind of the world comes back when the weather has gone. All of it ends up in the one global world_wind. From a script: FoliageWind.set_wind(direction_degrees, strength), FoliageWind.set_base_wind(direction, strength) and FoliageWind.set_weather_wind(direction, intensity).

Your own globals ​

Add them in Project Settings as usual. The toolkit never removes a global it does not know.

Good to know ​

  • Names. Every global is lower case words joined by underscores, the thing first: terrain_wetness, world_wind, water_map, water_map_rect.
  • Older projects. Earlier versions of the toolkit added WindDirection, WindIntensity and GaleStrength, and the wind picture was called foliage_wind and the water picture water_height_map. The wind is one vector now (world_wind, the direction is its x and y, the strength its z). The plugin takes the three old numbers out of your project when the editor starts; if a shader of yours read them, read world_wind instead. foliage_wind and water_height_map are called world_wind and water_map now: change the name in a shader of yours that used them.
  • If you delete one of the toolkit's globals in Project Settings, the plugin puts it back the next time the editor starts.
  • A picture global (foliage_pushers, water_map, weather_ground) is only an empty picture in the project; the game fills it in when the terrain or the weather starts. In the editor the plugin fills them in when it starts.