DIstortion behaves weird when camera moves
Shader code:
shader_type spatial;
render_mode unshaded;
uniform sampler2D shape_texture;
uniform float distortionView : hint_range(0.0, 0.3, 0.005) = 0.03;
uniform float speedView : hint_range(0.0, 1.0, 0.005) = 0.5;
uniform sampler2D noiseViewX;
uniform sampler2D noiseViewY;
uniform sampler2D screenTexture : hint_screen_texture;
uniform vec3 tintColor : source_color;
uniform float fresnelAmount : hint_range(0.0, 5.0, 0.1);
float fresnel(float amount, vec3 normal, vec3 view) {
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0)), amount);
}
void fragment() {
vec4 shape = texture(shape_texture, UV);
if(shape.a < 0.5){
discard;
}
vec4 worldPos = MODEL_MATRIX * vec4(VERTEX, 1.0);
float noiseValueX = (texture(noiseViewX, worldPos.xy * 0.1 + (TIME * speedView)).r * 2.0) - 1.0; // Range: -1.0 to 1.0
float noiseValueY = (texture(noiseViewY, worldPos.xy * 0.1 + (TIME * speedView)).r * 2.0) - 1.0; // Range: -1.0 to 1.0
vec2 noiseDistort = vec2(noiseValueX, noiseValueY) * distortionView;
vec3 distortedScreenTexture = vec3(texture(screenTexture, SCREEN_UV + noiseDistort).rgb);
vec3 fresnelTint = (tintColor * fresnel(fresnelAmount, NORMAL, VIEW));
ALBEDO = distortedScreenTexture + fresnelTint;
}