Wind sway for foliage and flags
A gentle sway for trees, grass, flags, hair and banners. The top moves most and the base stays planted. It animates on its own, no script needed.
Settings:
- strength (0-0.15), speed.
Tip: give each copy a slightly different speed (each with its own material) so a row of trees does not move in sync.
Works with the Compatibility renderer and respects the node modulate.
This shader is part of the free 2D FX Essentials pack (9 sprite shaders with a demo scene): https://dimensionalmios.itch.io/almios-2d-fx-essentials
Shader code
shader_type canvas_item;
// Wind sway for foliage, flags, hair and banners. The top of the sprite sways
// most; the bottom row stays anchored.
uniform float strength : hint_range(0.0, 0.15) = 0.04;
uniform float speed : hint_range(0.0, 6.0) = 2.0;
varying vec4 vertex_tint; // modulate and self_modulate, applied at the end
void vertex() {
vertex_tint = COLOR;
}
void fragment() {
vec2 uv = UV;
float sway = sin(TIME * speed + uv.y * 3.0) * strength * (1.0 - uv.y);
uv.x += sway;
COLOR = texture(TEXTURE, uv);
COLOR *= vertex_tint;
}


