Search Unity

Horizon Based Ambient Occlusion - HBAO image effect

Discussion in 'Assets and Asset Store' started by jimmikaelkael, Feb 21, 2016.

  1. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    That's great to hear! Until then, rz_0lento's suggested changes worked. HBAO is now rendering!
     
  2. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    Just to clarify how to make HBAO work in urp 12:

    1.) Comment out line 34 from Assets\Horizon Based Ambient Occlusion\SRP\URP\Editor\HBAOEditor.cs that contains
    hasAdvancedMode
    override.

    2.) On line 375 from Assets\Horizon Based Ambient Occlusion\SRP\URP\Runtime\HBAORendererFeature.cs
    Replace this:
    Code (CSharp):
    1. source = new RenderTargetIdentifier("_CameraColorTexture"); // <----Original
    With this:
    Code (CSharp):
    1. source = renderingData.cameraData.renderer.cameraColorTarget;
    3. At this point, HBAO will render, but it won't render correctly. In the HBAO override for the Post Process Volume, make sure to change the Per-Pixel Normals option to one of the Construct variants.

    Thank you again rz_0lento for pointing me in the right direction!
     
  3. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    As extra note, those Per-Pixel Normals from Camera didn't really work proper on URP 10 either, have to use reconstruct versions. In addition if now using URP 12 deferred they have extra option on URP Renderer Data asset called "Accurate G-buffer normals" which now totally break HBAO if it is still getting normals from camera :) Reconstruct -variants work fine still.
     
  4. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Would be nice if this option was in URP too now that it has deferred mode (URP 12+).
     
    jimmikaelkael likes this.
  5. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    This method was strongly tied to how standard render pipeline worked.

    For SRP I'm expecting Unity to allow access to a global ambient occlusion texture so that we can write ourselves in it instead of the builtin AO (this should be done at early stage, before opaque, so we need the correct injection points in the pipelines). Then like it is actually done in HDRP the materials can access the occlusion term.
    The benefits are that it is a lit AO and it can also be disabled per material.

    EDIT: please also take a look at this thread https://forum.unity.com/threads/mis...nt-in-hd-render-pipeline.979803/#post-7376441
    HDRP does not currently have before opaque injection point, nor before atmospheric scattering
     
    Last edited: Aug 20, 2021
    rz_0lento likes this.
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    This is now available on URP10+ in HBAO v3.4. There's a new field at the top of general settings which allow for LitAO mode.
     
    rz_0lento likes this.
  7. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,266
    Nice work! SSAO is now dead to me :D
     
  8. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Hell can you please talk more on what is the LITAO and should I use it over the normal HBAO you have? Does it look better, does it cost the same, what other benefits?
     
  9. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    With this mode the AO is applied to lighting at material level. It is more physically correct and won't cost more perfs. Another benefit is that you can exlude AO in your custom shaders.

    To support AO in your custom shaders, this is done the exact same way as for Unity's SSAO, please refer to this page:
    https://docs.unity3d.com/Packages/c...iversal@10.2/manual/upgrade-guide-10-0-x.html

    EDIT: it seems there's a missing bit of information in the doc about the required passes in your custom shaders; The Depth pass is required in any case and the DepthNormal pass is required only if you intend to use per pixel normals "Camera".
     
    SilverStorm likes this.
  10. OMGOMGXAXA

    OMGOMGXAXA

    Joined:
    Apr 2, 2016
    Posts:
    10
    I have the same error in HDRP (unity 2021.2.0b8) :
    Assets\Horizon Based Ambient Occlusion\SRP\URP\Editor\HBAOEditor.cs
    that contains "hasAdvancedMode override" not working.

    How to fix this in HDRP pipeline? :)
     
  11. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    In Unity 2021.2.0b10 I think at certain camera angles the results is backwards with camera normals?

    upload_2021-9-7_21-13-38.png

    upload_2021-9-7_21-13-51.png

    Compared to reconstruct
    upload_2021-9-7_21-15-49.png

    looks fine at this angle
    upload_2021-9-7_21-14-29.png
    upload_2021-9-7_21-14-42.png

    Compared to reconstruct it looks the same

    No idea whats happening :O

    This is in forward mode
     
  12. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
  13. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Camera view normals on URP were added not so long ago. I added the option for the future but it is not reliable actually (I have let reconstruct mode as the default option). It's what unity outputs... And generally I do not support betas: I can not even launch the version you mentionned without it crashing instantly on my system.

    I'm really sorry for the inconvenience.
     
  14. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    Ah fair enough, hopefully it comes out of beta soon XD

    The new features in URP 12 are simply too good to pass up for me so I figured I'd just jump on it.

    Reconstruction works fine for now so I'll just do that. I hope you get 2021.2 to work soon!
     
  15. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    I'm having issues with URP in 2020.3.3f1. I created a new project, installed URP 10.5.1, installed the current version of HBAO, created a new URP pipeline asset, added HBAO to the Renderer features, and enabled the depth texture but it doesn't work in the demo scene. Did I miss anything?

    If I remove the pipeline asset from the graphics setting (basically going back to built in), it works but as soon as I assign the pipeline asset to the SRP field, it stops. The scene renders fine, it's just like the asset is not doing anything. I do have Post Processing checked on the scene camera.
     
  16. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    @reggie_sgs Make sure you apply the HBAO to the right URP data asset (the one in use atm).
     
  17. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    Yes, it's a new project and there's only one so that's not it.
     
  18. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I tried on these specific versions and had no issue.

    - you did not mention you unpacked HBAO's embedded URP package, so I hope you're not adding Unity's builtin SSAO renderer feature
    - please consider that the demo scenes for URP and Standard pipeline are not the same, you seem to be looking into the same demo scene when you switch the pipeline: it doesn't work like that
    - try removing renderer feature, removing HBAO package and reinstall
     
  19. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Just to make sure, can you add SSAO renderer feature to the same URP data asset you've put HBAO and see if the SSAO applies? If you can't see that one either, it's probably still the wrong asset. Also if it's the right asset, make sure HBAO is actually enabled by upping the intensity above 0 (or whatever naming convention it uses for this).
     
  20. reggie_sgs

    reggie_sgs

    Joined:
    Jun 29, 2014
    Posts:
    276
    Thanks, I didn't realize the SRP package added a different demo scene, I just missed that. After switching to the correct demo scene, I was able to get it to work. Thanks!
     
  21. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hi, I am using HDRP13 with HBAO and all works very good (Good job!). But is there a way to render AO before Fog? The old method doesn't seem to be working (I can't find the lines anymore).

    Also, I hear that they added injection points for custom postprocess.
    https://docs.unity3d.com/Packages/c...13.0/manual/Custom-Pass-Injection-Points.html

    Is this relevant for HBAO and if so, how do I use it to render HBAO before fog? Thanks!
     
  22. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hey another thing, in HDRP13, (I am not sure if it also happens in HDRP12) but with DLSS on, optimal settings turned off for DLSS, and Dynamic res set down to below 1, the screen renders wrong.

    https://forum.unity.com/threads/dls...l-settings-is-unchecked.1179922/#post-7559440

    Check this thread out that I posted, I initially thought it was HDRP, but it looks like it is HBAO +HDRP13.
    Would really appreciate it if you can provide a workaround, or update to the code.

    Thanks!
     
  23. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Hi, sadly I can not run recent unity editor versions on my computer, it crashes instantly. And honestly, I generally never support betas because it is too much broken.

    Yeah, the document you are showing are the available injection points. I know them all and if you look closely there's no custom post process injection point available just before fog, I'm so sorry for the inconvenience.

    Thank you very much for the feedback! Now I know that HBAO doesn't actually get proper render size for DLSS, but, as stated above I have no ETA for a fix.
     
  24. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    NP mate, honestly you have one of the best support for your product so I am not worried about this getting fixed in the future. Just wanted to relay the message so that you are aware.

    Also, it breaks in HDRP12 with DLSS, so, so far all available versions of DLSS + HBAO is broken at the moment.
    I am guessing this is related to the newly introduced upscaled TAA but I haven't looked into the code so your guess is as good as mine :)

    Cheers!
     
  25. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    I understand it is probably not ideal for mobile but I do have a question regaurding this package. I have the same application running on a few Android devices and a few iOS devices. I get about 18fps on Android but getting 60 fps on iOS with it. Just curious what the difference is or does SSAO on Android just suck compared to iOS?
     
  26. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm not used to mobile but let me guess.
    Behind the platforms you mentionned there is hardware and SSAO computation heavily rely on GPU. Old graphics benchmarks https://www.anandtech.com/show/10685/the-iphone-7-and-iphone-7-plus-review/4
     
  27. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    I'm getting an issue where my transparents appear on top of everything. Note I am using Unity 2020.1 / URP 8. Depth texture generation is enabled.

     
    Last edited: Oct 29, 2021
  28. tomtong

    tomtong

    Joined:
    Aug 5, 2013
    Posts:
    17
    Hello. Would I select specific objects or layers to be ignored for the filter Thank you for any reply.
     
  29. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Hello Jimmi

    Thank you for this plugin. I am trying to optimize a urp project and I'm wondering if hbao can use the build in opaque texture (in the render pipeline asset) or if it always will use blit (which seems very costly in my case ~8ms on high setting). I'm not a graphics programmer, so I may misunderstand how this works.
     
  30. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    upload_2021-11-2_11-43-29.png

    Just to clarify - this is what I'm seeing when GPU profiling a release build.
     
  31. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    No it's not possible I'm sorry.

    No using opaque texture won't help, and it's not meany to be used for that.
    The effect is fully scalable, it seems you are on URP. Run Medium or Low quality, with a small radius (max 1), low MaxRadiusPixels (64 for example) and avoid large blur radius.
     
  32. benjamin_flashbulb

    benjamin_flashbulb

    Joined:
    Aug 4, 2020
    Posts:
    25
    Thank you for responding and the advise.
     
  33. unity_DE629D8000C95784981A

    unity_DE629D8000C95784981A

    Joined:
    Aug 22, 2021
    Posts:
    1
    i have intall HBAO as the document guide me, but it still not working, already try on 2 version 2019 and 2021, on both URP and HDRP (i cant even put it in the render feature in URP), can anyone please help me :(
    thank you guy so much
     
  34. jacknero

    jacknero

    Joined:
    Aug 15, 2018
    Posts:
    60
    Hi there. I've noticed the addition of the "Lit AO" mode for URP in the latest update.
    I've tried it and found it provides a quite new-look style with a little more conserved but with more fidelity visual effect.
    It works fine in the editor but didn't appear as expected in the build. I set an option to switch the "traditional" dramatic style and the new "realistic" style. The former one can be properly displayed in the build.
    Does it need some specific tweak?
     
  35. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Hi, sorry for the inconvenience... it's because of shader stripping.
    I was reported the issue by @rz_0lento along with the reason why. He was able to bring Unity attention on that, please check this post and the following for a workaround:
    https://forum.unity.com/threads/shader-stripping-improvements-in-urp.1193215/#post-7631371
     
    jacknero likes this.
  36. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    @jacknero Like the staff reply on that linked thread suggested, you can create additional URP Renderer Data asset where you enable URP's own SSAO Renderer Feature and add that to your main URP asset's renderer list, just make sure you don't set it to default or enable it via script otherwise. This way the shader stripper will not take away the AO blending part of the URP shaders.

    Another way is to make a local copy of the URP package and place it into your projects Packages folder etc and change this line: https://github.com/Unity-Technologi...s.universal/Editor/ShaderPreprocessor.cs#L971 to
    Code (CSharp):
    1. hasScreenSpaceOcclusion = true;
     
    jacknero and jimmikaelkael like this.
  37. jacknero

    jacknero

    Joined:
    Aug 15, 2018
    Posts:
    60
    Thank you!It works fine now.
     
    rz_0lento and jimmikaelkael like this.
  38. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Can we expect support for Motion Vector soon? It is in 2021.2 URP already, thanks! Also Lit AO in URP in 2021.2 turns the entire screen super dark.
     
  39. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Sure, it's available in newly published HBAO v3.4.2.
    I haven't noticed any problem with LitAO, if it's in build it might be related to shader stripping, then please read just a few posts above.
     
    rz_0lento likes this.
  40. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I haven't noticed darkness issue for LitAO specifically either. But what can cause unnatural dark images itself is if you use the default "from camera" option for the normals, you have to change that so HBAO reconstructs normals itself:
    I don't think the reconstruct option is the default.. that is unless the latest HBAO release changed that? I always had to swap that again after changing to a new HBAO preset.
     
    jimmikaelkael likes this.
  41. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Good catch, I will check that.
     
  42. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    @iceb_ @sacb0y the normals/darkening issue is fixed in HBAO v3.4.4.
    I apologize, problem was that I assumed it was view space normals but I was wrong.
     
  43. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    It has nothing to do with builds, because it is happening in the editor. When using Lit AO, it seems to not be taking in the original image on screen at all. I've also tried removing all other post processing, and even including basic shader as part of the test in this image.

    Here it is using debug mode, split with AO and AO Only: Using Normal mode.
    upload_2021-11-24_11-17-35.png

    And here I will switch to using Lit AO:

    upload_2021-11-24_11-17-53.png

    I've also tried using a new forward renderer, readding HBAO into a new PP profile etc, all preset settings. Even tried a complete new install of HBAO after wiping it, and tried it inside and outside of /plugins directory.
     
    Last edited: Nov 24, 2021
  44. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Also when I move my mouse around with middle click, which I assume plays effects, (created a new camera) in editor while out of play mode, it has these weird artifacts.

    not clicking with mouse:
    upload_2021-11-24_11-31-8.png


    middle mouse button clicking

    upload_2021-11-24_11-30-50.png
     
  45. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I don't see anything wrong, I'm sorry. Please update to the latest, it has been updated.
    You can't get proper snapshot of what LitAO truly is as it runs through lighting, but the darkening issue you had with should be gone.
     
  46. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    I am using the latest version that I downloaded just now, and the problem still persists unfortunately
     
  47. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Ok, I'm sorry for the inconvenience, please keep on using normal mode until it's fixed.
     
  48. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    oh found what fixes/breaks it. If I turn on Opaque Texture in the pipeline asset, then it breaks it.
    Actually that fixed it in a demo scene, but not in my complex scene...strange.
     
  49. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Thanks for feedback, I will try to reproduce and investigate.
     
  50. iceb_

    iceb_

    Joined:
    Nov 10, 2015
    Posts:
    95
    Found it, if I disable MSAA in the Pipeline asset, it breaks it.