2D simple animated flag shader

This is a simple shader to animate a texture like a flag. You can use the various uniforms to control the look and feel of the flag.

  • speed: speed at which the TIME elapses. Basically the wind speed
  • frequency_x: frequency of the sine wave for the x axis
  • frequency_y: frequency of the sine wave for the y axis
  • amplitude_x: amplitude of the distortion for the x axis
  • amplitude_y: amplitude of the distortion for the y axis
  • inclination: inclination in the x axis, where the flag is attached (left)

I made a video showing you how I made it, check it out here: https://youtu.be/FIYrT8H9Qgg 

Feel free to use it however you like!

Shader code
shader_type canvas_item;

uniform float speed = 2.0;
uniform float frequency_y = 5.0;
uniform float frequency_x = 5.0;
uniform float amplitude_y = 50.0;
uniform float amplitude_x = 25.0;
uniform float inclination = 50.0;

void vertex() {
	VERTEX.y += sin((UV.x - TIME * speed) * frequency_y) * amplitude_y * UV.x;
	VERTEX.x += cos((UV.y - TIME * speed) * frequency_x) * amplitude_x * UV.x;
	VERTEX.x -= UV.y * inclination;
}
Tags
animated, deform, flag, shader, sine, vertex
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from mreliptik

2D dissolve with burn edge

Tiled texture inside of mask

2D Rotation deform

Related shaders

3D simple animated flag shader

2D Flag Shader

Waving flag

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
testdev
testdev
3 years ago

Awesome, thanks!

FritzMeinzer
FritzMeinzer
3 years ago

Cool