Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

URP + Deferred + Camera Stack not possible?

Discussion in 'Universal Render Pipeline' started by Jonas-Neuston, Nov 28, 2021.

  1. Jonas-Neuston

    Jonas-Neuston

    Joined:
    Jun 10, 2017
    Posts:
    70
    Unity 2021.2.3f1
    Universal RP 12.1.1

    I'm using camera stacking to render first person weapons with a different field of view on top of the rest of the game.

    When I set the rendering path to Deferred the weapon camera can't set the Render Type to "Overlay" (it's in the list but grayed out). Switching it back to Forward makes it possible to select "Overlay".

    I would like to use Deferred rendering. Is it not possible?
     
    Haapavuo likes this.
  2. benjmitch

    benjmitch

    Joined:
    Nov 27, 2019
    Posts:
    17
    I'm using the same Unity stack more or less, and hitting the same need. My understanding is based on this page:

    https://docs.unity3d.com/Packages/c...ersal@12.1/manual/urp-universal-renderer.html

    which states "Unity renders only the base Camera using the Deferred Rendering Path. Unity renders all overlay Cameras using the Forward Rendering Path."

    As expected, I can select "Overlay" for a camera that is using the forward renderer, and can stack this on a camera using the deferred renderer. This appears to work, though I haven't gone further than testing a successful execute.

    But - is this a fundamental limitation, or can we expect to be allowed to stack deferred pipeline cameras in future? For my application, the stacked camera is the one that needs to be deferred, so this issue is blocking for me. I'm afraid I don't understand the tech well-enough yet to determine this.



    As an aside, I feel this page might usefully make a statement on it, or link to the above, also:

    https://docs.unity3d.com/Packages/c...es.universal@12.1/manual/camera-stacking.html
     
    MrDizzle26 likes this.
  3. fule123

    fule123

    Joined:
    Oct 30, 2020
    Posts:
    3
    You need to create a new URP Renderer and set the Rendering Path to forward.
    Then add it to the URP Asset and your overlay camera should use this forward renderer.
    upload_2022-4-21_11-39-52.png
    Now you can choose Overlay.
    upload_2022-4-21_11-40-10.png
     
  4. bajja

    bajja

    Joined:
    Feb 3, 2013
    Posts:
    5
    Worth noting that you can stack deferred cameras by setting them all to Render Type "Base", and then using the priority setting to order them - setting cameras above the lowest priority to Background Type "Uninitialized" so they don't wipe the screen.
    Presumably, doing this will result in multiple gbuffer / lighting passes.
     
    EvanZSV and Kreshi like this.
  5. benjmitch

    benjmitch

    Joined:
    Nov 27, 2019
    Posts:
    17
    @fule123 That works, but means the overlay camera must use the forward renderer, whilst the OP wants to use the deferred renderer.

    @bajja Thanks, I hadn't seen that. However, the two cameras do not overlay each other, though they certainly can render alongside (targeting Display1). I can't quite work it out, but I wonder if this is a limitation of the deferred rendering technique, or just a configuration issue. It seems that both (deferred renderer) cameras are preparing their image in a separate space, and then blitting the end result to the target (Display1). Since the interaction at the target is only in that final blit, there is no 'overlaying' of the objects rendered by one camera over those rendered by the other. It may be as simple as saying 'the two cameras do not use the same GBuffer object', but I can't see any info on that in the Frame debugger. There must be a reason why camera stacking is not supported for 'deferred on deferred', and I wonder if this issue is also blocking the overlay technique, here.
     
  6. OverTheImmense

    OverTheImmense

    Joined:
    Oct 14, 2021
    Posts:
    2
    thx brother
     
  7. benjmitch

    benjmitch

    Joined:
    Nov 27, 2019
    Posts:
    17
    I found a solution/workaround (not sure which) to this, in the end. 'Base' camera is set to priority 0, and renders using a forward renderer, into a render texture. 'Overlay' camera is set to priority 1, and renders using a deferred renderer, into the display. Then I put a plane in the world, with depth test set to always, and depth write set to off, displaying the render texture from 'Base' camera. It feels a bit hacky, but the performance seems ok so far, and certainly it works.

    The only thing I'd like to do to improve it is to simply blit the rendered texture to the overlay camera background as a first rendering step - or, at least, to render it using an object attached to a RectTransform so that it always exactly fills the view. At the moment I'm having to manually adjust the scale of the rendering plane so that it slightly overlaps the view of the overlay camera to ensure there's no gap at the edge, and that feels like I'm doing it wrong.

    Anyway, much happier with the result, thanks for the input.

    Clearly, then, it's not technically impossible to overlay a deferred-renderer camera on a forward-renderer camera in URP, since I found a way of effectively making that happen. That leaves me ignorant of why it's not supported in camera stacking, I'd be curious if anyone knows that.
     
    Lipoly likes this.