3D object display issue

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;
}

When you say ‘lit it’, not sure what you mean, do you have an example? Do you want the lighting on the back sides of the triangles to match the shading they are getting on the front side, or something else?

Hi!
I just uploaded the video of the issue here: video
Unfortunately Godot forum don’t want me to share it directly here so I hope this link works for you. The ‘lit’ part was recreated from really old video where person was struggling with lighting of 2d objects in 3d space and that’s all. For ex. when you put light from one side it’s well illuminated and the other was unlit.

try using:

depth_prepass_alpha

instead of:

depth_draw_opaque

or along with it, not sure what would work best for your setup.

1 Like

You’re my hero! This is the answer!
Thank you so much!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.