Search Unity

Horizon Based Ambient Occlusion - HBAO image effect

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

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
    Hi there,

    This asset doesn't seem to work with dynamic resolution or forced resolution scale in HDRP.

    a31fa0899e8db8ae7017cacca9f6766e.png

    When using a HBAO on such a project, it will appear as if the camera zooms in.

    I hope this can be looked into at some point.

    All the best.
     
  2. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Hi,
    I'm sorry for the inconvenience, this is a known bug.
    https://issuetracker.unity3d.com/is...sion-when-both-at-active-drs-plus-custom-pass

    We are awaiting fix, with the hope it will happen soon.
     
    SunnySunshine likes this.
  3. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    977
  4. Sarahsauce

    Sarahsauce

    Joined:
    Sep 5, 2021
    Posts:
    5
    I have a question before I buy anything. I've been using Cinemachine post processing Ambient Occlusion but when I turn up the setting there is a lot of noise / grainy / flickering behavior in the grass that I use. I wonder if this would be something that would be improved using this asset?
     
  5. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Hi @jimmikaelkael
    Unity 2020.3.19f1, Built-in pipeline.
    HBAO with MSAA enabled creates a one-pixel wide outline around opaque objects when a transparent object is rendered behind.

    Here is the example
    upload_2022-6-25_12-17-31.png
    Behind objects there is a transparent "cylinder" that creates the effect of height fog.

    When either MSAA or HBAO is disabled then there is no such outline.
    Is it a known issue?
     
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    No, it was not known issue.
    I'm sending you by PM a package that should fix it, but I prefer you to try it before to make this a release.
     
  7. Rastapastor

    Rastapastor

    Joined:
    Jan 12, 2013
    Posts:
    589
    I get the following error when going into play mode on HDRP in 2022.1 (I know its tech release, so something to plan ahead :) )

    Code (CSharp):
    1. RTHandle.Initialize should only be called once before allocating any Render Texture. This may be caused by an unreleased RTHandle resource.
    2. Unreleased RTHandles:
    3.     HBAO_AO
    4.     HBAO_Temp
    5.     HBAO_Temp2
    6.  
    7. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
     
  8. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    No luck getting it running in HDRP 14.03 - Unity 2022.2.0b1.
    Also all properties in inspector are doubled.
     
  9. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Doubled properties was just a problem with inspector and had no impact on functionality. This is fixed with newest HBAO v3.4.12.
    Tried 2022.2.0b3, HDRP 14.0.3 and no such issue.
     
  10. Vhalen

    Vhalen

    Joined:
    Oct 27, 2016
    Posts:
    9
    Hello,
    I am sorry to ask for help but I really tried my best all night to solve this issue without result.
    I am trying to build my project, in the editor everything is fine but in build the render appears more yellowish and the shadows much more darker. I am using Unity URP 2021.3.7f1.

    upload_2022-8-2_0-3-49.png

    I have the same result starting from a clean project, it seems to disappear when the SSAO and HBAO are actives at the same time but I obtain some kind of double SSAO even when putting a very low intensity.
    I didn't see this problem as a known issue, it only appears when the post process is turned on and the Debug Mode seems all right in build.

    The mode "Lit AO" seems to worked properly, I switched on this mode for now.

    upload_2022-8-2_0-11-12.png

    Thank you for this amazing asset.
     
    Last edited: Aug 1, 2022
    SunnySunshine likes this.
  11. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm sorry for the inconvenience, most likely it's URP shader stripping issue that is known already.
    As a workaround, best option is to create a 2nd Universal Renderer Data (Create->Rendering->URP Universal Renderer menu) then add builtin SSAO renderer feature to it:


    Then you add this renderer to your pipeline asset renderers list, but you keep yours as the default:


    This will prevent URP to strip SSAO functionalities from shaders in build, without to have to pay the runtime cost of builtin SSAO.

    About LitAO mode: this should be the preferred mode for URP>=10. If you want to have normal look with litAO mode you can raise direct lighting strength setting that appears to 1 but will be less realistic.
     
  12. Vhalen

    Vhalen

    Joined:
    Oct 27, 2016
    Posts:
    9
    Thank you a lot for your quick help and the precision about LitAO ! This asset is really a must have !

    Have a good day
     
    jimmikaelkael likes this.
  13. Liminal-Ridges

    Liminal-Ridges

    Joined:
    Oct 21, 2015
    Posts:
    256
    This is probably asked but is the transparent terrain bug fixed? (Legacy RP)
     
  14. seok-in-yoon

    seok-in-yoon

    Joined:
    Feb 11, 2016
    Posts:
    20
    When using HBAO in HDRP Forward, MSAA support is not available.Is there a solution?
     
  15. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    177
    I don't see anything happening, unity 2021.3.6f1

    upload_2022-9-15_19-13-50.png
    upload_2022-9-15_19-14-1.png
    upload_2022-9-15_19-14-24.png
     
  16. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Nope, I'm sorry to say that but concerning this I think Unity will never fix in builtin RP. The issue is that _CameraNormalsTexture Unity is providing to shaders is incorrect in this case. The workaround is to use "Reconstruct" as Per Pixel Normals setting in HBAO.

    No solution yet, It's a bug in HDRP with custom post processes, the source texture HDRP is passing to Render() method that custom PP are overriiding is 1x1 gray pixel... Nothing I can do to workaround it, I'm really sorry.

    You are not using the effect correctly. On URP the effect should not be placed on the camera, please check documentation for proper use on URP.
     
    Liminal-Ridges likes this.
  17. jmgek

    jmgek

    Joined:
    Dec 9, 2012
    Posts:
    177
    Thank you, got it working.

    On final question, do you offer an API to change presets at runtime?
     
  18. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Yes, on URP basically you get a reference to your VolumeProfile then you access HBAO component:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Rendering;
    4. using HorizonBasedAmbientOcclusion.Universal;
    5.  
    6. public class NewBehaviourScript : MonoBehaviour
    7. {
    8.     public VolumeProfile postProcessProfile;
    9.  
    10.     void Start()
    11.     {
    12.         HBAO hbao;
    13.         postProcessProfile.TryGet(out hbao);
    14.         if (hbao != null)
    15.         {
    16.             hbao.EnableHBAO(enabled);
    17.             hbao.SetAoIntensity(4);
    18.             hbao.SetAoRadius(2);
    19.         }
    20.     }
    21. }
    22.  
    Be careful to use HorizonBasedAmbientOcclusion.Universal namespace and not just HorizonBasedAmbientOcclusion.
     
    jmgek likes this.
  19. Hjeldnes

    Hjeldnes

    Joined:
    Jul 22, 2012
    Posts:
    116
    Hi, I got an error when testing this addon. It requires the XR package to be imported. Is there something I can do to avoid this? I have no need for VR in the project, so if I can avoid importing a package I don't use then that would be great.

    Thanks!
     
  20. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Sorry for the inconvenience, I will fix in next release. In the meantime I just sent you an email with fixed script.
     
    Hjeldnes likes this.
  21. Hypertectonic

    Hypertectonic

    Joined:
    Dec 16, 2016
    Posts:
    75
    Just in case anyone is struggling with getting the VolumeProfile to show up, you need to reference the Unity.RenderPipelines.Core.Runtime assembly.

    BTW you can also do the variable declaration, getting, and null check in a single line like this
    if (postProcessProfile.TryGet(out HBAO hbao))
    because TryGet already returns a bool.
     
  22. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I bought this asset over 6 years ago, and I am VERY GLAD this is working with HDRP. Just reinstalled it for the first time in a long time, and I am glad to be replacing the HDRP SSAO with this, especially since all of my model details are further accentuated and it's per pixel (correct me if I am wrong)
    upload_2022-10-10_19-36-57.png

    upload_2022-10-10_19-34-21.png
     
    DragonmoN likes this.
  23. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    135
    So issue which I would like to fully understand. Getting this on our characters. We do have a custom shader so looking for advice on how to avoid this. It gets slightly better if I switch from G Buffer to Camera (or Reconstruct) OR pipeline stage to after lighting or before reflections.

    *UPDATE* Interesting when I switch to debug mode (view normals) the character completely disappears.

    Shader on the character is setup as a custom surface shader.

    #pragma surface surf Custom fullforwardshadows

    upload_2022-10-28_10-37-55.png

    (after or camera etc its less but you can still see it.)

    upload_2022-10-28_10-41-42.png
     

    Attached Files:

    Last edited: Oct 28, 2022
  24. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Shader not writing to depth it seems. Is it ZWrite Off or also maybe because you have no Fallback instruction to standard shader...
     
  25. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    135
    I trimmed this down to the bare min to see if it still did it so I could pass on something that can repro the issue.

    Digging into writing to the depth. There is no issue with transparent, fade out objects etc is there? Thank.
     

    Attached Files:

    Last edited: Oct 28, 2022
  26. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Your shader is incorrect, this is an improper way to define your custom lighting model (https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html) and the value you write to surface normals is wrong.
     
  27. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    135
    Thanks will dig deeper.
     
  28. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    You need to have your object treated as opaque. If it's transparent or fadeout, ao will pass through it and this is expected.
     
  29. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    144
    Hi! Great asset. But I'm having this annoying bug where I constantly have this weird material icon appearing in my scene viewport bottom corner if I have any mesh renderer selected and there's HBAO active in my scene.
    This is only in editor but still very annoying. Also, it covers entire viewport if dynamic resolution is enabled. The Gif is with dynamic res disabled.
    2021.2.11, HDRP



    Edit: also, both scene view and game view constantly get covered by a buggy white filter until I toggle HBAO off and on.
    upload_2022-11-4_19-28-41.png
     
    Last edited: Nov 4, 2022
    Howard-Day likes this.
  30. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    144
    I've updated to 2021.3.12 and it's only getting worse. This artifact is happening every time I start / stop play mode. And I need to toggle HBAO off and on every time. Can you maybe suggest a workaround?
    @jimmikaelkael
    upload_2022-11-8_4-15-47.png
     
  31. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm sorry for the inconvenience, I will investigate this issue.
     
    Howard-Day and Genebris like this.
  32. Avol

    Avol

    Joined:
    May 27, 2016
    Posts:
    95
    In HDRP water absorption distance stops working. Only 0 value changes the absorption. Can this be solved in any way?
    I also modified the rendergraph to render HBAO before the fog like this:
    upload_2022-11-10_11-4-4.png
     
  33. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I was unable to reproduce the issues. Could you please send a repro project with resources stripped ?
     
  34. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm sorry but currently HDRP has limitations... They will change RenderGraph api to allow access to ao buffers, not sure when this will happen, but when it will be the case HBAO for HDRP will be rewritten to use it which will result in working properly with scattering.
     
    Avol likes this.
  35. Genebris

    Genebris

    Joined:
    Mar 18, 2013
    Posts:
    144
    I think I found it. Both issues appear only if you choose second or third post processing buffer format in HDRP asset. Default R11G11B10 is fine, other two cause these bugs.
    You can see it yourself in a brand new HDRP project. Also, the buggy white overlay appears in build as well.

    I don't know why I even had it at second option, I'll just stick to the first 32 bit format.

    upload_2022-11-14_3-59-50.png
     
  36. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I see. Please do a quick test, open HBAO hdrp shader file (path is "Assets/Horizon Based Ambient Occlusion/SRP/HDRP/Shaders/HBAO.shader") and comment line number 315 (RGB colormask in composite pass).
    It should fix the issue, just let me know.
     
  37. kentaroid

    kentaroid

    Joined:
    Feb 10, 2014
    Posts:
    1

    Hello,
    Let me report that I was able to get HBAO working with single pass instanced of the builtin pipeline.
    Most of the SPI support is already done by you, I just made a few tweaks.

    By setting the argument depthSlice of CommandBuffer.SetRenderTarget to -1, DrawMesh to Tex2DArray works fine. Mentioned in the forum below.

    https://forum.unity.com/threads/com...enders-only-to-left-eye.1026310/#post-6749524

    I have attached all DIFFs that I made SPI compatible with as images.

    spi fix diff.png

    Thanks,
     
    jimmikaelkael likes this.
  38. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Yeah I know, but this is only a small part of the solution. Doing this you'll currently get AO mismatch between both eyes, inconsistency between VR ao and non VR ao, and temporal filter will be broken.

    However thank you so much for the effort, I appreciate it!

    I'm currently fixing issues with URP & HDRP SPI support, then once done I'll get back to investigate on Builtin pipeline case.
     
    kentaroid likes this.
  39. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    v3.5 has been published with this changelog:
    • Standard pipeline: added VR SPI support
    • Standard pipeline: fix compile error when built-in VR module is disabled
    • Reduced number of shader variants (all pipelines)
    • URP/HDRP: fixed VR SPI projection issue
    • HDRP: fixed issue with R16G16B16A16 and R32G32B32A32 buffer formats
    Please note minimal Unity version is now 2020.3, minimal SRP version is 10.3.2.
     
    Genebris likes this.
  40. DeadPoet

    DeadPoet

    Joined:
    Jan 7, 2013
    Posts:
    37
    HBAO seems to ignore the fog in the scenes for me in HDRP 2021.3.11. I have some very foggy weather and the AO effect is always extremly strong through the fog.
     
  41. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    pwka likes this.
  42. EricWilliams

    EricWilliams

    Joined:
    Jun 23, 2017
    Posts:
    40
    Doesn't seem to work for hdrp on a fresh 3d (hdrp) core project in Unity 2022.1.23. In the hdrp demo scene for hbao the check boxes and sliders have no affect.

    I haven't tried 2022.2.xx, yet.
     
  43. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Works fine here, please take a look at documentation.
    Most probably you forgot to add the effect to proper injection point in custom post processes (HDRP Global settings).
     
  44. EricWilliams

    EricWilliams

    Joined:
    Jun 23, 2017
    Posts:
    40
    I apologize, I read the usage section in the readme files thinking they were documentation.
     
  45. burrpuzzle

    burrpuzzle

    Joined:
    Dec 21, 2015
    Posts:
    4
    Hi there! Sorry if it's been asked but since supported platforms change with time and updates: does HBAO support mobile Quest 2 VR on multiview? In my case, I'm using Standard Pipeline (built in), 2021.3 on Vulkan. Also, how is the support generally on other mobile devices? Thank you
     
  46. CRG-Hans

    CRG-Hans

    Joined:
    May 9, 2022
    Posts:
    11
    Just added this asset to our project, looks awesome. Love how configurable it is. BUT, we're not getting this to work in stand alone builds. Works perfect in the editor though. Unsure if its something with our rendering configuration. We're rendering the game world using a deferred renderer, and the UI with the normal forward renderer (as overlay cameras)
    upload_2022-12-30_14-12-52.png

    upload_2022-12-30_14-17-50.png

    The HBAO render feature has been added to the DeferredRenderer configuration. For extra precaution, we've also added the URP/HBAO shader to the list of always included shaders.

    Running Unity 2021.3.9f1, URP 12.1.7

    Any guidance how to get it working would be appreciated.
     
  47. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Please check this post above:
    https://forum.unity.com/threads/hor...hbao-image-effect.387374/page-22#post-8333814
     
  48. CRG-Hans

    CRG-Hans

    Joined:
    May 9, 2022
    Posts:
    11
  49. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I cannot reproduce despite I tried with the same version and with a setup similar to yours...
    You should not have to add HBAO shader to always included shaders list because the renderer feature has a serialized field for the shader.
    Have you tried to build HBAO URP demo scene and just check build report?
    In player log is there a log that mentions 'HBAO shader was not found'?
     
  50. CRG-Hans

    CRG-Hans

    Joined:
    May 9, 2022
    Posts:
    11
    I added it to the always include just as a safe guard. No issues in the log about not finding the shader etc.
    Just to make sure its actually active, I've done some debug commands, and sure enough the HBAO feature is enabled and present in my global volume profile. I can see it generating a couple of temporary textures using RenderDoc to debug the rendering. It happens between the color pass and light pass for the deferred renderer. The 4 draw calls procude 3 blue/cyan textures and one classic B/W AO texture. upload_2023-1-2_10-58-19.png

    However, none of the resulting temporary textures produced by the HBAO shader is used anywhere.

    Results after color, light+particles, URP "FinalPost" call:
    upload_2023-1-2_11-6-28.png

    EDIT: Managed to get it working by adding the default SSAO to my deferred renderer (instead of the dummy workaround) and disabling it during runtime when entering the game. There is still some difference, its almost as if the intensity value need to be about twice in order to look the same as in the editor.
     
    Last edited: Jan 2, 2023