Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

An alternative to camera stacking for URP with a solution

Discussion in 'Universal Render Pipeline' started by Bosozuki, Feb 9, 2020.

  1. Bosozuki

    Bosozuki

    Joined:
    Dec 19, 2013
    Posts:
    63
    In our project we were using camera stacking for GUI, our GUY has 3D objects.

    So moving URP and from several forum post it seems this is not a recommended practice. So after going through lots of documentation, forum posts, and youtube videos I have come up with a single camera solution that works with no extra c# code

    Unity 2019.3.06f and URP 7.1.8

    I am putting this here for other people who may be struggling and for comments and thoughts about this solution.

    When you create the render you must add two Renderer Features that we call First Pass and Second Pass with the following settings

    First Pass
    EVENT - After Rendering (can be before post processing if you need post processing on the 3d objects)
    LAYER MASK - LAYER_MENU - What ever layer your objects are in
    OVERRIDES
    DEPTH - True
    WRITE DEPTH - True
    DEPTH TEST - Greater Equal

    Second Pass

    EVENT - After Rendering (can be before post processing if you need post processing on the 3d objects)
    LAYER MASK - LAYER_MENU - What ever layer your objects are in
    OVERRIDES
    DEPTH - True
    WRITE DEPTH - True
    DEPTH TEST - Less Equal

    In the scene view

    Attached to the main camera (i.e. all objects are parented to the camera) place all of your ui, 3d objects and place those objects in the layer LAYER_Menu

    Optional
    For lighting you will need to remove the layer LAYER_MENU from culling mask
    and add some form of light to the main camera that only has the culling layer LAYER_Menu Selected

    The lighting is optional depending on how you wish to light the GUI (also works very similarly with post processing)

    In our project we required the 3d objects to cast shadows correctly on each other hence why we did the lighting this way.

    As for the renderer Features the first pass makes sure the objects/gui are drawn after the *world* scene data
    so they always appear on the scene.

    The second pass reorders those objects to be drawn in the order they are placed in the scene view (i.e. box 1 appears behind box 2 correctly)

    The write depth must be check for both to keep shadows from the *world* scene data from appearing on the objects.

    Hopefully this will help and any thoughts appreciated.
     
    Onigiri and ryzeonline like this.
  2. ryzeonline

    ryzeonline

    Joined:
    Feb 10, 2020
    Posts:
    27
    This is way over my head, but I'd love if I could have camera stacking, with URP, *AND* 2D. Fingers-crossed one day :)
     
  3. Bosozuki

    Bosozuki

    Joined:
    Dec 19, 2013
    Posts:
    63
    Just a small followup,
    You will need to add separate passes for opaque and transparent objects. in other words four passes total instead of two.

    I had an issue when using vfx graph effects on menu items if the vfx graph uses transparency and the same with other transparent/ cutout items.

    I have not done a specific 2D test with URP and the new camera stacking that was added in 7.2.1, but the above method should work. Worse case scenario would be just to use a 3d project with URP and create the 2D game

    I know unity added quite a few camera stacking features with 7.2.1 (currently 7.3 now) but those versions of urp are not verified yet so I have not completed many tests with 7.2 and higher yet. (Once a new verified version is out I will complete performance tests to compare render passes versus camera stacking for specific use cases)

    Also ryzeonline you mentioned that it is over your head, its not too bad the real problem is the documentation is not updated and pretty sparse for the moment for render features and passes in what they actually do and how to use them correctly. There are a few youtube videos by unity and other youtubers and a few post outside of unity but quite a few them are old and are incorrect due to changes in URP etc.

    I had to do a lot of guessing and then lots of testing to say okay that is what that feature does... Documentation should get better this year, hopefully

    Cheers