Godot Version
4.3
Question
following along with a tutorial for a water shader (https://youtu.be/7L6ZUYj1hs8?si=lYCyQDsFNadkbZO3) and I’m at the part where he’s using edge detection to add like a beach foam effect on the edges. The problem is that instead of turning the edges white it’s turning the whole thing white even if its not intersecting anything.
Here’s all the relevent parts of my code
uniform float edgeScale = 0.1;
uniform float near = 1.0;
uniform float far = 100.0;
uniform vec3 edgeColor : source_color;
float calc_edge(float depth)
{
depth = 2.0 * depth - 1.0;
return (near * far) / (far + depth * (near-far));
}
void fragment ()
{
...
// geeting edge depth
float zDepth = calc_edge(texture(DEPTH_TEXTURE, SCREEN_UV).x);
float zPos = calc_edge(FRAGCOORD.z);
float zDif = zDepth - zPos;
...
vec3 depth_color_adj = mix(edgeColor, color, step(edgeScale, zDif));
ALBEDO = clamp(surfColor + depth_color_adj,vec3(0.0),vec3(1.0));
}