screen space refraction shader

code for my screen space refraction shader tutorial. i made it for ocean shader fragment part & later reflection & depth fade is planned too.

Shader code
shader_type spatial;

uniform samler2D normalmap;
uniform sampler2D screen_texture : hint_screen_texture;
uniform sampler2D albedo;
uniform float refraction_strength = 0.5;
uniform float alpha = 0.5;

vec2 refract_uv(vec2 uv, float strength, vec3 normal){
	uv += strength * (normal.x * normal.y * normal.z);
	return uv;

void fragment() {
	NORMAL_MAP = texture(normalmap, UV).rgb;
	ALBEDO = mix(albedo, texture(screen_texture, refract_uv(SCREEN_UV, refraction_strength, NORMAL_MAP)).rgb, 1.0 - alpha);
refraction, screen-space
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 mujtaba-io

sine wave camera view shader

Film Grain Shader

Gerstner Wave Ocean Shader

Related shaders

Pencil screen space shader

Screen-Space Edge Detection Outline Shader

Depth Modulated Pixel Outline in Screen Space

Notify of

Inline Feedbacks
View all comments