I'm really stuck and have no idea how to fix this, I would put it under the rug if I could but it's really noticeable no matter what I do. I'm using Godot 4.0.3
I want to use this shader code I took from the proximity fade node in the visual shader:
uniform sampler2D DEPTH_TEXTURE: hint_depth_texture;
uniform vec3 water: source_color;
uniform vec3 edge_color: source_color = vec3(1.0);
uniform float edge_dis = 1.0;
void fragment() {
float depth_tex = textureLod(DEPTH_TEXTURE, SCREEN_UV, 0.0).r;
vec4 view = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, depth_tex, 1.0);
view.xyz /= view.w;
float prox = clamp(1.0 - smoothstep(view.z + edge_dis, view.z, VERTEX.z), 0.0, 1.0);
float blend = clamp(prox / edge_dis, 0.0, 1.0);
vec3 color = mix(edge_color.rgb, water, blend);
ALBEDO = vec3(color);
}
It's the "foam" of a water shader, basically an outline to any mesh in the water. The problem is, when the camera gets close to the outline, it gets distorted. And I need to use it for a beach, where the outline is veeeerry long, I have no way of hiding it.
Here is the literal code from the node:
From afar looks fine:
But up close, it gets all curved:
And on a beach, even worse:
Already searched everywhere, could not find anything. Most water shaders in godot are outdated or ignore this problem. Tried searching for unity, and there the depth texture is somehow perfectly consistent, but it's done differently so no help either.
Am I missing something? Is this a bug or an oversight from the engine?