Search Unity

Horizon Based Ambient Occlusion - HBAO image effect

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

  1. Calum

    Calum

    Joined:
    Mar 14, 2015
    Posts:
    45
    Hi, thanks for the reply. Yeah I have hbao added to my volume profiles but I don't see any effect, even with intensity at max.

    the settings I was referring to is how it appears in the renderer settings compared to the screenshot in the docs...
     

    Attached Files:

  2. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I haven't tried with your specific version but here works fine with 2020.3.0f1 and 2020.3.3f1 both URP 10.4.0.

    This is expected, changes were done in the builtin renderer feature editor since the screenshot...
    Capture.PNG
     
  3. Calum

    Calum

    Joined:
    Mar 14, 2015
    Posts:
    45
    My fault! I was adding hbao to the wrong renderer as I forgot Enviro (which is in my scene) has it's own renderer which is set to default, not the one created by Unity :rolleyes:
     
    jimmikaelkael likes this.
  4. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    We've been trying to figure out how to debug this to figure out where the issue is, but sort of lost so far. Any ideas?
     
  5. dancegunter

    dancegunter

    Joined:
    Apr 12, 2019
    Posts:
    2
    Hello good sir. HBAO rox and overall I'm a very happy customer, but I stumbled upon one tough issue with the Multi Bounce parameter and the way it works with specular lighting (in HDRP). When high intensity lighting hits smooth surfaces (metallics especially) there is this weird temporal burnout effect that envelops parts of a mesh (extreme case on the ss attached). In combination with bloom and other post-processes it can create a real hell of glitches :y Do you have any idea what could be the solution to this? I like how it works and I wouldn't want to give it up. Standard fixes in terms of specular reflections like specular AA etc. doesn't really work in this case. Thank you in advance :^)
     

    Attached Files:

  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    That's strange, could you please send me a small repro project on PM or on my support email?
     
  7. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Hi there, how do I access HBAO settings in HDRP?

    I tried the following, but seems like it is not working. Any guidance is much appreciated.
    Code (CSharp):
    1. HorizonBasedAmbientOcclusion.HBAO.AOSettings hbao = null;
    2.      mainVolume.TryGet<HorizonBasedAmbientOcclusion.HBAO>(out hbao);
    3. hbao.active = false;
     
  8. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    You were almost there, but I'd suggest to use HBAO helpers methods:
    Code (CSharp):
    1.  
    2. HBAO hbao;
    3. mainVolume.TryGet(out hbao);
    4.  
    5. if (hbao != null)
    6. {
    7.     hbao.EnableHBAO(true);
    8.     hbao.SetAoRadius(1f);
    9.     hbao.SetAoIntensity(1f);
    10.     // ...
    11. }
    12.  
     
  9. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Thanks for the quick help. Much appreciated.
     
  10. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174
    Hey! Any chance that it's some common issue with a quick fix? I have a big difference between AO in front of the sky and over the terrain. So I always see where the horizon border is. Using forward built-in rendering and enviro sky.




    Here is the better view in motion:
    https://gyazo.com/117e30fece79dae829caa4bf19144453

    (As I understand that's the issue of the forward rendering. Don't have this issue in deferred. Can I even use HBAO with forward?)
     
    Last edited: May 31, 2021
  11. alchemist_wurzelpurzel

    alchemist_wurzelpurzel

    Joined:
    Sep 4, 2018
    Posts:
    43
    Hi there!
    First of all thanks for your hard work on this asset, it's really great! We have run into a problem with our characters and HBAO and since I'm kind of a noob at shaders and rendering I'm not sure if it's fixable at all.

    We want our characters to have an outline that, as of right now, uses depth normals edge detection to work. The outline and HBAO work together when using lit shaders, but not when using unlit shaders on our characters. Now, after some investigation using the frame debugger I think it's because both use the DepthNormalsTexture and HBAO causes our characters to not be included in it anymore, probably because HBAO only applies to lit objects?

    Our outline uses a custom DepthNormals renderer feature, which is actually not needed when HBAO is turned on. Now I am wondering if it is at all possible to have our unlit characters still be included in the depth texture after HBAO is done doing its thing?

    Using Unity 2020.3.1f1, URP 10.3.2 and HBAO 3.3.1.

    Thank you for your work!
    Cheers
     
  12. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Hi, this issue is not new and is linked with how Unity internally generates view normals with semi transparent in forward... I'm sorry for this inconvenience but HBAO is not in fault.
    If you want to keep forward rendering you can change per pixel normals setting to "Reconstruct" in ao settings. This way HBAO will only rely on depth buffer.
     
    SammmZ likes this.
  13. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    That's something strange but there's no way HBAO can change DepthNormals texture... HBAO applies to both lit and unlit objects provided their shader write to depth buffer and they are before the transparent queue.
    HBAO uses both Depth and DepthNormals texture when per pixel normals mode is set to "Camera Normals", if set to Reconstruct it only require Depth texture. The depth provided in DepthNormals is too low resolution to be used to generate ao.
    Your character shader should have a DepthOnly pass as well as a DepthNormals pass.
     
  14. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174
    Great! Thanks for your assistance!
     
  15. mptp

    mptp

    Joined:
    May 30, 2014
    Posts:
    29
    Hi,

    I'm having some trouble getting this to work in a VR URP project in Unity 2020.1

    It doesn't work at all in Single Pass Instanced rendering (using OpenVR) - nothing but a black screen is rendered.

    In multi-pass, it does work, but the screen-space AO texture lags behind the rest of the scene by a lot. Like, when I turn my head, the AO image ghosts behind all the objects as they move across my field of vision like a dark afterimage.

    Is my configuration supported? Are there any places you can think I should check to see if I can fix the problem? Would appreciate any advice or support! :)

    edit: Single Pass Instanced has started not working in a slightly better way now...not quite sure why. In my left eye, the AO works perfectly. In my right eye, everything is super weird. It seems like the camera texture's projection into the HMD is all messed up, and the ambient occlusion doesn't line up with what is being displayed at all...
     
    Last edited: Jun 3, 2021
  16. krakentanz

    krakentanz

    Joined:
    Aug 13, 2020
    Posts:
    34
    hey mptp,

    what HMD are you targeting? I'm running into the same black screen issue (audio still works though) when making an Android build for the Quest 2.
    I'm wondering if it is currently possible to use HBAO with the Mobile-VR, as in my case it never worked in various configurations of HBAO.

    Unity 2021.1.7f1 | URP 11.0 | targeting Android API level 26 | Stereo Rendering Mode: Multiview
     
  17. mptp

    mptp

    Joined:
    May 30, 2014
    Posts:
    29
    I'm running on a Valve Index within OpenVR, targetting windows.

    Also an update - something I've noticed is that the HBAO isn't correctly projected in the HMD for detail objects on a terrain (i.e. grass). The HBAO seems to be getting rendered correctly, but again, it looks like it's happening at the wrong point in the SRP somewhere.
     
    Last edited: Jun 4, 2021
  18. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I'm sorry guys for the inconvenience, I was never able to test VR on URP because my headset is broken so I'm not surprised at all of the issues. I'm very busy since a few months but I'll try to acquire a new headset for summer holidays and try to sort ou these problems.
     
  19. mptp

    mptp

    Joined:
    May 30, 2014
    Posts:
    29
    I could have a go at fixing it myself if you don't have time / hardware right now, could you give me some pointers on where to look in the URP version to try getting it working?
     
  20. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    Hi, I've tried getting support via the stated support site (twitter) and no response. trying here now, :p

    I'm using URP in version 2021 and have made custom toon lighting shader using emissive channel while diffuse colour is black. I am finding unity standard AO won't render ao on emissive pixels, and HBAO doesn't seem to be doing much of anything, not sure what to check on, what to do.

    I put hbao on my main camera and it doesn't render anything. selecting debug view doesn't change what is displayed at all.

    Thanks for reading.

    (btw, I changed my review)
     
  21. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I see, that's really bad as I provide support only by email or here... I'll try to change it. I have to admit I did not understood your review, now it's clear.

    When creating custom shaders in URP, you need to implement DepthOnly and DepthNormals passes properly as like every SSAO solution, HBAO relies on depth and normal buffers to calculate ao.
    If you are using the shadergraph it is done automatically for you.

    Now about emissive: emission is some light, in HBAO it starts to cancel ao by tinting it with emissive color and as intensity increases, ao vanishes completely. This is expected behavior.

    Let me illustrate this, I quickly created an emissive material with shadergraph, with emissive intensity at 0.5:
    Capture.PNG

    With emissive intensity at 3.0:
    Capture2.PNG
     

    Attached Files:

  22. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    thanks, yes I am using shadergraph. since the current shadergraph automatically lights the diffuse output, I cannot customise it. my only option is to use the emission channel with my custom lighting calculation.

    can I access HBAO output using a custom function in my shadergraph?
     
  23. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    In the sample I've shown above, this is more or less the same the same: base color is black and the material color is plugged into Emission.

    HBAO is a screen space effect, calculated after all your opaque materials have rendered, you can't access it in shadergraph or at material level.
     
  24. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    oh sorry, I was not paying attention. the hbao is having an effect in the screenshot you have shown.
    so this is not an issue with emission. I guess I mainly mentioned it as it may have been an issue.

    I have put some objects in my scene with the standard shader. as you can see from my screenshot, HBAO is not rendering anything
     
  25. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    This is not the proper way to use HBAO in URP. Please refer to documentation and the dedicated demo in URP folder...
     
  26. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    I see. I initially bought this asset for a previous version of unity. I updated my project and there was no indication things were configured wrong now. I will check the documentation again. thank you.
    do you think it would be helpful to put some kind of warning or comment in the editor to let people know that the implementation needs to be changed?
     
  27. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Almost sure I cannot reference and detect URP from Standard pipeline without throwing an error, preventing hbao to run.
     
    tremault likes this.
  28. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    I understand. that is another shortsight by unity technologies then. they really do love to make life exciting for us don't they ^^ :D
     
  29. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    I can't tell from the store page description, but is there an option to use the depth normals texture generated by Unity, or to reconstruct it from the depth texture?

    Additionally, is there the option to copy the AO result into the screen-space AO texture (_SCREEN_SPACE_OCCLUSION shader keyword path, link). This is rather important for us to ensure AO is properly factoring into lighting, rather than multiplied over the final image. This is the main strength of Unity's SSAO, but I probably don't have to tell you that SSAO it's a poor option :p

    Any issues to expect when using MSAA?
     
  30. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    There might be an option by detecting render pipeline setting in graphics settings, I'll try that.
     
    tremault likes this.
  31. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Yes, HBAO provides Camera (DepthNormals) and recontructed normals option. This in all pipelines.

    There's no such option actually, Unity provided SSAO solution on URP after us so I was not aware about it. The texture name seems to be _AmbientOcclusionTexture, I'll explore this possibility later.
    On Standard pipeline, HBAO is factored into lighting when injecting at BeforeRelections stage and only available in deferred.

    In demo scene it works fine. Maybe others can confirm, for URP?
     
  32. tremault

    tremault

    Joined:
    Oct 16, 2015
    Posts:
    58
    I don't use MSAA yet, but I just switched it on in my scene and it was fine. I changed the render scale and the HBAO went dark for a bit but when i hit enter on the manual input it rectified itself. so I would say all good for me at least.
     
    StaggartCreations likes this.
  33. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,260
    Thanks for the reply! Currently not sure which depth normals method we'd use, but good to know there's the option.

    Integrating AO into URP's lighting pipeline would be epic, this project in specific uses a custom lighting model, so being able to interpret the AO information however we like will go a long way!
     
  34. Kretoskar

    Kretoskar

    Joined:
    Mar 15, 2019
    Posts:
    11
    Hi. I'm having problems after importing HBAO to a project with Enviro. Although the effect of HBAO is visible, it breaks the Enviro clouds rendering order. upload_2021-6-28_17-22-22.png

    I tried contacting the Enviro developer but I was sent to here.
    upload_2021-6-28_17-23-27.png
     

    Attached Files:

  35. Kretoskar

    Kretoskar

    Joined:
    Mar 15, 2019
    Posts:
    11
    Also, another reply from the enviro dev
    upload_2021-6-29_10-15-43.png
     
  36. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Hi, HBAO is not at fault here, I'm sorry...

    It is clearly a problem with the tree shaders. Sure, HBAO can use both Depth and DepthNormals texture but it is not a fault. If you are using deferred rendering I suggest you to use "GBuffer" as per pixel normals setting in HBAO, this will make it only use Depth texture.
     
  37. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    Any ETA on 21.1 and 21.2 integration? It seems like 21.1 works with a bit of kink here and there and also 21.2 works just fine except it throws a lot of error logs. It works just fine though.
     
  38. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I haven't noticed any problem on 2021.1. Anything specific on your side?

    For 2021.2 it's still beta so I won't do any changes to support it (if required) until it is released.
     
  39. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    when temporal option is turned on, game view gets a ghosting copy overlay of scene view.
     
  40. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    Ah yes, I can see the issue. But it is not related to Unity version but rather HDRP version, and already happens in HDRP 10.

    Sadly, this is a regression... They made changes so that motion vectors can support msaa, but with their current code any custom post process is unable to access the motion vectors texture:
    Capture.PNG
    The GetMotionVectorsBuffer() method is inacessible from outside.

    Nothing I can do for now, I'm sorry for this inconvenience.
     
  41. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,117
    So another case of Unity being Unity. Cool mate. Thanks!
     
  42. PGiza

    PGiza

    Joined:
    Jul 22, 2019
    Posts:
    4
    Changelog claims:
    2.4:
    Added support for Single Pass Stereo Rendering
    3.3:
    Added VR support to Standard Render Pipeline HBAO

    But when on empty project with standard renderer (only xr managment and oculus integration installed) i add HBAO to camera, when turning on "single pass instantanced" stereo rendering mode in oculus provider settings, all i can see in left eye is gray color and right eye render fine, but without AO whatsoever. And i'm getting error "A multisampled texture being bound to a non-multisampled sampler. Disabling in order to avoid undefined behavior. Please use Texture2DMS in the shader."
     
  43. Blade_Master_2020

    Blade_Master_2020

    Joined:
    Aug 3, 2019
    Posts:
    38
    Hi,Is there a way to make HBAO render before volumetric fog like the default AO? I'm using HDRP 11.0 and I tried to modify HDRenderPipeline.cs but can't find the RenderSky() method.

    4.png 3.png
     

    Attached Files:

    • 1.png
      1.png
      File size:
      3.2 MB
      Views:
      280
    • 2.png
      2.png
      File size:
      3.2 MB
      Views:
      281
  44. Camarent

    Camarent

    Joined:
    Feb 19, 2014
    Posts:
    168
    Hi! I am seeking for Ambient Occlusion solution that would work better with smoothed meshes. I tried builtin AO from URP 10.6.0 and I had this results.
    upload_2021-7-29_14-43-58.png
    upload_2021-7-29_14-46-20.png

    When using smooth mesh it produce black lines on edges.
    Can i fix it using your plugin or it is typical problem for all AO solutions?
     
  45. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Hi! Is there currently a way to apply HBAO only to certain objects?
    Also, I'm on HDRP 12 and Unity 2021.2 beta 5 and the asset works fine. The only issue is that I get this error:
    upload_2021-8-2_17-45-52.png

    I just commented it out in the code and the error is gone.

    And the view normals mode looks a bit broken:
    upload_2021-8-2_17-46-20.png
    But it doesn't seem to affect anything. Should I worry about these or can I just ignore it?

    Thanks!

    UPD: seems like I've found a way to apply AO only to specific objects and layers in the scene. But if there's some official method to do this, please let me know anyway :)
     
    Last edited: Aug 2, 2021
  46. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    Any planned support for URP 12 or URP 11+?

    CommandBuffer: temporary render texture _CameraColorTexture not found while executing HBAO (Blit source)
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)


    ^^Happens in my project and the included URP demo scene. HBAO effect doesn't render.
     
    Last edited: Aug 15, 2021
  47. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    To make HBAO 3.3.1 run on URP12:
    - remove/comment out line 34 from Assets\Horizon Based Ambient Occlusion\SRP\URP\Editor\HBAOEditor.cs that contains hasAdvancedMode override
    - remove/comment out line 375 from Assets\Horizon Based Ambient Occlusion\SRP\URP\Runtime\HBAORendererFeature.cs that sets source a new RenderTargetIdentifier
    - add following to line 359 on that same file (Assets\Horizon Based Ambient Occlusion\SRP\URP\Runtime\HBAORendererFeature.cs):
    source = renderer.cameraColorTarget;
     
    GridWanderer and jimmikaelkael like this.
  48. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    While not ideal, you can iron out the worst issue (SPI not rendering anything proper) by using the MockHMD option on Unity's current XR setup. This is a lot nicer to test rendering changes with as you don't have to put on the headset to check the changes. As for URP VR + SPI being broken, it's because Unity broke cmd.Blit on 2020 cycle I think.

    To work around the broken Blit you have to use cmd.DrawMesh API now. I've put together a simple example of this here: https://github.com/0lento/URP_RendererFeature_SPI_Example
     
    GridWanderer and jimmikaelkael like this.
  49. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    796
    I can't tell if you can fix with my asset... But my guess is that Unity's SSAO is not at fault, I'd check the vertex normals on your models are correct.

    Just submitted an update (3.3.2) which will fix the editor issue. For view normals view you can just ignore it, skybox is just not being cleared.

    I'm sorry for this issue, will be solved by v3.3.2 which is pending review.

    Thank you so much for this tip sir! Will try to check on this weekend.
     
    GridWanderer and rz_0lento like this.
  50. RichmarIII

    RichmarIII

    Joined:
    Mar 15, 2015
    Posts:
    7
    Cheers! That fixed it, Thanks!
     
    rz_0lento likes this.