Waving flag

Make a Plane mesh wave like a flag. Add a SimplexNoise or any texture to UV Offset Texture to make the flag behave differently.

This shader comes from GD Quest’s library of free shaders.

Shader code
shader_type spatial;

uniform float wave_size = 1.0;
uniform float face_distortion = 0.5;
uniform vec2 time_scale = vec2(0.3, 0.0);
uniform vec2 uv_offset_scale = vec2(-0.2, -0.1);

uniform sampler2D uv_offset_texture : hint_black; 


void vertex(){
	// Sample Noise
	vec2 base_uv_offset = UV * uv_offset_scale;
	base_uv_offset += TIME * time_scale;
	float noise = texture(uv_offset_texture, base_uv_offset).r;
	
	// Calculate offset
	float texture_based_offset = noise * 2.0 - 1.0; // Convert from 0.0  1.0 to -1.0  1.0
	texture_based_offset *= wave_size; // Apply amplitude
	
	texture_based_offset *= UV.x; // Apply dampening
	
	VERTEX.y += texture_based_offset;
	
	VERTEX.z += texture_based_offset * face_distortion; // Distort the face to give impression of conserving shape
	VERTEX.x += texture_based_offset * -face_distortion;
}


void fragment(){
	// Sample noise
	vec2 base_uv_offset = UV * uv_offset_scale;
	base_uv_offset += TIME * time_scale;
	float noise = texture(uv_offset_texture, base_uv_offset).r;
	
	ALBEDO = vec3(0.0, noise, 1.0 - noise); //Display noise. Blue for valleys, green for peaks
	//ALBEDO = vec3(1.0 - UV.x, 0.0, UV.x); //Display dampening. Red is full dampening, blue is none
}
Tags
displacement, vertex
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from hancan

3D burn dissolve

2D outline stroke

Related shaders

2D simple animated flag shader

3D simple animated flag shader

Progress Pride Flag

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments