I’m doing a mostly 2D scene but using a perspective camera to support certain effects and transitions. The overall scene width is about 370 x 210 units, quads are aligned and scaled along XY only, all rotations in the scene are 0,0,0, and the camera is back at 0,0,-180. Only Z positions of the quads are altered (very slightly).
The problem is the quads don’t render with respect to their z positions the further they get from the vertical center of the screen (or, if you prefer, the center of the view frustum). Horizontal position has no effect.
For example, I have a scrollbar and a scroll-thumb towards the top left corner. The scrollbar has a very small positive Z value and the thumb is at Z 0, which should always position the scrollbar behind the thumb. When the thumb is near the top of the scrollbar (further from the center), it renders behind the scrollbar, but as it moves down the screen they swap places. If I reposition the quads at the bottom left corner I see the same behavior according to screen position (thumb further from screen center, towards the bottom, renders behind the scrollbar, then swaps as it moves up, closer to screen center).
I have to assign relatively large Z differences (greater than 1, enough to cause perspective problems) to force the correct order at all screen positions.
Why does this happen and can it be corrected?
Edit: Note this does not only affect quads. I’m using TextMeshPro objects in the scene and they’re exhibiting the same strange behavior. (Granted they’re all just flat textured meshes but I figured I’d mention that it isn’t somehow quad-specific.)
Left: thumb behind scrollbar (incorrect) – greater distance from screen center
Right: thumb in front of scrollbar (correct) – closer to screen center