Improved frosted glass

Based on miskatonicstudio’s frosted glass shader (and updated for Godot 4). The difference is that this one makes use of the depth texture to prevent the distortion from increasing with distance. This can make the effect more believable, especially in cases where the distortion is subtle.

(this also has a mild performance impact)

Shader code
shader_type spatial;
render_mode shadows_disabled;


uniform float distortion_size = 0.4;
uniform sampler2D glass;

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform sampler2D depth_texture : source_color, hint_depth_texture;

void fragment() {
	vec2 d = texture(glass, UV).xy - vec2(0.5);
	ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV + d * sqrt(texture(depth_texture, UV).r) * distortion_size).rgb * 0.9 + vec3(0.1);
	ALPHA = 0.99;
}
Tags
frosted glass, glass, Ice
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.

Related shaders

Frosted Glass

Frosted glass

Toon glass

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments