Meshes not respecting Z order in certain positions

Hello,

I have two quads, the first is farer (big white circle) to the camera and the second is nearer to it (small robot).

If the second is closer to the center of the first quad, it appears before it (that is correct).
But if the second is in the right side of the first quad, it appears behind it on camera (that is wrong).

Some idea what could be causing it?
I’m rendering those sprites using quad meshes and ShaderMaterials to set the texture UV.

The scene composition is too complex as to build it in a playground, so I firstly ask if someone has an idea of what could be causing it.

Correct situation:

  • Camera:
    • Target: Vector3(1, 0, 0)
    • Position: Vector3(-422, 2, 0)
    • Rotation: Vector3(0, 90, 0)
  • Farer quad (white circle):
    • Position: Vector3(1, 25, -100)
    • Rotation: Vector3(0, 90, 0)
  • Nearer quad quad is at Vector3(1, 25, -100):
    • Position: Vector3(-19, 11, -165)
    • Rotation: Vector3(0, 90, -8)

Wrong situation:

  • Camera:
    • Target: Vector3(1, 0, 0)
    • Position: Vector3(-422, 2, 0)
    • Rotation: Vector3(0, 90, 0)
  • Farer quad (white circle):
    • Position: Vector3(1, 25, -100)
    • Rotation: Vector3(0, 90, 0)
  • Nearer quad quad is at Vector3(1, 25, -100):
    • Position: Vector3(-19, 11, -175)
    • Rotation: Vector3(0, 90, -8)

I didn’t check with actual numbers but if makes sense that the distance from camera to center of quad changes and quad order might change.
Moving the big white circle further away so order doesn’t change is 1 solution. A better one would be to change rendering group id like in this PG:

1 Like

You are right, the problem is the distance to the camera.

Let’s see how I fake it in a pseudo 2D scene… sprites Z order should be ordered by the distance to the camera perpendicular plane, not the camera center…

Set the rendering order with render group id, I think it will be easier to control and maintain.

1 Like