I have a depth-peeling effect which is calling ‘Camera.RenderWithShader()’ (using a copy of my main camera) multiple times in order to render the transparency correctly.
It works quite well, but now I am adding some UI (screen-space overlay) and it totally kills the performance.
When I look into the profiler, it seems that the problem is caused by ‘UIEvents.WillRenderCanvases()’ which is called by each call to ‘Camera.RenderWithShader()’.
I have no canvas which is not screen-space overlay so I guessed that ‘Camera.Render()’ renders the screen-space canvas too.
But in the frame debugger I do not see the UI during the construction of the image, which is in ‘Camera.Render → Camera.ImageEffects → DepthPeelEffect’.
The UI is added at the very end and only once in ‘UI.RenderOverlays → Camera.RenderOverlays’.
So I don’t really know what’s happening here.
I tried to disable the canvas but it does next to nothing.
Disabling the gameObject which contains the canvas does restore the performances.
I tried to use Screen Space - Camera but it actually reduce the performance by a lot (despite the fact that the UI isn’t displayed anymore since the camera is configured not to display the UI layer).
Is there a way to call ‘Camera.Render()’ while completely excluding the canvas set to ‘Screen Space - Overlay’?
Note: I am using the Built-in render, would changing that help?