Frosted glass

A shader that creates an effect of a frosted glass surface. By default it works with a noise texture, but if a normalmap texture is used instead, it can create any glass surface type (e.g. lens).

Shader code
shader_type spatial;

uniform float distortion_size = 0.4;
uniform sampler2D glass;

void fragment() {
	vec2 d = texture(glass, UV).xy - vec2(0.5);
	ALBEDO = texture(SCREEN_TEXTURE, SCREEN_UV + d * distortion_size).rgb;
}
Tags
glass, noise, normalmap, screen 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

Hexagon pattern

UV light (2D and 3D)

Aurora Borealis

Related shaders

Improved frosted glass

Frosted Glass

Glass shader

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lucas Thomaz
1 year ago

Nice! to make it work in godot 4 add the following line:

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
Palooka
2 months ago

This is great! I tweaked it a little so you can change its color and opacity.

shader_type spatial;

uniform float distortion_size = 0.4;
uniform sampler2D glass : source_color;
uniform vec4 color: source_color = vec4(1.0, 1.0, 1.0, 1.0);

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;

void fragment() {
    vec2 d = texture(glass, UV).xy - vec2(0.5);
    ALBEDO.rgb = texture(SCREEN_TEXTURE, SCREEN_UV + d * distortion_size).rgb * color.rgb;
    ALPHA = color.a;
}
Palooka
2 months ago
Reply to  Palooka

You may also find you get better results by changing this line:
vec2 d = texture(glass, UV).xy – vec2(0.5);
To this:
vec2 d = texture(glass, UV).xy – vec2(0.25);

Last edited 2 months ago by Palooka
sfammonius
2 months ago

The distortion gets more intense as you travel further. I made a slight modification to the shader to fix that here: https://godotshaders.com/shader/improved-frosted-glass/