Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

HDRP Camera Stacking Now Supported?

Discussion in 'Graphics Experimental Previews' started by Korindian, Jul 28, 2019.

  1. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Camera Stacking was supposedly removed from HDRP, but according to the HDRP 6.9 docs:

    https://docs.unity3d.com/Packages/c...s.high-definition@6.9/manual/HDRP-Camera.html

    Quote from that page:
    "Cameras capture and display your world to the user. Customize and manipulate your Cameras to present your Unity Project however you like. You can use an unlimited number of Cameras in a Scene and set them to render in any order, at any position on the screen."

    Edit (for clarity): I tested this in 2019.2 with HDRP 6.9.1. Camera stacking works with multiple cameras, but has a high performance cost of anywhere from 1-2ms per camera on both the CPU and GPU.

    Post processing seems to work on the other cameras only when the highest depth camera has it. This means we currently cannot have a UI in World Space or Screen Space - Camera that is unaffected by post processing.

    Is Camera Stacking now a supported part of HDRP? Will it stay or be removed?
     
    Last edited: Aug 1, 2019
  2. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    There's been a lot of confusion about camera stacking in HDRP. Can we get an official word on this @Remy_Unity @SebLagarde ?

    Especially being able to choose which cameras get affected by post processing.
     
  3. Lawina

    Lawina

    Joined:
    Feb 28, 2019
    Posts:
    21
    LWRP as well.
     
  4. jeffcrouse

    jeffcrouse

    Joined:
    Apr 30, 2010
    Posts:
    20
    I am also interested in this.

    If it's not supported in HDRP, can someone suggest another way specify objects which are/aren't affected by a post-processing volume?
     
  5. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    936
    Hi,

    The documentation is correct. HDRP support many camera (that you can use to do render to texture), and it doesn't say that it support camera stacking.

    so official answer:
    HDRP support multicamrea (i.e split screen)
    HDRP don't support camera stacking

    We have however patched HDRP in 7.2.0 so it could support the stacking of camera within a set of constrain (i.e we manage correctly the clear of depth / color. We are working on a prototype to allow to compose multiple camera or stack them. There is no ETA for this tool but it mean some users could come with custom script for it.
    A big warning: the cost of camera stacking is very heavy (on CPU), and it is not recommended for game context. Prefer the usage of custom pass / custom post process.
    Also in HDRP if you want to draw UI after postprocess, there is a RenderPass mode on Unlit.shader and shader graph to do exactly that, it is name: AfterPostprocess (without the need of using a second camera)

    hope that help.
     
  6. AlexTuduran

    AlexTuduran

    Joined:
    Nov 26, 2016
    Posts:
    27
    @SebLagarde
    Hi. When you say it's very heavy on the CPU, you mean that rendering UI elements on an overlay canvas or with a custom pass / custom post-fx is significantly more efficient than rendering that UI on top of the scene with a different camera that renders only the UI?

    I'm asking because my project setup is so that I render the UI using a UI-only camera, so that the UI lives in world-space and shows up in VR. What's the correct alternative with a single camera in the case you want your UI to show up in VR as well?
     
    keeponshading likes this.
  7. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
    I have exactly the same issue with the extension that Space UI s interactive Worlda Space UI s are rendered to texture and applied to the car screens. They are up to 8 interactive screens in the car.
    So they din t need TAA because of smearing. This is working with the AfterPostprocessm described above.
    But they need Tonemapping and DOF because when car interior has DOF the screens need it too.

    For us this is the last showstopper to finally switch to HDRP.
     
    Last edited: Mar 9, 2020
  8. AlexTuduran

    AlexTuduran

    Joined:
    Nov 26, 2016
    Posts:
    27
    @keeponshading Just found out how powerful the custom pass / full-screen pass features are.I recommend taking a look at the following link, as it's a Unity project that exercises these features and manages to get some pretty amazing full-screen and per-object effects. You'll need Unity 2020.1.0a24 at least - I have 2020.1.0a25 and works fine.

    https://github.com/alelievr/HDRP-Custom-Passes

    Now speaking strictly about your car screens, you can render each screen separately with a different camera on render textures (make sure that the RT has alpha) and push these RTs in a Lit material as Base Map and / or as Emissive Color. Set the in the material Surface Type to Transparent, Rendering Pass to Default, Blending Mode to Alpha, check Transparent Depth Prepass, Postpass, Transparent Writes Motion Vectors and Depth Write. Set Depth Test to LessEqual. Also check Receive SSR if the Material Type is set to something that looks glossy (Standard, Iridescence, Translucent etc).

    Additionally, crank up the Smoothness and / or Coat Mask to make the surface glossy. Since we're talking about glass, you can enable refraction by setting the Refraction Model to Box or Thin. Of course, put that material(s) on quads, so they show up in the scene and render as geometry.

    HDRP-Transparency-Lit-Material-Settings.jpg

    By doing this, you'll effectively get a glossy refractive surface that although looks transparent it writes into the depth buffer, hence being subject to all post-processing effects that use the depth buffer, Depth-Of-Field being one of these. Also, because you're using the Lit shader, it will also respond well to the lighting in your scene (reflections included).

    Check the 2 uploaded photos for a reference of what you could get. The main difference between the two is that in the second one I've used alpha clipping.

    Why using alpha clipping? Since your transparent surface now writes into the depth buffer, everything that's behind it will not matter to the DOF (you can see that in the focus areas, the background is also in focus, which is wrong).

    HDRP-Transparency-DOF.jpg

    In the second capture, alpha clipping is enabled, so that the shader writes into the depth buffer only the information that has an alpha grater than some value (0.22 in my case). Doing so, you'll get correct DOF on your UI and also on whatever is in the background.

    HDRP-Transparency-DOF-AlphaClipping.jpg

    All the best.
     
    Beugnen, lord_Z, Instinctz and 2 others like this.
  9. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
  10. AlexTuduran

    AlexTuduran

    Joined:
    Nov 26, 2016
    Posts:
    27
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,725
    FYI camera stacking is a bad concept anyway, not one that most commercial games use. They favour drawing to buffers and can draw to another cam or combine, things like that.

    When you have multiple cameras with stacking in Unity, unity does all the work all over again per camera (and always has) from sorting lights to culling, it's a huge amount of waste render and cpu time (and always has been).

    It's better to ask from this point how to achieve your ambitions without an extra camera (you will find all things are possible, just different and much faster to execute)
     
    4sascha and Rich_A like this.
  12. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    hippocoder likes this.
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,725
    I haven't checked but I'm hoping that URP and HDRP gain parity with that sort of thing so I can port easily if needs be.
     
    Lars-Steenhoff likes this.
  14. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Is there an alternative way to render FPS objects with a different Fov than the Camera does, without Camera stacking?

    URP can achive this with custom pass, since there is an override for that.

    How about HDRP?
     
    Marc-Saubion likes this.
  15. josue16

    josue16

    Joined:
    Apr 24, 2017
    Posts:
    8
  16. bac9-flcl

    bac9-flcl

    Joined:
    Dec 5, 2012
    Posts:
    829
    If you're referring to making FPS weapons look like they are rendered with a different field of view, then a shader with a custom projection matrix distorting vertices can accomplish exact same effect without a need for an additional camera.
     
    lord_Z and MaxWitsch like this.
  17. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    I'll give that a try.
    Sounds very hacky in my opinion.

    Is it possible to just override the default projection Matrix or should I rewrite the lit shader?
     
  18. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,725
    Game dev is very hacky :D You can also try to write an area of depth to reserve it for the FPS weapon if that's possible.

    Multiple cameras are a game dev evil if they are doing all the same work over again.
     
    Sycoforge, MaxWitsch and Raul_T like this.
  19. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    I Agree.
    But in URP there is the possibility to override the Camera for custom Passes.
    Looks like it just overrides the Projection Matrix for rendering objects in this case.
    With no extra work for the Pipeline. Just integrated!

    Such a solution in HDRP, however, is completely missing.
    I guess this is another half baked thing that comes with HDRP. :D
     
  20. Hybris_Team

    Hybris_Team

    Joined:
    Oct 17, 2015
    Posts:
    114
    Is there a current guide/workflow for a replacement technique to camera stacking in HDRP?
     
    Marc-Saubion, RedEarth and Cookieg82 like this.
  21. valarnur

    valarnur

    Joined:
    Apr 7, 2019
    Posts:
    443
    There will be camera compositor tool.
     
  22. Hybris_Team

    Hybris_Team

    Joined:
    Oct 17, 2015
    Posts:
    114
    Oh ok that sounds promising. Has a timeline been released for that feature do you know?
     
    Cookieg82 likes this.
  23. Gasimo

    Gasimo

    Joined:
    Mar 3, 2015
    Posts:
    80
    Gentleman, I prezent you sie Compositor tool silently added into HDRP we have all waited for.
     
  24. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    Great now I need camera stacking tutorial.
     
  25. Frieza

    Frieza

    Joined:
    Aug 29, 2008
    Posts:
    68
    Me too, I tried this and couldn't get it to work with sub layers. Not sure what I'm missing.
     
  26. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    937
  27. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,654
    hi

    Is there a way to control which scene camera renders first ? I want to do my own reflection script and seems to have latency comparing to camera turn speed, i assume because renders after the main camera and next frame gets the old sample

    Thanks
     
  28. Gasimo

    Gasimo

    Joined:
    Mar 3, 2015
    Posts:
    80
    For anyone wanting the stacking cameras just for UI, new HDRP made a special UI Camera stack thingy to make it really cheap compared to full camera pass.
     
  29. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,100
    Link please.
    Sorry for being lazy.
     
  30. Gasimo

    Gasimo

    Joined:
    Mar 3, 2015
    Posts:
    80
  31. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    271
    There is also this repository that has a good solution for UI camera stacking (it was also linked in the blog post above): https://github.com/alelievr/HDRP-UI-Camera-Stacking
    It's still not perfect but in term of performance, it's on par with the custom pass option.
     
    keeponshading, Gasimo and iamarugin like this.
  32. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Hello, was trying to use the material solution to this problem but its a bit confusing to me.
    Seems like we have to apply the image in the shader if we do that which removes all of the abilities the Ui normally has and is basically not a viable solution for anything beyond the most basic of scenarios. So wondering if I am doing it wrong or something.
     
  33. alderaan_unity

    alderaan_unity

    Joined:
    Aug 25, 2022
    Posts:
    1
  34. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    369
    I was considering looking into this, but you're saying it doesn't work in a Build. What version of Unity are you using?
     
  35. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    I've used camera stacking in built-in to create an asteroids style screen wrap with visibility on both sides. its a bit nasty with side effects. would compositor be a better way to achieve that?
     
  36. GhostbuGaming

    GhostbuGaming

    Joined:
    Sep 17, 2019
    Posts:
    25
    What about compositor? Its a bit confusing to work with...or maybe it was confusing because I was playing the sliders without knowing which slider does what...but really wish if HDRP had camera stacking like URP...
     
  37. driitzzcabal

    driitzzcabal

    Joined:
    Oct 7, 2017
    Posts:
    2
    HDRP feels rushed, so many features that was in previous renderpipeline got removed, like camera stacking which was so convenient and easy to do in URP.
    Now to achieve the same effect in HDRP you have to create a render texture , a shader , make a cube or plane add the render texture to that object and position it in front of the main camera? How janky is that?
    Or im dumb and can't read , the documentation aint very helpful and theres a lack of tutorials...

    Not to mention the memory leaks and the constant error about dx11 loop warning in the console.
    Amazing water and clouds thought woo. but imo with all the things that HDRP messed up it just not worth the hassles of all the cons that it brings.
     
  38. boyaregames

    boyaregames

    Joined:
    Jun 23, 2021
    Posts:
    86
    Addind the second camera in HDRP basically halves your fps no matter what pp settings are set.
    Currently all this stuff you have to do via custom pass using hdCamera (main).
     
    Gasimo likes this.