Frosted glass

This shader uses a normalmap texture to distort the view and create a frosted glass effect. The repo provides 2 textures: a .png file (created using Blender) and an instance of NoiseTexture2D (built into Godot Engine).

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

Shader code
shader_type spatial;

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

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

Cyberpunk scanner

UV light (2D and 3D)

Engine flame

Related shaders

Improved frosted glass

Frosted Glass

Frosted Glass

Subscribe
Notify of
guest

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Lucas Thomaz
2 years ago

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

uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
Palooka
11 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
11 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 11 months ago by Palooka
sfammonius
11 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/