Search Unity

URP Camera Stacking + Depth of Field issue

Discussion in 'Universal Render Pipeline' started by Aghawa, Apr 6, 2021.

  1. Aghawa

    Aghawa

    Joined:
    Apr 17, 2019
    Posts:
    6
    Hi all, so I've recently updated my project to URP, and while the performance gains have been great, I've ran into this issue.

    At the moment, my scene (3D) is built with multiple cameras, in order from bottom-most to top-most

    0-Background Camera (this renders the game background)
    1-Midground Camera (this renders objects between the player and the Background)
    2-Player Camera (This renders the player related stuff)

    Now, before starting using Camera Stacking, I used to have:

    0-Background Camera, environment set to Color (or whatever)
    1-Midground, set to Depth Only
    2-Player, Set to Depth Only

    So the Player Camera renders the player stuff, behind it the Midground cam renders the stuff behind, and at the bottom the BG camera renders a background.

    I used to have a Depth of Field post fx applied in a Global Volume which worked well, but since trying to setup the scene the same way with Stacking, I can't get this the focus distance to work anymore.

    Here's how I stacked my cameras:

    -Background Cameras (base)
    -Midground (overlay)
    -Player (overlay)
    since as far as I understood, it's the only way I can get the same camera layering?

    However, since this setup (and Post fx is applied to all 3 cameras), my Depth of Field's Focus Distance doesn't work anymore, as it seems to now only seem to focus at near infinity or really high focus distance value. This both in Bokeh and Gauss modes for all objects relying on the overlay cameras.

    Do Overlay cameras stop writing to the depth buffer or something similar?

    If you want to try it yourself, just create 3 cubes at 3 different distances, 1 camera set to Base, and a global volume with Depth of Field set. Then create a second camera, set your cubes to render only from that camera, and make that camera an Overlay stacked on top of the other base camera. Depth of field becomes defocused and (especially noticeable in bokeh mode) the focus distance doesn't seem to work anymore.

    Using Unity 2020.3.1f1

    Anyone had the same issue?

    Thank you!

    EDIT: So it seems that once a camera is in Overlay, Post Process active and has 3d geometry rendering on it, the Depth of Field Focal Distance MUST be set at that camera's Far Clipping Plane value. doesn't really make sense to me? Am I arranging things wrong?
     
    Last edited: Apr 6, 2021
  2. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    The Depth buffer that DoF will be working with is not going to be some combination of 3 depth buffers - you have to remember, there is no such thing as 'adding' depth buffers from 3 cameras together, that wouldn't work. So without a custom DoF effect, you will struggle to achieve what you want to with a complex camera stacking setup like that.

    For my game, I wrote a custom AO effect to get AO on both the scene (one camera) and player (FPS camera), which had to manually save the depth buffer from the first camera and pass it into the effect as another reference.

    A good way to see what the Depth of Field effect is using as it's depth buffer is to go into Frame Debugger, hit enable, find the DoF effect's first or second pass and ctrl-click on the depth buffer there. You will see the issue visually.
     
  3. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    68
    Std URP DoF in Bokeh mode is not working for near clipping plane even for simple Stacked camera with separated Env mask and separated Volume in same layer.
    Focus Distance is working properly only for base cameras.

    PS Just meet the same issue, 2020.3.11f1.