Vertical Drops

Another 2D rain shader with many parameters to modify.

Please find the full tutorial on YouTube: https://www.youtube.com/watch?v=GMSKFZ-T6iU

Shader code
shader_type canvas_item;

uniform vec3 color: source_color = vec3(0.5);
uniform float speed: hint_range(0.01, 10.0, 0.01) = 0.1;
uniform float density: hint_range(1.0, 500.0, 1.0) = 100.0;
uniform float compression: hint_range(0.1, 1.0, 0.01) = 0.2;
uniform float trail_size: hint_range(5.0, 100.0, 0.1) = 50.0;
uniform float brightness: hint_range(0.1, 10.0, 0.1) = 5.0;

void fragment() {
	vec2 uv = -UV;
	float time = TIME * speed;
	uv.x *= density;
	vec2 duv = vec2(floor(uv.x), uv.y) * compression;
	float offset = sin(duv.x);
	float fall = cos(duv.x * 30.0);
	float trail = mix(100.0, trail_size, fall);
	float drop = fract(duv.y + time * fall + offset) * trail;
	drop = 1.0 / drop;
	drop = smoothstep(0.0, 1.0, drop * drop);
	drop = sin(drop * PI) * fall * brightness;
	float shape = sin(fract(uv.x) * PI);
	drop *= shape * shape;
	COLOR = vec4(color * drop, 1.0);
}
Tags
2d, drops, rain, Starfield
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 FencerDevLog

Lightning

Grid shader tutorial

2D Fireworks

Related shaders

How To Get Vertical Camera FOV

Rain drops on screen – notexture

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jorbyte
14 days ago

I love your youtube tutorials! Thanks for sharing