Godot Version 4.3 .Net
Question
(I apologise for any confusion english is not my mother tongue)
I was adding depth based transparency to my shader and as a side effect my waves became transparent in a weird way, cant figure out why this is happening, I’m having transparent waves when looking from one side but not when looking from the other, id like for my waves to not be transparent from both sides when it comes to other waves, (this affects ONLY other waves and works as expected for any other meshes).
Video explanation: Imgur: The magic of the Internet
Code:
shader_type spatial;
render_mode shadows_disabled;
uniform sampler2D depth_texture : hint_depth_texture;
uniform float depth_distance : hint_range(0.0, 50.0, 1.0) = 0.5;
uniform float transparency : hint_range(0.0, 1.0, 0.1) = 0.5;
uniform sampler2D screen_texture : hint_screen_texture;
uniform vec3 watercolor : source_color;
//normal maps
uniform sampler2D texture_normal;
uniform sampler2D texture_normal2;
//teksture
uniform sampler2D tekstura_pjene;
vec3 GerstnerovVal(vec4 val, vec3 vertexP, inout vec3 tangenta, inout vec3 binormal) {
float nagib = val.z;
float wavelength = val.w;
float k = 2.0 * PI / wavelength;
float c = sqrt(9.8 / k);
vec2 d = normalize(val.xy);
float f = k * (dot(d, vertexP.xz) - c * TIME);
float a = nagib / k;
tangenta += vec3(-d.x * d.x * (nagib * sin(f)), d.x * (nagib * cos(f)), -d.x * d.y * (nagib * sin(f)));
binormal += vec3(-d.x * d.y * (nagib * sin(f)), d.y * (nagib * cos(f)), -d.y * d.y * (nagib * sin(f)));
return vec3(d.x * (a * cos(f)), a * sin(f), d.y * (a * cos(f)));
}
void vertex() {
vec4 val1 = vec4(0,1,0.5,50);
vec3 tangenta = vec3(1, 0, 0);
vec3 binormal = vec3(0, 0, 1);
vec3 vertexP = VERTEX;
vertexP += GerstnerovVal(val1, vertexP, tangenta, binormal);
VERTEX = vertexP;
NORMAL = normalize(cross(binormal, tangenta));
}
void fragment() {
// Sample the red channel from the depth texture at the screen coordinates
float depth_red = textureLod(depth_texture, SCREEN_UV, 0.0).r; // Get the depth value
vec4 world = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, depth_red, 1.0); // Transform screen coordinates to world coordinates
world.xyz /= world.w; // Normalize the world coordinates
float depth_blend = smoothstep(world.z + depth_distance, world.z, VERTEX.z); // Calculate the depth blend factor
vec3 screen = textureLod(screen_texture, SCREEN_UV, 0.0).rgb; // Sample the screen texture
ALBEDO = mix(vec3(depth_blend) * screen, watercolor, transparency); // Blend the screen texture with watercolor based on transparency
METALLIC = 0.0;
ROUGHNESS = 0.1;
}