Horizon Based Ambient Occlusion - HBAO image effect

Hey, using hdrp 2022 here and wanted to know if is there any possible way for me to exclude the hbao from unlit materials, if there is any way to do that.
Reason is I was gonna use anime chars in the game, and didnt want to render the strong hbao on them, but of course in everything else I wanted to use a reasonably strong hbao.
Reasobably inexperienced in shader coding but I figured I can at least half-understand what’s happening in there, I’ve read all the hdrp ao code and your hbao code, tried some things but neither one worked. Any sugestions?

Edit: My suspicion is that your HBAO in hdrp is being applied as an “overlay” rather than affecting the actual internal AO channel/buffer in HDRP, and doing this would only be possible if you integrated it via RenderGraph, is that correct?

In HDRP the ao buffers are not accessible yet, so that’s not because I don’t support RenderGraph yet in hdrp. And because we cannot inject ao inside ao buffers yet, excluding materials properly is not possible in hdrp.
I’m really sorry for the inconvenience.

1 Like

I think there’s definitely no way with RenderObjects I’m sorry. I hope they will change it one day…

Hi,I’ve been using HBAO for some time now, but recently the processing effect has stopped working. Toggling it in the global volume doesn’t make any difference, and the debug mode is also ineffective. I’ve gone through the user guide again and reset everything according to it, yet it still doesn’t work. Could you help me resolve this issue?

Sure, please send me your project or a repro project on my email and I’ll take a look.

I’m sorry, I don’t have your email address. Can you give it to me?

I got your repro project: all you have to do is to raise the HBAO intensity slider above 0.

CONTEXT @ BIRP
I was previously using the Built-In Render Pipeline with HBAO and was absolutely loving it.

TRANSITION @ URP
I’ve recently been exploring URP more and was happy to see that HBAO also supported URP. However I am having a few anomalies and wanted to post for perspective.

ISSUE
The one big difference seems to be with Grass so far.

ATTEMPTS

  1. I’ve tried both Normal and Lit AO as options.
  2. As well as various settings (Camera, Reconstruct, Bias, etc).

OBSERVATIONS:
I saw some previous chatter regarding URP + Grass (Translucent / Alpha Clip)
~ But no clear cut solution AFAIK for my goal.

SHADER GRAPH??
I saw you can maybe do a custom Shader Graph that omits AO factors?
(haven’t tried that, but if a viable option to get back to Built In Render visual behavior let me know!)

// EXAMPLES

  1. Built-In
    = As expected & desired
  2. @ URP
    = AO all over the place.

// SETTINGS
Also including my HBAO settings from URP.

RESOLUTION
Basically looking for any advice and perspective on how to achieve the look from the BIRP version.

Thank you!

It’s hard for me to notice if you were having some AO cast on terrain while you were on BiRP.

If the behavior you want is that your grass receive and cast occlusion then the issue on URP seems to be with your DepthOnly/DepthNormal passes in the shader not applying the clipping. Have you tried to enable shadows for the grass to see if clipping is applied properly to shadows?

Is it a custom or 3rd party shader?

You can always share your shadergraph and Unity version, I’ll take a look to it.

Any luck on the VR fix? Happy new year!


How do I prevent this from happening where the Ambient Occlusion doesnt apply if the edge on the screen is next to a diffetent object in front of it

You cannot prevent it, this is a limitation of any SSAO solution. This is generally not an issue unless you exagerate the AO.

Not yet, I’m sorry I had no chance to try it during Christmas holidays.
I’ll try to find an already used Quest 3 at a good price.

I have the same issue of LitAO not working in the build, and got excited to try the workaround out since LitAO looks so good. However, it unfortunately still didn’t work for me on 2021.3.22f1 even when I duplicated the renderer with SSAO added on top.

I’ve also made sure the pipeline settings aren’t overridden in the Quality tab. Are there any other ideas?

You need to duplicate your renderer (don’t remove any renderer feature on it), add builtin SSAO to it then assign this dummy renderer to your pipeline asset.

