Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I stack two deferred cameras as optimally as possible? (BIRP)

Discussion in 'Shaders' started by VirtusH, Nov 25, 2023.

  1. VirtusH

    VirtusH

    Joined:
    Aug 18, 2015
    Posts:
    94
    Context: BIRP. We're currently rendering parts of the scene at lower resolution, storing that result in a render texture, then re-rendering everything at full-resolution with water geometry. The water shader is deferred and uses the pre-pass to create a transparent water effect. Because it's all deferred, we can then slap a semi-custom SSR implementation on top for fantastic looking transparent water with fully dynamic reflections and shadows under the surface of the water.

    Now of course there's quite a bit of overhead, especially on the GPU-side because so much has to be rendered twice. I've considered many ways to tighten that up, but the most promising idea is this:
    1. Render everything without water at full quality, but with no post FX.
    2. Second camera doesn't clear, retain GBuffers. (This seems to be the sticking point)
    3. Second camera uses command buffers to render water geometry, with postFX.
    Then we would have minimal overhead for a proper 2-pass solution.

    I've been reading all over the forums, and it sounds like Unity's BIRP Gbuffer setup may be way too rigid to stack deferred cameras directly, but it feels like something that should be possible.

    Is there any way with command buffers to effectively 'stack' the gbuffers directly like this to completely reuse the first-pass?

    In my attempts to simply stack the cameras, it appears as though the second pass inherits a bunch of information, but ultimately just overwrites the previous depth information completely, which destroys the final result.