2D Wind Sway for Grass & Foliage
A drop-in canvas_item shader that makes grass tufts, bushes, flowers and tree tops sway in the wind. The base of the sprite stays anchored while the top bends, neighbouring sprites move out of sync automatically (the phase comes from their world position), and slow gusts roll across the whole scene. No extra textures or scripts are needed.
USAGE:
Put the shader in a ShaderMaterial on a Sprite2D, TextureRect or AnimatedSprite2D whose texture has the plant standing on the bottom edge. Share one material across all your grass sprites; each one still sways differently because the phase is based on world X. For the curved bend (curve_amount > 0), leave a few transparent pixels on the left and right of the sprite so the tip has room to move.
Uniforms:
sway_strength — how many pixels the top of the sprite moves
sway_speed — speed of the back-and-forth motion
phase_scale — how much the timing changes per world pixel (0 = everything sways in sync)
wind_bias — constant lean in the wind direction (negative = wind blowing left)
stiffness — how the bend is spread over the height. Above 1 = stiff base and bendy tip, 1 = straight skew
pivot_y — the UV.y that stays anchored (1 = bottom edge, 0.5 = middle)
gust_strength — extra push from gusts
gust_speed — how fast gusts travel across the scene
gust_scale — how wide a gust is in world space (smaller = wider gusts)
curve_amount — bends the image inside the sprite instead of only skewing the quad (0 = off, needs side padding)
time_offset — shifts the animation in seconds (handy for a still preview or desyncing groups)
Note: the skew works on single sprites. For TileMap tiles, use curve_amount with sway_strength = 0, since tiles share one atlas texture.
Works in Godot 4.3+ (Compatibility, Forward+, Mobile).
AI-assisted (code + text)
Need sword swings and hit sounds for the game around that meadow? Free Combat SFX sampler: https://crtforge.pages.dev/combat-sfx-sampler/ and the full Fantasy RPG Combat SFX pack: https://assetsmithpixels.itch.io/fantasy-rpg-combat-sfx
Shader code
// 2D Wind Sway for Grass & Foliage (Godot 4.3+, canvas_item) - MIT License
// Copyright (c) 2026 assetsmith
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files, to deal in the Software without restriction, including
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
shader_type canvas_item;
// --- base sway ---
uniform float sway_strength : hint_range(0.0, 64.0) = 8.0; // pixels the top moves
uniform float sway_speed : hint_range(0.0, 10.0) = 1.6;
uniform float phase_scale : hint_range(0.0, 0.2) = 0.015; // phase change per world pixel (desyncs neighbours)
uniform float wind_bias : hint_range(-1.0, 1.0) = 0.25; // constant lean in the wind direction
uniform float stiffness : hint_range(0.5, 4.0) = 1.6; // >1 = stiff base, bendy tip
uniform float pivot_y : hint_range(0.0, 1.0) = 1.0; // UV.y that stays anchored (1 = bottom edge)
// --- gusts ---
uniform float gust_strength : hint_range(0.0, 3.0) = 0.8;
uniform float gust_speed : hint_range(0.0, 5.0) = 0.6;
uniform float gust_scale : hint_range(0.0, 0.05) = 0.004; // width of a gust wave in world space
// --- curve (bend inside the sprite instead of a straight skew) ---
uniform float curve_amount : hint_range(0.0, 0.3) = 0.0; // needs transparent padding on the sides
uniform float time_offset = 0.0;
varying float v_sway;
float anchor_weight(float uv_y) {
return pow(clamp((pivot_y - uv_y) / max(pivot_y, 0.001), 0.0, 1.0), stiffness);
}
void vertex() {
vec2 world = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
float t = (TIME + time_offset) * sway_speed + world.x * phase_scale;
float s = sin(t) * 0.7 + sin(t * 2.31 + 1.7) * 0.3;
float g = sin((TIME + time_offset) * gust_speed - world.x * gust_scale) * 0.5 + 0.5;
s += wind_bias + g * g * gust_strength;
v_sway = s;
VERTEX.x += s * sway_strength * anchor_weight(UV.y);
}
void fragment() {
vec2 uv = UV;
if (curve_amount > 0.0) {
uv.x -= v_sway * curve_amount * anchor_weight(UV.y);
}
vec4 c = texture(TEXTURE, uv);
if (uv.x < 0.0 || uv.x > 1.0) { c.a = 0.0; }
COLOR = c * COLOR;
}

Comments 0
No comments yet.