Yes, that’s what I’ve done. (Ignore the ForwardRenderer name, they are both deferred renderers haha).

Maybe it’s one of these custom assets interfering so I’ll try removing them individually later. Well, the Normal HBAO still looks pretty good at least and thank you for making this asset for all of us!

Sorry to necro this - I know it works in HDRP 14 point something, but if you’re using an older HDRP version (ex. 7.x) like I do, you can use the following workaround:

  1. Bring the HDRP package (folder com.unity.render-pipelines.high-definition@7.x) to your project’s local /Packages/ folder, so that it can be patched.
  2. Locate file HDRenderPipeline.cs (in /Packages\com.unity.render-pipelines.high-definition@7.x/Runtime/RenderPipeline/).
  3. Open it for editing and move line m_PostProcessSystem.DoUserAfterOpaqueAndSky(cmd, hdCamera, m_CameraColorBuffer); (should be somewhere between SendGeometryGraphicsBuffers(...) and RenderTransparentDepthPrepass(...)) after RenderSubsurfaceScattering(...) and before RenderForwardEmissive(...).

Your HDRP implementation might be different and m_PostProcessSystem.DoUserAfterOpaqueAndSky(...) might be named differently, but ultimately, you want to move the AfterOpaqueAndSky injection point earlier in the RP, so that its effects execute earlier. Not too early though.

Of course, beware that doing so will affect all PP effects that are assigned to After Opaque And Sky injection point (they too will execute before fog), as changing its execution location effectively invalidates its original semantic (now it’s essentially “before transparent”). I only have the HBAO effect assigned to After Opaque And Sky, so for me, the workaround did not break anything.

I know it’s a dirty workaround, but perhaps somebody might find this useful as a last resort.

For more context, my RP looks like this now:

m_PostProcessSystem.DoUserAfterOpaqueAndSky(cmd, hdCamera, m_CameraColorBuffer);

// moved:
// before volumetric lighting, so that custom AO effects don't render after fog
m_PostProcessSystem.DoUserAfterOpaqueAndSky(cmd, hdCamera, m_CameraColorBuffer);

RenderForwardEmissive(cullingResults, hdCamera, renderContext, cmd);

RenderSky(hdCamera, cmd);
// Send all the geometry graphics buffer to client systems if required (must be done after the pyramid and before the transparent depth pre-pass)
SendGeometryGraphicsBuffers(cmd, hdCamera);

// default
// should be before volumetric lighting, so that custom AO effects don't render after fog
//m_PostProcessSystem.DoUserAfterOpaqueAndSky(cmd, hdCamera, m_CameraColorBuffer);

RenderTransparentDepthPrepass(cullingResults, hdCamera, renderContext, cmd);

Some before & after:

Before HDRP patch (left - HBAO off, right - HBAO on):


After HDRP patch (left - HBAO off, right - HBAO on):


Before (left) & after (right) HDRP patch (HBAO on in both):


All the best!

1 Like

Posting for records. I updated my project to Unity 6 and HBAO was completely screwed up, it made my whole scene weirdly purple dark, rendering nothing, and kinda had that effect you’d get when you’re rendering nothing at all and so the screen just keeps whatever was on the screen like when there’s no skybox.

Anyway the fix was that URP pipeline asset thing (not the one that you put renderer one you put render features in, the other one) has a setting called Opaque Texture below the required Depth Texture, and somewhere along the way that got turned on. I have no idea what that does or if it matters or if I did that on purpose or if Unity 6 decided to be insidious, but I’m leaving this here in case it happens to someone else.

Update to this - it looks like this Opaque Texture issue came up several years ago, and was fixed then, but the issue seems to have returned (in unity 6?). I found that the Distortion effect in shaders uses the opaque texture, so I cant have HBAO and distortion at the same time. I don’t think this was an issue before upgrading to unity 6. Hoping there will be a fix. I’ll try a few things to see if I can magically find a workaround.

Yep but Lit AO looks even better. Worst case you can add builtin SSAO feature to your main renderer and set intensity to 0. It’s less clean but the builtin SSAO pass should not run with a 0 intensity.