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;
}
Live Preview
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

Related shaders

Comments 7

  1. Lucas Thomaz

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

    uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
    
    7
    1. Hi and sorry for a super delay, I don't get any notifications from this website :(

       

      Thank you for your contribution! The shader was upgraded to Godot 4, so now it includes that line of code :)

      0
  2. 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;
    }
    
    1
    1. 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);

      1