Godot Version
4.2.1
Question
Hello fellow developers!
I have a scene with a X-shaped 3D lowpoly mesh ( basically just a two quads) object with a shader material ( tree texture with alpha channel). Unfortunately, when I look on the mesh from different sides I can see that one quad of the mesh draws over the other quad even when it shouldn’t. I want to fix this ‘side overlapping’ but I don’t know how and hope you give me a hint. Thank you!
Video of the issue: video
The shader itself supposed to make mesh visible from both sides of the quads and lit it:
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx;
uniform sampler2D tree_texture : filter_nearest_mipmap;
void vertex() {
// Called for every vertex the material is visible on.
NORMAL = normalize((MODEL_MATRIX * vec4(NORMAL, 0.0)).xyz);
}void fragment() {
// Called for every pixel the material is visible on.
vec2 uv = UV;
vec4 tex_color = texture(tree_texture, UV);
ALBEDO = tex_color.rgb;
ALPHA = tex_color.a;
}void light() {
vec3 lightN = NORMAL;
if (dot( lightN, LIGHT ) < 0.0)
{
// reverse the normal if it’s facing away from the light
lightN = -1.0 * lightN;
}
DIFFUSE_LIGHT += clamp(dot(lightN, LIGHT), 0.0, 1.0) * ATTENUATION * ALBEDO;
}