Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Horizon Based Ambient Occlusion - HBAO image effect

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

  1. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    507
    Yes it's normal.But now after changing setup a bit it looks better now :)
     
  2. wahntin

    wahntin

    Joined:
    Sep 17, 2019
    Posts:
    83
    Hi, we are currently adding this to our game Imagine Earth using the latest URP. Looks great so far!

    Just one question: How can I access the HBAO renderer settings from script to enable/disable it from within the game?
     
  3. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Glad you like it, upcoming v3.0 will be even better, lots of bugfixes and improvements!

    To toggle HBAO from script, you need a reference to the settings file being used, for example you can do:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class HBAOSettingsManager : MonoBehaviour
    5. {
    6.     public HBAORendererSettings hbaoSettings;
    7.  
    8.     void Update()
    9.     {
    10.         if (Input.GetButtonDown("Fire1"))
    11.             ToggleHBAO();
    12.     }
    13.  
    14.     public void ToggleHBAO()
    15.     {
    16.         if (hbaoSettings != null)
    17.         {
    18.             var generalSettings = hbaoSettings.general;
    19.             generalSettings.enable = !generalSettings.enable;
    20.             hbaoSettings.general = generalSettings;
    21.         }
    22.     }
    23. }
    24.  
    EDIT: I will add a few helper methods to the HBAORendererSettings class in v3.0
     
    Last edited: Mar 22, 2020
    wahntin likes this.
  4. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Hi there, v3.0 has been submitted for review:
    • Rewritten scripts/shaders code for Unity 2019.1+
    • Added scene view effect
    • Added temporal filtering
    • Added interleaved gradient and spatial distribution noises
    • Added possibility to stack AO components (both Standard and Universal Render Pipeline)
    • Added UI for Universal Render Pipeline AO setting assets
    • Fixed wrong RenderTextureFormat for color bleeding
    • Fixed memory leaks
    • Improved number of compiled shader variants

    Please note that due to the fact that package installer does not keep track on deleted files or folder structures, you will need to delete older HBAO package content from your project before importing it.
     
    transat likes this.
  5. mbancewicz

    mbancewicz

    Joined:
    Feb 1, 2017
    Posts:
    4
    Hi there,

    the issue regarding VR + URP was already reported. Is there a new ETA on this fix? I noticed that new version introduced some changes. Previosly nothing was rendered for right eye (black screen). Now, the left eye is rendered correctly with HBAO, but AO on the right eye is shifted to the left side.
     
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    I haven't yet looked at fixing it, but the code rewrite was motivated too by VR problems. Let's say on June we should get VR support.
     
  7. SufferinPup

    SufferinPup

    Joined:
    Jul 7, 2012
    Posts:
    24
    We're using 2019.3's camera stacking feature with the URP, and the 2nd camera seems to render after the AO. So not only does the 2nd camera not have AO, but the AO from the first camera renders on top of it. Is this a supported configuration? If so, is there additional configuration required to get it to work?
     
  8. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Thank you for report, this is something I will need to check.
     
  9. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I’ve been loving hbao in URP but v3 seems to have broken the effect in the latest 2020.1 beta. Now my game looks dull again! Help! :)
     
  10. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Works here, please make sure you deleted older package content before installing v3.0.

    Also, there's currently an issue in URP 8.0.1 that still exist in unreleased 9.0.0-preview, the problem is that an intermediate color texture is no longer created as it was the case with Universal Render Pipeline <8.0.1 when there was at least one renderer feature. The consequence is that the final blit pass does not happen wether it should.

    The method RequiresIntermediateColorTexture in ForwardRenderer.cs should return true if there's at least 1 renderer feature as it used to do before, or better, let a way for a ScriptableRendererFeature to notify that it requires intermediate color texture:
    https://github.com/Unity-Technologi...nes.universal/Runtime/ForwardRenderer.cs#L437

    In the meantime, a workaround if you have this problem is to tick Post Processing checkbox on the camera. I have filed a bug report with reproduce case project.
     
    Last edited: Apr 1, 2020
  11. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    320
    Was excited to see that with the update you can now see the effect in the scene view. I updated my project and it doesn't work because I'm using 2018.4 LTS, and HBAO now only supports 2019.1+

    I still have a backup of the old version that works, but is there some reason why the new version can't be compatible with 2018 LTS?
     
  12. Jglu

    Jglu

    Joined:
    May 14, 2019
    Posts:
    1
    I'm sorry if this has already been answered I'm getting an error when trying to use the demo scene in URP.

    Solid magenta screen (In Scene and Game window with HBAO enabled) with the error: Shader error in 'Hidden/Universal Render Pipeline/HBAO': failed to open source file: 'Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl' at Assets/Horizon Based Ambient Occlusion/SRP/URP/Shaders/HBAO_Common.hlsl(6) (on d3d11)

    Any help with this?
     
  13. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Yes, there was some good reasons to move on 2019, local shader keywords was one of them.

    I've made a 2018.4 LTS backport a few days ago, please check the store it is already available.
     
    Akshara likes this.
  14. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    It seems your URP setup has a problem, or you don't use the minimal supported version, not sure...
    Please check your pipeline setup and if you updated the asset recently try to delete and reimport it, then follow URP installation instructions from the documentation.
     
  15. Akshara

    Akshara

    Joined:
    Apr 9, 2014
    Posts:
    100
    Thank you for doing this and for all of your work and support with HBAO over the years.
     
    jimmikaelkael likes this.
  16. frostyone

    frostyone

    Joined:
    Aug 2, 2018
    Posts:
    8
    Is it possible to have AO only on specified shader/materials ? (and not on everything else)
     
  17. camta005

    camta005

    Joined:
    Dec 16, 2016
    Posts:
    320
    Excellent, I must have updated just before this came out. I've tested this version now and everything is working well and being able to see the effect in scene view is great.
     
    jimmikaelkael likes this.
  18. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO is a screen space image effect and so it is geometry agnostic. This is unfortunately impossible...

    EDIT: There are tricks to play with render queue in order to exclude objects from HBAO but I won't recommend doing this anymore.
     
  19. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    @jimmikaelkael I'm on 8.01 and do have postprocessing ticked on my camera. The effect actually suddenly came on at some point (not sure what I did) but now I can't change it through the render feature settings. So it's stuck on the default setting.
     
  20. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Have you tried to wipe older HBAO package content and reinstall ?
    Try to delete your custom HBAO settings files too if you have any.

    EDIT: Just tried once again on 2020.1.0.b3, Universal RP 8.0.1 and it works fine here.
    Which platform are you using ?
     
    Last edited: Apr 2, 2020
  21. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    779
    I'm now on 2020.1.0b4. Also 8.0.1 Twice tried uninstalling and reinstalling HBAO but still no luck. On a mac using Metal. Haven't tried in a new project yet.

    EDIT: Upon investigation this was likely due to some random bug or change in the 2020 beta. Now FIXED after messing around with the forward renderers.
     
    Last edited: Apr 4, 2020
  22. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO version 3.1 is pending review, here's the changelog:
    • Added HDRP support
    • Added more settings helper methods
    • Added namespaces for each render pipelines variants
    • Use 16bit floating point texture format for noise when platform supports it
    • Fixed wrong albedoMultipier setter method
     
  23. GridWanderer

    GridWanderer

    Joined:
    Dec 14, 2014
    Posts:
    12
    Sincerest condolences for your recent loss.

    Just had to stop by to say how impressive the new v3.0 release has been. Not only does this look far better on mobile than all the other AO packages we were experimenting with, but it has much faster performance despite this (Wow). We are very excited for the early URP + forward rendering support.

    Also, looking hugely forward to the upcoming VR support for the new SinglePass/MultiView rendering! (As we turn our attention to mobile VR as our next target platform, we've discovered that graphics quality on the Oculus Quest has been depressing to work with, without any (truly) viable AO options to date.)

    Thanks again for everything you are doing. Your work is an amazing benefit to Unity developers everywhere.

    Best Wishes
     
    Meltdown and jimmikaelkael like this.
  24. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    So, 3.1 has been published. Version 3.2 will pop out very soon.
    After investigating with the help of @transat on latest Unity beta and bleeding edge URP, some things will change in HBAO for Universal pipeline.
    The effect will be integrated as a Post Process, like it is in HDRP. It will make use of Volume component and overrides, so a few things will change in URP setup steps. Everything will be shown in the documentation.

    v3.2 will also fix an issue of whitish color bleeding problem after Max Distance, in all render pipelines.
     
    GridWanderer and camta005 like this.
  25. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    There is a HUGE memory leak:

    upload_2020-4-6_15-14-8.png

    I have been trying to find it for days and finally found the cause. Even when standing in an empty scene, not in playmode, material and objects increase by several every second. HBAO is the cause. Are you aware of this? Makes my entire project un-usable.
     
  26. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Of course...
    See the v3.0 changelog it is fixed already.

    Haven't you've been notified it was updated ?
     
    Last edited: Apr 6, 2020
  27. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I have the latest version and I still have this issue..

    I even deleted the entire asset and re-imported. But still there.
     
  28. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    You need to remove older render feature from your pipeline asset, then add it again

    After 10000 frames:
     
    mrCharli3 likes this.
  29. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO version 3.2 is currently pending review, changelog:
    • Fixed colorbleeding white color bleed beyond max distance
    • Switched HBAO for URP to Post Process VolumeComponent
    Note: please read documentation for new URP installation steps
     
    GridWanderer likes this.
  30. AlbertoMastretta

    AlbertoMastretta

    Joined:
    Jan 1, 2015
    Posts:
    71
    Hi!

    I just bought this asset, I'm very glad that there is a working version of post processing AO for URP. I was excited to get it running in my game, however I found a situation where it doesn't work, and I'm wondering if it is fixable at all.

    My game requires that players are visible behind objects, and I opted to use the silhouette technique which is very easy to implement with URP, as such:


    However, players are not rendered during the opaque pass, this makes it so players are not present in the depth texture, so AO doesnt contemplate them, and they get AO drawn on top of them form the objects behind them, while they don't get AO at all.

    Do you think there is a solution for this problem? Maybe forcing the "render objects" feature that unity made to write to the depth texture or the opaque texture?
     
  31. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Funny I have the exact same problem (using the same tutorial u linked above), didnt know it was caused by this AO though. My units are a tiny bit seethru when in-front of objects, and look a bit weird. Behind objects it works as intended.
     
  32. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    To be clear: this is not caused by this AO. This is other way round, this problem is caused by the render object feature which override depth for the characters.
     
  33. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    True, but they both work without each other. So the AO is just as much a reason as the render object feature. However I have solved it using a custom shader, so you can still get this effect while using HBAO :) So dont worry!

    Also, this AO looks way better than what you get from Unity's own, and support from the creator is great. I warmly recommend it!
     
    Last edited: Apr 7, 2020
    jimmikaelkael likes this.
  34. AlbertoMastretta

    AlbertoMastretta

    Joined:
    Jan 1, 2015
    Posts:
    71
    Exactly, this is a problem due to the render objects feature not writing properly to the necessary textures. Any hints on how to solve it? Maybe this needs to go on a forum for that feature itself.
     
  35. AlbertoMastretta

    AlbertoMastretta

    Joined:
    Jan 1, 2015
    Posts:
    71
    Ok, so I've found the problem, it is due to the depth pre-pass that is triggered when MSAA is enabled. If MSAA is disabled, the pre-pass is disabled with it, and then everything works!

    I'm so happy I can now use this effect!
     
    jimmikaelkael likes this.
  36. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Hello!
    Somehow I get strange anomalies when using URP and HBAO on iOS or Android, see screenshot.
    Any advise?
    In the editor all looks fine and I just use default URP shaders and simple one color skybox
    Also with the demo scene.

    Thank you!
     

    Attached Files:

    Last edited: Apr 14, 2020
  37. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Looks like depth precision issue, I will need to investigate.
    Could you please try to set blur to Disabled and see if the issue persists ?
     
  38. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Still the same
     
  39. GridWanderer

    GridWanderer

    Joined:
    Dec 14, 2014
    Posts:
    12
    Some scene depth banding also noticeable on Oculus Quest (Android, Snapdragon 835).

    Some related threads. It appears others may be encountering this as well:
    Posted recently:
    [1] https://forum.unity.com/threads/android-depth-texture-precision-issue.867232/
    [2] https://answers.unity.com/questions/1696763/no-scene-depth-in-mobile-build.html
    Old posts, but maybe insightful:
    [3] https://forum.unity.com/threads/depth-texture-not-working-on-some-devices.319568/
    [4] https://forum.unity.com/threads/problem-in-android.544213/

    [5] Do not know if this last one is helpful, but noticed several commented lines regarding shader quality being set to 'medium' on all mobile platforms besides GLES 2, seemingly as an internal Unity decision due to 'shader quality' setting being currently unexposed in scriptable render pipeline - but I do not know if shader quality is capable of affecting scene depth precision: https://webcache.googleusercontent....erLibrary/Core.hlsl+&cd=5&hl=en&ct=clnk&gl=us
     
    Last edited: Apr 14, 2020
    jimmikaelkael likes this.
  40. Claudia_Huai

    Claudia_Huai

    Joined:
    Mar 16, 2020
    Posts:
    3
    Sorry I am not familiar with HBAO.
    Did it have an effect on the animated and transparent objects,too?
     
  41. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Are you ticking "Depth Texture" in your render pipeline asset like mentionned in the documentation ?
     
  42. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Thank you very much for report, I will have a closer look to this.
     
    GridWanderer likes this.
  43. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO is a screen space image effect, like post process effect the occlusion is computed every frame, not baked. However transparent materials should never receive occlusion, and HBAO renders before transparent queue. Animated objects are supported provided they are not tranparent.
     
  44. EduardDraude

    EduardDraude

    Joined:
    Mar 8, 2019
    Posts:
    60
    Sure, alll is set up like in the docu, but I get these strange artifacts. On iOS the artifacts are not that big as on Android. See screenshot. Mostly noticable on flat surfaces like planes and such.
     

    Attached Files:

    Last edited: Apr 15, 2020
  45. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Yes, I have been able to reproduce it, I'm investigating.
     
    GridWanderer and EduardDraude like this.
  46. Claudia_Huai

    Claudia_Huai

    Joined:
    Mar 16, 2020
    Posts:
    3
    Thanks for explanation.
    I think this is definitely what I am looking for!
     
  47. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    Just wondering, what is the current issue with VR? Does it not work at all or only with specific settings/devices?
     
  48. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    I have redevelopped the project in v3.0 and I haven't tested it yet with VR. Most likely single pass instancing will have problems.
     
  49. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    GridWanderer and EduardDraude like this.
  50. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    I see so is that the issue that you mentioned would presumably be fixed around June or so?