Raindrops glass

This shader uses a normalmap texture to distort the view and create a raindrops effect. This repo provides 2 ways of generating such a texture.

The first mesh uses an animation created in Blender. The raindrops are represented by Metaball objects, so they merge with each other if they are close enough. The animation was exported as an .ogv file and used as a video texture in Godot.

The second version uses a particle system (with trails enabled) made entirely in Godot. It is rendered in real time in a viewport and used as a viewport texture.

The night environment HDRI is in public domain and can be downloaded from ambientCG.

 

Shader code
// ========== NORMAL SHADER ==========

// This shader generates a normal map output based on geometry
shader_type spatial;
render_mode unshaded, particle_trails;


void fragment() {
	vec3 normal = NORMAL * 0.5 + vec3(0.5, 0.5, 0.5);
	// convert linear to sRGB
	ALBEDO = pow((normal + vec3(0.055)) / vec3(1.055), vec3(2.4));
}

// ========== GLASS SHADER ==========

shader_type spatial;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform sampler2D raindrops_normal : hint_normal;
uniform float distortion_size = 0.2;


void fragment() {
	vec2 d = texture(raindrops_normal, UV).rg * 2.0 - vec2(1.0);
	ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV + d * distortion_size).rgb;
}
Tags
blender, glass, normalmap, particle trail, rain, raindrops, screen, screen texture, video texture
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 miskatonicstudio

Pride

Engine flame

UV light (2D and 3D)

Related shaders

Raindrops

Cracked Glass

Frosted Glass

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ColorauGuiyino
8 days ago

so simple, so elegant.