Render World Space Canvas First in 3D scene

I have world space canvases and I want them to be rendered over anything in the scene.

I have looked online and tried using a second camera that only renders the UI elements and applies that output onto a render texture. I tried overlaying that render texture over my main camera that does not render the UI elements, but I am not sure how to do that.

The second method I tried was to create a shader for the UI elements that always renders first. I made a shader that had Zwrite off and Ztest always on. Maybe I had something wrong with the shader but I applied it to the UI elements and that did not seem to work either.

Do you have any ideas on how to do this?

1 Answer

1

with the 2 camera solution you want to make sure the camera rendering the UI is only rendering the UI Layer (or whatever layer/s your UI is in), that it has depth only clearing, and that its depth parameter in the inspector is a higher number than the camera rendering everything else.

I think you can do a shader based solution for UI if you really need to avoid using 2 cameras, but its probably not necessary unless you really need the performance gains.

Okay but but then how do I merge the output of both cameras? I have never done anything with Cameras in unity with to this level, I would greatly appreciate it if you described the steps necessary to achieve this.