Good morning Community.
I tell you my problem.
I am using multimesh3d, to create multiple instances with a shader that makes cuts to the image, depending on the position and size of the subimage. My code Shader
`shader_type spatial;
uniform sampler2D main_texture;
uniform float transparency : hint_range(0.0, 1.0) = 0.0;
varying float x;
varying float y;
varying float ancho;
varying float alto;
varying float zorder;
void vertex() {
x= INSTANCE_CUSTOM.r;
y= INSTANCE_CUSTOM.g;
ancho = INSTANCE_CUSTOM.b;
alto = INSTANCE_CUSTOM.a;
}
void fragment() {
vec2 frameSize = vec2(ancho, alto);
vec2 frameOffset = vec2(x,y);
vec2 texCoord = UV * frameSize + frameOffset;
vec4 texColor = texture(main_texture, texCoord);
// Aplica el color del segmento al resultado final
texColor.a *= 1.0 - transparency;
ALBEDO = texColor.rgb * texColor.rgb;
ALPHA = texColor.a;
}`
But I have the problem when viewing the instances with an orthogonal 3D camera, with position (0,0,40) and rotation (0,0,0) I am simulating a 2D visualization in 3D.
The problem arises when rendering the instances, for each instance that is drawn. I use the Z coordinate, to use it as depth, that is, while Z is larger, it should be rendered above Z, which is smaller.
But the problem arises there since it does not respect the rendering order, I understand that it is due to the camera mode in orthographic mode, in position 0,0,0. What it does is always render the smaller instance above the larger instance.
I don't understand the reason, and if anyone knows how to configure the camera or perhaps the shader so that the depth of the instance is taken correctly
If we move the camera to see another perspective, I see that it really draws it well, the problem is when the camera remains at 0,0,0
Camara with rotation
Camara without rotation
I hope you can help me.
regards.