Perpective behavior incoherence

Hello,

I’m having an issue trying to build a gameobject with some kind of perspective.

From the front it looks like this (it’s a kind of room):

The background is at z=0, the walls are rotated around the y axis, the floor and ceiling around the x axis.
Theses 4 sprites are closer on the z axis (z=50).

If I move the view the walls start to overlap:
image

But if I start to rotate the viewport (ctrl+lclick) the perspective gets fine instantly:
image

The issue is that in-game I get the overlapping sprites, when using default camera with perspective or rendercam.

Have I done something wrong ?
Thanks in advance

You can try and reproduce with these assets:

room.zip (3.5 KB)

Have you tried recreating this with model components and the quad from builtins?

I also think perhaps @Dragosha has some experience with sprites and perspective cameras?

1 Like

That’s because sprites don’t use z-buffer depth test in common render pipeline. They sort by their pivots. If one sprite’s pivot in the camera view is closer to the camera pivot than other sprite’s pivot then sprite one render above other one. When you rotate the camera you are changing this ordering.

Well, for correct sorting you need to use a mesh or model components as @britzl said. They using z-buffer by default. In render_script it looks like

render.enable_state(render.STATE_DEPTH_TEST) -- check z-buffer
render.set_depth_mask(true) -- write to z-buffer

or enable this feature to sprite predicate too. But notice that z-buffer depth test may broke render-order of self-transparent sprites.

6 Likes

Thanks for your answers, I’ve recreated a test project from this sample:

It looks like it’s working for this gameobject alone, but if I continue this way I think I’ll have to rethink a lot of the stuff around.

Also, I’m playing with tints and lights, and it looks like depending on the camera position, if have a kind of light reflection effect on quads:

If you open up the model material you will see that there is a lightsource. In the basic 3d project template it gets updated based on mouse position:

If you skip the light update based on mouse position and instead copy and modify the material and position the light far from the camera (0 0 1000 0) everything should be equally affected by the light I think.