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. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Cool will do, do you know when the sale is going to end on HBAO?
     
  2. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    The sale is related to Unite 2017 events and the offer ends on May 24.
     
    KillerNads likes this.
  3. AlexeyDrobyshevsky

    AlexeyDrobyshevsky

    Joined:
    Sep 28, 2016
    Posts:
    37
    @jimmikaelkael A question about stencil buffer. We're using HBAO asset, and when it draws the post effect, it clears the stencil buffer (or rather, it looks like Unity clears the buffer for some reason). If we remove ImageEffectOpaque attribute stencil is no longer cleared, but HBAO works incorrectly - since it renders after transparent effects in this case.
    We need stencil data because we render some UI decals (e.g. markers that render on top of terrain) last, after post-effects.

    Any ideas on how to solve this?
     
  4. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Most likely the problem comes from your shader clipping some geometry but not writing to depth buffer, so the clipped geometry is still present in it.

    HBAO (like any SSAO solution) being based on Depth Buffer it believes the clipped geometry is still there.
    You need to add a shadow caster pass to your shader and clip the geometry the same way in this pass.

    If you can't solve it, feel free to send me a small repro case, or simply your shader on PM.
     
  5. AlexeyDrobyshevsky

    AlexeyDrobyshevsky

    Joined:
    Sep 28, 2016
    Posts:
    37
    The problem comes from our shader depending on correct values in the stencil buffer, which are not there if HBAO runs. I don't see what depth data has to do with this.

    To elaborate, we draw some decals after post-processing step using depth data to project decals onto the geometry, and stencil to exclude some geometry from being affected by decals. If HBAO renders before our decals, the depth is still correct - the decals do render. But the stencil buffer is cleared - decals render on top of all geometry, even those meshes that were to be excluded.
     
  6. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Is your decal shader using CommandBuffers ?
    If yes I suggest to do a blit at cam event CameraEvents.BeforeImageEffects.

    Or write in PM, giving your invoice number and a sample material or project. I'll gladly help if I can!
     
  7. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    There's also a thread that could be useful: https://forum.unity3d.com/threads/onimagerender-with-stencil-buffers-of-source-active.428738/
     
  8. AlexeyDrobyshevsky

    AlexeyDrobyshevsky

    Joined:
    Sep 28, 2016
    Posts:
    37
    This does not actually help because HBAO renders even before this (after opaque geometry). Here's the rendering order:
    1. Opaque geometry
    2. HBAO <--- stencil is cleared here
    3. Transparent Geometry
    4. Image Effects
    5. Our decals <--- make use of stencil
    Even if we move the decals before image effects, the problem still persists. However, if we move HBAO after transparent geometry, stencil buffer survives intact. We've settled on the following workaround:
    1. Opaque geometry
    2. Render decals to a separate texture <- before HBAO, stencil is still correct
    3. HBAO <- clears stencil
    4. Transparent geometry
    5. Image Effects
    6. Draw the texture from step (2) on top
    This works but requires an additional render texture which is not optimal. We're quite pressed for time right now, and can't make a simple repro case. Maybe we'd be able to do so in a few days.
     
  9. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Yes check the post I suggested above where @Tim-C from Unity is giving an answer on the correct way to achieve it.
    Just to be clear: HBAO doesn't clear stencil by itself... Have you tried to look with the frame debugger what/how it happens ?

    EDIT: No need a full repro project... Just your decal shader and it's script and a material exported in a package and it's fine, not too much time consuming I guess.

    EDIT2: HBAO won't render before CameraEvents.BeforeImageEffectsOpaque, sorry for the confusion, when I said BeforeImageEffects I really meant BeforeImageEffectsOpaque
     
    Last edited: May 16, 2017
  10. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Hey guys,

    Im very confused about which SSAO asset to purchase!! Its for a desktop VR game, I've broken it down to 3 choices: HBAO, Amplify Occlusion and Volumetric Ambient Occlusion.

    Im slightly biased towards HBAO because of the number of reviews (with high ratings) and the amount of people using this and also because of the Sale currently on. However, it doesn't support SPSR and also i don't know whether it is compatible with Valve Lab Renderer or not.

    Both the other packs support SPSR (and i know AO works with Lab Renderer too) so would be ideal for VR but i don't have a clue how they work in comparison as a SSAO solution...

    Any tips/advice that would help me make up my mind please :)
     
  11. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    From what I know, on the 3 SSAO solutions you've mentionned only VAO currently supports SPSR. Correct me if I'm wrong...

    HBAO is compatible with Valve's Lab Renderer (however their shader has shadow caster pass commented, which is required to uncomment for any SSAO solution or post FX based on depth to work).

    Now I let others give their point of view.
     
  12. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Okay cool, from Amplify's email they did tell me that SPSR is supported also in AO. As for Valves Lab Renderer, they said that they have a separate build available that i can get through email that supports this. So I'm assuming that it probably has some files in it that replaces the code that is commented out.
     
  13. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Hi, i see that this is on sale again :D

    Any chance that it has been updated yet for VR support?
     
  14. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    I'm really sorry for the late reply...

    Yes SPSR support is coming in update 2.4, which will be released in just a few days.
     
    scvnathan likes this.
  15. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO update 2.4 has been submitted for review yesterday with the following changelog:
    • Added support for Single Pass Stereo Rendering
     
    docsavage and scvnathan like this.
  16. scvnathan

    scvnathan

    Joined:
    Apr 29, 2016
    Posts:
    75
    Thank you! :D

    By the way, just curious but have you been keeping up with the work being done on the new post process stack (https://github.com/Unity-Technologies/PostProcessing/wiki/(v2)-Writing-custom-effects) ? Do you foresee HBAO being rewritten or refactored as a custom post-process effect?
     
  17. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    To be honest, I'm really not sure there will be a performance benefit by doing this and I guess this is what you're expecting, right ?
    Another problem is that I can't ask my customers to have the new PostProcessing stack in order to use my asset.

    EDIT: FYI the HBAO_Integrated component already integrates into the rendering pipeline if this is what you meant.
     
  18. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Hi @jimmikaelkael !
    I recently bought your HBAO solution and it is producing some great results. However when using it together with double sided shaders like these: https://www.assetstore.unity3d.com/en/#!/content/42360

    It does not seem to work, the backfaces looks semitransparent. The double sided shader package above have correct ligting on both side of the mesh.

    I tried another solution as well, Amplify occlusion and it seems to handle the double sided materials just fine. However the results using this is far from the quality using your HBAO. Is this something that you can fix or add support for?

    Best Regards,

    Kristian
     
  19. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Have you tried the newer HBAO_Integrated component to see if it makes a difference ?

    EDIT: Another thing to check, and maybe this is to be tried first, is to set normals like you were setting it with Amplify. The HBAO per pixel normals set on "Reconstruct" is the same as Amplify normals set to "None".
     
    Last edited: Jun 27, 2017
    turboscalpeur likes this.
  20. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Setting the HBAO per pixel normals to "Reconstruct" solves the problem in both HBAO and HBAO_Integrated. Thanks!
     
    turboscalpeur likes this.
  21. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    I'm glad it fixed the problem!
    However, it seems that the shader package you're using is correctly writing the depth, but not the normals at least for that backfaces. I'm not sure about it and this is to be investigated.

    The problem is solved because in Reconstruct mode HBAO extrapolates normals from depth buffer. The downside is that you loose texture normals contribution.
     
    turboscalpeur likes this.
  22. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Ah i see the asset has finally been updated to support full VR. Thats great thanks! I wish i had purchased it from the sale now but back then you wasn't sure if and when SPSR would be supported so thats why i held off!

    Will wait for the next sale to come along now and then purchase it.

    thanks
     
  23. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Yes, support for SPSR has been added in the latest release. However I haven't been confirmed it works as expected for both HBAO components (HBAO and HBAO_Integrated).

    Should be OK but if anyone can give feedback about it that would be great! ;)
     
    turboscalpeur and Howard-Day like this.
  24. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    @jimmikaelkael HBAO v2.4, single pass stereo rendering does not appear to be working in 2017.1.0 Beta 9 on the HTC Vive.
     
    Last edited: Jul 7, 2017
  25. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Ok, seems (I'm still unsure) there's strange behavior regarding SPSR with Unity 5.6.1 and above.

    Can anyone please report if VR Single Pass is working as expected with HBAO 2.4 and Unity 5.5 ?
     
    Last edited: Jul 7, 2017
  26. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    @jimmikaelkael There is a new issue I'm encountering in 2017.1.0b9. It seems Unity's Post Processing Behaviour (PPB) is canceling HBAO in the stack, but I'm not sure why; for some reason I'm only experiencing this on a specific project. What's interesting, however, is that if Ambient Occlusion is enabled - even .001 intensity - HBAO becomes active; it's as if PPB is intercepting the pass(?)
     
  27. scvnathan

    scvnathan

    Joined:
    Apr 29, 2016
    Posts:
    75
    I haven't tested in 5.5 but I tested in 5.6 and there were some weird depth issues in SPSR. Something was definitely off between both eyes.

    I just tested it in 2017.1f3 and now there are also several black lines running up and down the screen. I can post some screenshots later.
     
  28. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Yes, I have reproduced this issue on my end as well and contacted the developer
     
  29. scvnathan

    scvnathan

    Joined:
    Apr 29, 2016
    Posts:
    75
    Interestingly, other AO assets seem to be having issues with SPSR too, not just HBAO. I've noticed similar issues (no black lines though) with Amplify and Wisdom AO. Pretty much the only AO solution I've tried with 5.6.2 that worked ok was Unity's post-processing stack(v1 and v2 seem identical). But I gotta say, their AO is pretty ugly with not much control...
     
  30. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    There is something going on with grabpass or changes to the depth buffer that are causing inconsistencies for many image effects in 2017.x. A much stranger issue is one I haven't reported to the forums, but contacted the developer about, wherein if HBAO and Unity's Post Processing Behavior are stacked on the same camera, the post processing behavior will hijack the HBAO pass and you cannot enable HBAO without also enabling AO in the post processing behavior; very strange. Michaël is working on a fix for SPSR as we speak.
     
  31. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,897
    Previous versions of Unity's Post-Processing were reseting the camera depthTextureMode property. Latest update on GitHub seems to respect the current camera value and only adds new flags when needed.

    Since Unity 5.6, there're some inconsistencies with temporary render textures (ie. used in downsampling or internal passes) and Single Pass Stereo. Seems _MainTex_ST has not the expected values, also the projection matrices are different from Unity 5.5. There're bug reports in this regard which have been confirmed by Unity. Hopefully they fix or docu the behaviour change soon.
     
  32. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    I'm acquiring an Oculus CV1 so I'll be able to keep track on SPSR bugs in the coming weeks. Sorry for the inconvenience.
     
  33. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    @Thrawn75 I've got my Oculus so I've played with it a bit and with the help of @buttmatrix to test on the Vive. What I noticed is that the resolution returned by the Camera.pixelWidth and Camera.pixelHeight is not the same as what is used internally when doing the rendering. For example on my Oculus using OpenVR Camera given resolution is 1344x1600 per eye but the rendering pipeline uses 2816x1600 for both eyes.

    Once I set my texture resolution properly it fixes all problems, I'm actually digging into it a bit more as I need to check what VRSettings.eyeTextureWidth and VRSettings.eyeTextureHeight returns and if render scale impacts on used resolutions.
     
  34. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,897
    Nice. I'll check out your future update and compare it to what they're introducing in Unity 2017.1 (and supposedly back ported to Unity 5.6 in a future patch). I'm using RenderTextureDescriptors which works great in Unity 2017.1, basically reusing source.descriptor for any buffer option except for downsampling, when I simply adjust its width/height if necessary.
     
  35. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Hi,

    I would like to know if it is possible to "invert" your code to achieve a colored "glowing" effect like this:



    (What I do not mean is to invert the whole renderoutput like an invert-posteffect.)
     
    Last edited: Jul 26, 2017
  36. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Inverting just the effect will not look like this. This is the whole scene that needs to be inverted.
    Isn't there any Post FX around handling negative ?
     
    buttmatrix likes this.
  37. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Very many: ColorfulFX, Amplify, etc.
     
  38. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Thanks, but I wrote that I would prefer NOT to achieve this with a PostEffect but by the HBAO-plugin itself.
     
  39. to8touser

    to8touser

    Joined:
    Aug 2, 2017
    Posts:
    3
    hello , how can i set some object not to cast AO?
     
  40. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    This is actually not easy. Like every SSAO plugin, HBAO is a screen space image effect and is geometry agnostic.

    One way (awful way I have to admit) is to set a higher custom render queue to the material. For upcoming releases I'm searching for a way to plug the AO in the Standard shader so one could decide if a material receive AO or not, but I can't promise anything...
     
  41. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    I have flickering issue my character's face when I set HBAO to G-buffer.
     
  42. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    Isn'it the problem mentioned above when using the Post Processing Stack ?
     
  43. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    I'm not using Post Processing Stack yet. anyway there is another issue that HBAO doesn't works with Hair Tool. Don't know why but it makes hair transparent.
     
  44. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    If you have a flickering issue when GBuffer per pixel normals are enabled then most likely you're using tool altering it.

    For Hair Tool, I think it is hair tool not working with SSAO solutions... As the author stated it seems to not work out of the box when "you use some post effects with using of normal depth texture". I suggest reading this post: https://forum.unity3d.com/threads/hair-tool-1-1-0.446431/page-6#post-3147045

    In any case, from Unity 5.5 and above you should be using the new HBAO_Integrated component instead of the older HBAO component.
     
  45. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
  46. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    This is not a problem but I already replied this question :)

    This won't be that good: controlling the exact placement of the custom effect in the stack is currently impossible...
    2nd thing: you won't get any performance benefit.
    3rd: HBAO will break everytime they make API changes
    4th: if a customer imports HBAO without prior importing PostProcessing Stack, it will break

    And finally, the HBAO_Integrated component already integrates in to the rendering pipeline ;)
     
  47. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Thanks for replying. Sorry about the repeat post but I didn't see it :(
     
  48. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    There's no problem you know, you're welcome! ;)
    The idea is great I have to admit.
     
    Stormy102 likes this.
  49. jimmikaelkael

    jimmikaelkael

    Joined:
    Apr 27, 2015
    Posts:
    791
    HBAO 2.5 has been submitted for review with the following changelog:
    • Added offscreen samples contribution setting
    • Improved color bleeding performance

    For VR Single Pass bugs, I'm awaiting a reply from Unity as to why the resolution returned by the camera API isn't corresponding to what's used internally by the HMD.
     
  50. N00MKRAD

    N00MKRAD

    Joined:
    Dec 31, 2013
    Posts:
    210
    How do I enable/disable it with a script?

    My script can't find it: