Search Unity

HDRP. How to draw characters on top of the background?

Discussion in 'High Definition Render Pipeline' started by EnriqueGato, Jul 29, 2021.

  1. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Hi there!

    I'm making a 2.5D platformer, and I'm trying to always draw the player on top of certain platforms so he doesn't cross them visually (2D style).

    I know you have to create a Custom Pass Volume, but I'm absolutely unable to set it up. This is the best I got so far.

    Any idea about it?

    upload_2021-7-29_16-15-43.png
     

    Attached Files:

  2. JansM

    JansM

    Unity Technologies

    Joined:
    May 20, 2019
    Posts:
    15
    Hello, I could propose a simpler solution that doesn't involve Custom Pass with DrawRenderers. Things you need to do:
    • Create a new layer and assign it to your character
    • Duplicate your main camera (parent duplicate to the main one), set its background type to none and set culling mask to your character layer.
    • Now you probably already see two mixed together but second camera leaks some extra fog that we don't want. In order to fix that, create another (global) volume with Exposure, Visual Environment (you can set it to dynamic) and Tonemapping similar to original volume (Mixing cameras doesn't play nicely when you have different tonemappings. in my case both volumes have ACES Tonemapping). Also set its layer to your character layer.
    • Go back to your character camera and set its Volume Mask to character layer too so it will use only that volume without any fogs.
     

    Attached Files:

    Last edited: Jul 29, 2021
    PutridEx likes this.
  3. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Thanks for your answer JansM. I didn't think on a solution like that. I'll try it out and see if it woks.

    Anyway, aren't Custom Passes supposed to be the "Easy Way" to do this? I checked this tutorial from Brakeys and it's actually really simple, but HDRP doesn have the same parameters.

     
  4. JansM

    JansM

    Unity Technologies

    Joined:
    May 20, 2019
    Posts:
    15
    It certainly is possible via Custom Passes, but i'm afraid it will be more difficult than just setting depth check to Greater as it already doesn't play nicely with your character submeshes. I will ask one of Custom Pass devs to pop in this thread
     
  5. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    Hello,

    For the custom pass, what you can try is to use the custom depth buffer instead of the camera one when rendering the object, this will force your character to render on top of everything in the scene while keeping the z-test correct.

    So the setup for the DrawRenderers custom pass would be:
    - Target Depth Buffer = Custom
    - Override Depth = true
    - Depth Test = Less Equal
    - Write Depth = true
     
    BreakfastBrew and seoyeon222222 like this.
  6. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    438
    WHAT?! User with "Unity Technologies" badge recommends multi-camera setup for HDRP? What about the performance cost of this solution vs custom pass? I personally wouldn't recommend anyone using more than one camera in HDRP because of the overhead that comes with it.
     
  7. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Hey, thaks for the answer! I'll try this ASAP. The multi-camera solution is definitely not good for this case.

    Thanks again

    Enrique
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,799
    Didn't they add a camera stacking system lately that's supposed to be reasonably efficient?
     
  9. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Ok, for a second it looked like it could work, but I as soon as I rotate the viewport I get a really weird behaviour (both in viewport and through gameplay camera).

    https://www.dropbox.com/s/ukc3r1epycw53p7/Custom Pass.mp4?dl=0

    I'm using Unity 2020.1.3f. Can it be related to that (outdated version of the editor)?
     
    Last edited: Jul 30, 2021
  10. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    My bad, I forgot that you also need to set the Clear Flags to "Depth Stencil"
     
  11. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    Apologies for the confusion here, camera stacking is not meant to be used for games as it's extremely expansive and for now custom passes are almost the way to go for real-time compositing.

    For other industries that only require interactive framerate or use HDRP with the recorder, the Graphics Compositor can be used: https://docs.unity3d.com/Packages/c...h-definition@12.0/manual/Compositor-Main.html
     
    AcidArrow likes this.
  12. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Aaaaaall right!!! Thanks antoinel. I've been dealing with this for a while (a looong while). I added another Custom Pass for the rest of the stuff I need to be drawn on top of the player and it works like a charm.

    Should I be worried about the performance wih this approach?

    Thanks again.
     
  13. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    265
    No, that should be fine :)
     
  14. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    Last edited: Aug 2, 2021
  15. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    Last edited: Aug 2, 2021
  16. EnriqueGato

    EnriqueGato

    Joined:
    Sep 3, 2016
    Posts:
    81
    I've tried playing with that parameter long ago, but it doesn't seem to be used for a case like this.