Upgraded my project to 5.6, and I now seem to have cameras that don’t respect the depth buffer. This seems to be caused by the following change in the release notes:
Graphics: Refactored camera render ordering code. When a Scene is rendered, it now figures out which cameras can share the same render target. The rules for this are:
- Cameras must use the same display to share the same render target.
- Cameras must share the same viewport.
- All cameras must have a depth buffer, or none of them must have a depth buffer.
- If the Scene is being viewed in VR, the cameras implicitly share the same render target.
These cameras are then split into a stack, which is rendered into a shared Texture based on depth ordering. This Texture has the most common settings found in the cameras in the stack.
My problem is that I have:
- A full-screen camera for background UI elements. (Depth 1)
- A split-screen camera for mid-ground 3D objects. (Depth 2)
- A full-screen camera for foreground UI elements. (Depth 3)
Unity detects that camera 1 and camera 3 share the same viewport, and render them together. Camera 2 is then rendered on top of Camera 3, despite Camera 3 having a larger depth buffer.
My current solution is to change the viewport width of Camera 3 from “1” to “1.1”, to prevent it sharing the same render target as Camera 1. It solves my problem, but it seems like a flawed workaround. Is there a setting I’m missing?