Image Warp Shader

It warpes the projected image using three noise textures.

Apply to a colorRect or MeshInstance2D. 

 

If you have any ideas on how to make the shader better, let me know.

Shader code
//shader is really unoptimised and not made by someone who knows much about shaders, 
//but someone who makes stuff that poorly work, if at all. 

shader_type canvas_item;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform sampler2D noise_1;
uniform sampler2D noise_2;
uniform sampler2D noise_3;
uniform float strenght = 0.85;
uniform float speed = 5.0;


void fragment() {
	
	
	float noiseValue = 0.0;
	
	float time = (TIME - floor(TIME)) * speed;
	time = time - float(int(time));
	
	if (time < 0.33){
	noiseValue = texture(noise_1, UV).r;
	}
	else if (time > 0.33 && time < 0.66){
	noiseValue = texture(noise_2, UV).r;
	}
	else{
	noiseValue = texture(noise_3, UV).r;
	}
	
	
	// glsl -> godot shader

	vec2 iResolution = 1.0 / SCREEN_PIXEL_SIZE;
	vec4 fragCoord = FRAGCOORD;
	vec2 p = fragCoord.xy / iResolution.x;
	float prop = iResolution.x / iResolution.y;
	vec2 m = vec2(0.5, 0.5 / prop);
	vec2 d = p - m;
	float r = sqrt(dot(d, d)); 
	
	
	
	vec2 uv;
	uv = p + noiseValue / (100.0 / strenght);
	uv.y *= prop;
	
	vec3 col = texture(SCREEN_TEXTURE, uv).rgb;
	
	COLOR = vec4(col, 1.0);
}
Tags
Warp Noise Canvas Item
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 Batboil

Cast Texture To Surface

Related shaders

Perspective Warp/Skew Shader

Visual Effects with an Image Mask

Palette Swap: Post-Process, Image-Parametrized

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ColorauGuiyino
8 months ago

I don’t really know what you mean with “make the shader better”, but…
at lines 18 and 19, can’t you simply use fract(TIME)?
and the next if-else statements… can’t you combine 2 mix with step?
like: mix1= mix(noise_1, noise_2, step(0.33, time))
and then mix(mix1, noise_3, step(0.66, time))
this is because the people always says that you must avoid “ifs” in shaders. I don’t really know if it’s better or not in terms of performance to be honest.

Jake
Jake
8 months ago

Error: Redefenition of ‘SCREEN_TEXTURE’