I have a camera that renders to an off-screen RenderTexture. I render this manually with the camera’s Render method. I also have a command-buffer that I’ve inserted into the camera “AfterSkybox”.
In this command-buffer, I draw objects again using CommandBuffer.DrawRenderer to a different colour render buffer, but I need to (re)use the original camera depth buffer.
This works fine. Except …
If the camera has any post-processing component active, or has HDR rendering enabled, then the depth buffer when executing my command-buffer is upside-down. (The original colour buffer is too - but I can cope with that!)
What can I do to resolve this?
I could copy ‘n’ flip the depth buffer to another RenderTexture’s depth buffer - but I can’t see any obvious (and lossless) way of copying depth. Can’t see any Graphics.Blit variants that would do this, for example.
I could draw all my objects v-flipped in the command-buffer, and then flip the whole render texture afterwards. I would need to try it and see if it still matches exactly (I’m relying on a z-equal depth test) due to rasterization rules etc.
Ideally I would avoid any additional blitting/flipping at all though. Is there any trick I’m missing that results in the camera drawing things a consistent way-up??
Any advice would be greatly appreciated.