Search Unity

Bug HDRP - Render object in front of everything with Custom Passes when Ambient Occlusion is ON

Discussion in 'High Definition Render Pipeline' started by ristetutureski, Jul 10, 2021.

  1. ristetutureski

    ristetutureski

    Joined:
    Jan 29, 2019
    Posts:
    23
    Hello Respected,

    For our game, we are using HDRP version 11. We needed a solution when the objects are in inventory or in examine mode, to be rendered in front of all other objects in the scene to avoid clipping. Since for HDRP using another camera was not a solution, we achieved that with creating Custom Passes. Here is our blog that we wrote for this solution since on the net, there was no any solution for it when HDRP is used: https://www.intetic.com/blogs/unity-hdrp-render-object-on-top-of-everything/

    Everything worked fine. But now when we enabled Ambient Occlusion, the object that we want still is rendered in front of all other objects, but Ambient Occlusion itself is above this object that is in examine state (that is the point when our Custom Passes are running against that object).



    Is it possible somehow to fix this problem? Because it looks like our object is "transparent" since Ambient Occlusion is above it.

    Thank you,
    Riste Tutureski
     
  2. CihanGurbuz

    CihanGurbuz

    Joined:
    Apr 30, 2020
    Posts:
    25
    Hello there.
    I was having trouble with custom pass before. My problem was that when I used subsurface scattering it showed the material black.

    Topic link
    https://forum.unity.com/threads/custom-pass-issue-subsurface-scattering.996329/

    I discovered your blog two days ago and with your method I can now use subsurface scattering and custom pass.
    I wanted to thank you for this.:) I also wanted to say that it is problematic for using custom pass in temporalAA.

    Video of the problem.
    https://drive.google.com/file/d/1Ra5D_Xc7ct-3mr6jcFyhBbbKsrcV8CDG
     
  3. masak

    masak

    Joined:
    Aug 14, 2011
    Posts:
    52
    Hello,
    How did you solve the subsurface scattering problem that the material looks black?

    I tried the way of ristetutureski, but still black:(
     
  4. CihanGurbuz

    CihanGurbuz

    Joined:
    Apr 30, 2020
    Posts:
    25
    Hi.

    I created a custom pass in camera. My camera and custom pass settings are as shown below.

    1.jpg
    2.jpg
     
    masak likes this.
  5. masak

    masak

    Joined:
    Aug 14, 2011
    Posts:
    52
    Thanks! I could render sss material!:)
    Injection point and culling mask in main-camera are important
     
  6. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
  7. CihanGurbuz

    CihanGurbuz

    Joined:
    Apr 30, 2020
    Posts:
    25
  8. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Ah, so it seems motion vector not working nicely with custom pass for now. I've tried spoofing the motion vector but it's also doesn't work. :/
     
  9. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    @CihanGurbuz
    well as usual find a way fix one but break others....

    Clipping can be avoided, custom FOV, Movecs support.

    But self shadow projection are broken. . . . :confused:
     
    Ruchir and CihanGurbuz like this.
  10. CihanGurbuz

    CihanGurbuz

    Joined:
    Apr 30, 2020
    Posts:
    25
  11. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    i move away from custom pass at least for now until they add support for motion vector in custompass.
    I just use a slight modification of shader from this sample https://forum.unity.com/threads/fps-sample-shader-graph-for-weapon-fov-not-working.576796/
    I modify so it's also apply scaling on z axis view space. But yeah now it screwed up shadow projection.
    This video also a good references but it's on UE4 though

    we might need a separate thread to talk about fps viewmodel rendering in HDRP
     
    KCGames47 likes this.
  12. CihanGurbuz

    CihanGurbuz

    Joined:
    Apr 30, 2020
    Posts:
    25
    @Reanimate_L

    Ah yes, I've seen that before. I have not tried this method neither in unreal nor in unity. Because methods other than the render layer bring their own problems. For example, our weapon will have a muzzleflash and bulletshelleject effect. What will these effects look like when the gun goes into the wall? Problems problems and problems. :)

    Thanks for the feedback my friend.
     
  13. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    yeah well like i said above, fix one break others :confused:
     
  14. FriendNFoe

    FriendNFoe

    Joined:
    Sep 24, 2012
    Posts:
    11
    I'm on the same boat, can't find a way to make HDRP work with FPS weapons or items. :(

    1. Custom Passes = messes the AO/motion vector buffers so it looks terrible
    2. Stacking cameras = with/without the Compositor has terrible performance.
    3. the FPS Sample shader = 3 years old... doesn't work any longer.

    Would be great to have somebody from Unity have some input on this, seems like everybody is having the same issue with FPS weapons in HDRP... since 2018.
     
    jiraphatK, gewl, jorikito and 4 others like this.
  15. KCGames47

    KCGames47

    Joined:
    Nov 3, 2014
    Posts:
    39
    I think our best bet is to wait until someone creates a 3rd party asset that completes this feature for them.. coz this is apparently how it works..
     
    Ghosthowl likes this.
  16. Gasimo

    Gasimo

    Joined:
    Mar 3, 2015
    Posts:
    68
    I reckon the UFPS asset on the Asset store managed to accomplish the FPS weapon rendering in a performant and bug-free way somehow. Didnt pick it apart to see how it works yet but seemed to work.
     
  17. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    I get what you did, but to have SSS shading working correctly in a Draw Renderer Custom Pass, there is another workaround :
    • Create your skin shader with ShaderGraph, set the Master Node to Transparent BUT set the material that come from this shader as opaque (it is still an option in the material, so np), it's capital => there are some data that will get some data initialized to make your SSS happend in the custom pass.
    • for injection point : After opaque and Depth to Before Post Process should work as expected.
    • Render queue Type : all
    • Override Depth State box : need to be enable to draw the mesh correctly,
    • Depth write box : can be checked as and comparison set as less equal for normal sorting, but it can be as you choose it to be
    here is a screen shot (I don't have the exact same GUI as you guys as I have modified my Custom Pass scripts to output into a given RT only using the Samplebuffer material, and I did get rid of the custom Inspector Editor script btw). SSS is working perfectly and Depth too :

    Capture d’écran 2022-07-13 170521.png

    cheers, hope it will help some ppl using Lit Subsurface Scattering Shader in a CustomPass
     
  18. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    Setting Master Node to transparent completely disables SSS for me (on StackLit Shader), regardless whether I use Custom Pass or not.
     
  19. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    Weird I got it working on StackLit, into both the custom pass and the camera rendering, did you keep the material in opaque mode?
     
  20. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    Ah something that may be important, It can be resolved.
    Right Click on your Main Color Map property in your ShaderGraph, then set this property to be the Main Texture, It will help the shader to resolve everything accordingly to the baseColor map across each sampler
    Capture d’écran (11).png
     
    Last edited: Jul 17, 2022
  21. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    BTW, in the StackLit master node in ShaderGraph, there is only a transmission box available, and so I think you should consider to use Lit in SSS mode to work on skin as it is better for SSS skin shading use
     
  22. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    StackLit does have SSS. It’s much better for skin then Lit. It’s also used by heretic project. You have dual lobe specular, which is essential for skin rendering.
     
  23. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    I kept it in opaque mode. I guess SSS is turned off because it’s not supposed to work on transparent shader. As soon as I set shader graph to transparent and save , the SSS effect vanishes. Custom pass works then, but no blur from SSS anymore.
     
  24. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    Your object should be in the opaque queue because the material is set to be so, I have the transmissin WorldScale responding too, it's an issue on your side, Do you use Before Post Process injection point with depth write enable in your pass setup?
     
  25. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    The issue is not the custom pass. Even without any custom pass, SSS is switched off if shader graph is set to transparent. Which makes sense, as transparent does not support SSS. Not sure why you can see it, and what’s different. I just switched shader graph to transparent, and keep materials to opaque. SSS is then off. If I set shader Gehalt to opaque, SSS is on.
     
  26. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    Ok , I guess you didn't get all my skin materials are set to opaque not transparent, the meaning of the master node to be set as transparent (into the shader, not the material you create) is to enable some usefull data so, some part of of Data you miss to resolve the SSS obviously, here is a screen of the material of his working like a charm on my side (to repeat again, I got it working, not you buddy)
    Capture d’écran 2022-07-15 003904.png
     
    Last edited: Jul 17, 2022
  27. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    I can't screenshot the result of my work in my actual project bcs NDA etc, so I will prepare a Sample to be shared as proof of concept using a sphere, draw in a custom Draw Renderer pass and using a stackLit shader setup with transmission and dual lobe spec.
     
  28. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    As said I switched material to Opaque. Which Editor version are you on? Maybe that's what makes the difference in behavior. I am on latest LTS (2021.3.6)
     
  29. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    2021.3.1f1, it should not be different from .3.6f1 :/, I think i will up the project asap so I'll tell you if it break, but I don't think so. I prepare a public git repo exemple today (tonight), I'll put the link here
     
  30. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    Last edited: Jul 16, 2022
  31. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    hm, scene does open, but shows only grey. No errors. I also noticed that it is using DXR + DX12, never used that, but it might be the reason why it behaves differently. But I cannot check due to the scene not showing.
     
  32. hugokostic

    hugokostic

    Joined:
    Sep 23, 2017
    Posts:
    84
    You can just Disable DXR, this is the setup from the HDRP wizard btw
    And no, RTX don't have anything to do with stackLit and custom Pass, I guess you will have the same result as in the readme once RTX/dx12 disabled.
    Anyway.. I have push the repo with RTX/DX12 disabled and it still work, take a look :
    Capture d’écran (16).png
    Capture d’écran (17).png
     
    Last edited: Jul 17, 2022
  33. koochy_rat

    koochy_rat

    Joined:
    Oct 26, 2011
    Posts:
    40
    Bumping this as hopefully someone knows of a solution. Subsurface materials are black in a custom pass. All the workarounds in this thread are not working for me too.

    Transmission definitely works when you set the shader master node to transparent. But subsurface scattering does not. The scattering effect is more subtle and only noticeable with a low light angle and bumpy surface. I've tried the repo above with and without custom pass and using a proper model (not just spheres), the results are as below:

    subsurfaceorange.png
    subsurfaceorange1.png