- Home /
Problem with render order using 3 cameras!
Problems with rendering order using 3 cameras!
Hello guys! My project is structured as follows: - A "Main Camera" that renders the game properly; - A "GUI Camera" to render the GUI! I had to separate the GUI from the Main Camera, because for some reason the "Bloom" effect did not work on the GUI buttons in "Overlay" mode, so I had to create a GUI Camera in Screen Space - Camera mode; - A "Skybox Camera" to render only the Skybox. It was the only way I found that I had a little control in the position of the Skybox;
The problem is that even setting the Depth correctly on the cameras, the rendering order gets messy when I press Play. In the editor, everything is fine, but in Play mode, the Main Camera is rendered in front of the GUI Camera.
Could someone help me with this problem?
Answer by arvindiitkgp · May 25, 2017 at 07:22 PM
The problem is with the combination of canvas plane distance, gui camera near clip plane and mainCamera near clip plane values. These values should be in the following order: GUICameraNearClipPlane < CanvasPlaneDistance < GUICameraFarClipPlane < MainCameraNearPlaneDistance
Try these values:
GUICameraNearClipPlane = 0.01
CanvasPlaneDistance = 0.02
GUICameraFarClipPlane = 0.03 (Not required though, but should be greater than CanvasPlaneDistance)
MainCameraNearPlaneDistance = 0.3
In your case you are using more cameras than required, each new camera has got performance overhead, to achieve the bloom effect on UI elements just make the canvas render mode as world space and parent it to the moving camera.
Hope this helps :)
Thank you for this. I've spent the whole afternoon trying to fix a problem that I was sure was caused by camera rendering order. Unity docs state that rendering order is controlled by the camera's depth setting. This is the only mention I've found anywhere of the clipping planes affecting render order, but sure enough this has fixed my problem.
Answer by Owen-Reynolds · May 22, 2020 at 08:55 PM
The problem is the DontClear setting (on GUICamera in the middle). Things you want shown as overlays should be DepthOnly, which means: always draw the whole sprite, covering up lower-depth cameras, and being coverable-up-able by higher depth cameras.
DontClear is DepthOnly with an extra restriction: it says to check each pixel of your sprite for being behind a rock or a tree from a previous camera. Not only do you almost never want that, but it makes no sense for a GUI camera off to the side, with different settings. Even so, the computer tries. Technically, a sprite's depth is its percent distance between the near and far clipping planes. That's why messing around with them "fixes" it (there are a million ways to make the sprite count as "very low depth".
A way to use DontClear would be to have a world canvas, actually in the scene, using a camera exactly following the 3D scene camera. Then the depths would be computed using the same scale as the world, and parts would be properly blocked by closer 3D objects (I think).
Your answer
Follow this Question
Related Questions
Second camera has higher depth, but terrain still occluding camera image. 1 Answer
What is the best way to render a depth map to Texture2D? 0 Answers
"Motion vectors" and "depth with normals" from camera's target texture 1 Answer
Rendering to DepthTextureMode.Depth 0 Answers
Rendering different shader when camera get near object 1 Answer