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

Question Built-in Render Pipeline "Camera Stacking" - "Don't Clear" flag clears previous camera

Discussion in 'General Graphics' started by Matsyir, Jun 3, 2023.

  1. Matsyir

    Matsyir

    Joined:
    Mar 13, 2019
    Posts:
    29
    To summarize, I'm trying to replicate what's described in this short 1:30 video:


    Firstly I'd like to clarify that this is NOT about URP's "Camera Stacking" feature. This is about the Built-in Render Pipeline, and manually stacking cameras that target different layers in order to separate post-processing effects.

    Basically, I want to apply certain post-processing effects on specific layers of GameObjects rather than on everything in the Main Camera. I'll refer to my two cameras as 'Main Camera' and 'Post-Camera'

    However, unlike what's seen in the video, my Post-Camera causes everything rendered from the Main Camera to be cleared. The Post-Camera has clear flags set to "Don't Clear", and a depth higher than the Main Camera's, so I'm lost as to why this is happening. I've tried various solutions like disabling HDR/MSAA, playing around with the Rendering Path, basically every core Camera option.

    For this test project, I have some 'light' bloom on the Main Camera, and some very heavy bloom on the Post-Camera to easily confirm that the post-processing is working separately on both cameras/both GameObjects. Well, the two objects do have different post-processing applied to them, but the Post-Camera is clearing everything from the Main Camera despite being set to "Don't Clear". Here's a quick recording of my test project which showcases the camera's configurations and the odd result:

    https://i.imgur.com/gb3qODd.mp4

    The intended/desired result is for the skybox/solid color background and the left sphere to still be visible. Does anyone understand why the 'Don't clear' camera flag is in fact, clearing everything?

    My actual use case has nothing to do with bloom, this is just a simple test project, but it's giving me this same issue in my real project.

    The project is now in the latest LTS release, Unity 2022.3.1f1 (and I still had the issue before updating, on Unity 2021.3.8f1). I'm open to alternative solutions rather than solving this issue if you guys know another good way to separate post-process effects between layers.
     
    Last edited: Jun 9, 2023
  2. jules_beep

    jules_beep

    Joined:
    Jun 2, 2022
    Posts:
    3
    In the same boat with 2D URP; trying to stack a background, default, foreground camera with DoF, no DoF, and DoF respectively. The foreground camera keeps overriding all the cameras behind it. On the same build of Unity too.
     
  3. Matsyir

    Matsyir

    Joined:
    Mar 13, 2019
    Posts:
    29
    I haven't touched 2D in a while, so forgive me if this only applies for 3D, but with URP you should be able to make use of the built-in camera stacking feature to achieve this. Here's a quick guide I copied from a pinned comment on that YT video I linked:
    If you're using URP, you'll notice there's no "clear flags" option, which is critical to making this work. In URP, you can follow all of these same steps - but when you create your child camera, set its "render type" to "overlay." Then, in your Main Camera's "stack" section, add your new overlay camera to the stack; it should combine with the main camera's output.

    You'll still have to ensure to manage each Camera's culling mask/target layers properly so that they aren't rendering on top of each other, and you'll also have to ensure your main camera contains the content of "lowest depth" with the overlay cameras adding on top of it. Hope this helps!

    PS. I have personally switched my project to URP so this isn't an issue for me anymore. In regards to the test project I recorded, I am indeed able to fix this with URP's camera stacking feature as described above. Still, it would be nice to get some clarification on this issue for those who are more stuck with the built-in render pipeline - it wasn't too bad to switch for me, and it makes sense for my project anyways as it's a simple style and will probably eventually be ported to mobile.
    Although, now the post-processing has changed and for now I can't find/re-create the effect I wanted to separate into two layers, only one as a Renderer feature which doesn't natively support stacking itself. So that's fixed but I'm left with a new issue to solve for now, lol. Regardless, that feature is an extra which is probably not as important as URP compatibility will be down the line. That's all unrelated to the main thread though.
     
  4. jules_beep

    jules_beep

    Joined:
    Jun 2, 2022
    Posts:
    3
    hi--to be clear, are your overlays child objects of the main camera (lowest layer)? Is it possible to send a screenshot of how you have yours set up? Or a text-mockup
     
  5. Matsyir

    Matsyir

    Joined:
    Mar 13, 2019
    Posts:
    29
    Your overlay cameras don't have to be children of your Main Camera, but yes, they were in my test, and in most cases that's what you'll want so that the overlay cameras' positions are based on the same position as your main Camera & get moved along with it.

    Here's a screenshot of my basic test project's setup in URP (note that the overlay camera is not included in the Scene's camera preview, but it does work in the game tab or when I run the game):
    upload_2023-6-18_21-55-27.png

    The inner camera, MainCamera_Megabloom's Render Type is set to 'Overlay', and its Culling mask includes only the World_Megabloom layer, which the Main Camera doesn't include as shown in the image.