Is there a way to render "forward" materials before the deferred render pass?

I switched to deferred rendering and my custom skybox (forward material) is overdrawing some of my objects in the background that are using deferred materials. The reason for this according to the frame debugger is the fact that forward materials will be rendered after the deferred GBuffer rendering is done. The skybox material has ZWrite Off and ZTest LEqual so it’s comprehensible that it is overwriting the aforementioned objects in the background.

Is there a way to render some materials in front of the deferred pass? How is Unity solving that? Is Unity internally drawing an insanely huge sphere or how does it happen that Unity’s default-SkyBox isn’t overwriting my background objects?

Note: “Custom sky box” means that I’ve created a separate gameobject with a UV sphere as a mesh. I have to do that because Unity’s default SkyBox rendering mechanism happens right before the first transparent material which is isn’t suited for my needs.

Yep.

When Unity draws the skybox it is doing so with a unique UNITY_MATRIX_MVP that is scaled by the max draw distance and with no translation so that it’s always as far away as possible and centered on the camera. You can create your own “skybox” matrix in a custom vertex shader to replicate this if you don’t want to use the skybox queue for your shader. I do this for rendering stars. Alternatively you can write depth out from your fragment shader, but this can be slow if your fragment shader is expensive as it’ll prevent early depth rejection.

Or you can just scale up your geometry.

1 Like

Thanks again bgolus! :slight_smile: May I ask how you figured that one out? Did you once work for Unity?

Frame debugger & RenderDoc

1 Like

RenderDoc? Interesting! Thank you. :slight_smile: