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

More from mreliptik

2D simple animated flag shader

Loading effect (color over grayscale)

Related shaders

2D simple animated flag shader

Perspective grid animated

Animated sketchy line

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.
guest
0 Comments
Inline Feedbacks
View all comments