3D 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
  • frequency_z: frequency of the sine wave for the z axis
  • amplitude_x: amplitude of the distortion for the x axis
  • amplitude_y: amplitude of the distortion for the y axis
  • amplitude_z: amplitude of the distortion for the z 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 spatial;

uniform float speed = 2.0;
uniform float frequency_y = 5.0;
uniform float frequency_x = 2.5;
uniform float frequency_z = 2.5;
uniform float amplitude_y = 0.1;
uniform float amplitude_x = 0.05;
uniform float amplitude_z = 0.05;
uniform float inclination = -0.04;

uniform sampler2D tex: hint_albedo;

void fragment(){
	vec4 albedo_tex = texture(tex, UV);
	ALBEDO = vec3(1.0) * albedo_tex.rgb;
}

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 * 0.1 * UV.x;
	VERTEX.z += sin((UV.x - TIME * speed) * frequency_z) * amplitude_z * UV.x;
	VERTEX.x -= (1.0 - UV.y) * inclination;
}
Tags
3d, 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

Loading effect (color over grayscale)

2D Rotation deform

Tiled texture inside of mask

Related shaders

2D simple animated flag shader

2D Flag Shader

Wave FLag

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments