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

Super-fast high-quality SSAO

Discussion in 'Works In Progress - Archive' started by sonicether, Nov 12, 2014.

  1. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Hey, everyone.

    I'd love to get your opinion on an image effect I've been working on for Unity. Like many users, I've never been satisfied with Unity's built-in SSAO functionality. I set out to see if I could come up with something that looks better and runs faster. I've made a lot of progress and I'd like to share what I've come up with so far.


    Here's a test scene rendered at some arbitrary high resolution over 1080p (2372x1335 to be exact). I'll be comparing Unity's built-in SSAO image effect with mine.



    Here's Unity's SSAO being rendered in 9.2 ms at the highest quality settings I could manage. There's a lot of noise, despite filtering, and high-frequency details are pretty much non-existent due to the large radius. Why can't we have a large SSAO radius and high-frequency details?


    Here's my SSAO effect in its current state being rendered in 4.3 ms. Because I take a simplified approach to gathering AO samples, many samples can be taken for a low cost. I've also written a more robust calculation that reduces under-occlusion and over-occlusion at a heavier performance cost. There may still be room for further optimization and there is definitely still room for further polish and image-quality improvement.


    I'm pretty happy with the results so far. In my opinion, it looks much better, and renders at more than twice the speed that Unity's built-in solution does.

    Let me know what you think! If enough people are interested, I'll consider putting it on the Asset Store. If there's any additional information you'd like about my implementation, feel free to ask me.
     
  2. RiokuTheSlayer

    RiokuTheSlayer

    Joined:
    Aug 22, 2013
    Posts:
    356
    *claps* Bravo, Bravo!
     
  3. Comradedrago

    Comradedrago

    Joined:
    Nov 11, 2014
    Posts:
    11
    Looks nice i would love if i ever did any thing needing this to be able to use it yours look a lot better then there default.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I like it. More performance is always welcome. It always seems to me that ambient occlusion, lighting, shadows, and radiosity, all really belong to the same single system and should have all those features working as one, ie global illumination, but I know that's really a challenge.
     
  5. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    whoa ... looks soooo much better than the default one :cool:
     
  6. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,608
    Web player? Will this be released?
     
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Nice

    Wil this work in Unity Free by any chance ? Also will it have a cut off parameter to control the depth it is applied to ?
     
  8. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,608
    He says it's an image effect, so unfortunately for free users, no use.
     
  9. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    yeah, I doubt you even could make ssao that would work in Unity free ;)
     
  10. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    There are ways to make it happen i guess, but are usually much slower.
     
  11. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    I don't think there are ... are there? how else would you do it if not as an image effect?
     
  12. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,789
    That looks much nicer than the built-in effects! One huge problem I've always had with ssao is that it breaks functionality for many succeeding image effects... as if the depth buffer get's overwritten. If you could solve this issue it would be seriously worth the upgrade :)
     
  13. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    You have to grab the backbuffer into a texture which is relatively slow and then you can re-draw that texture with an image-effect-like shader.
     
  14. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    that sounds like it would be incredibly expensive performance-wise
     
    Last edited: Nov 12, 2014
  15. srmojuze

    srmojuze

    Joined:
    Mar 18, 2013
    Posts:
    127
    I love your Sonic Ether plugin, that SSAO looks awesome.

    Can you post some comparison renders with colours, textures, etc. with Unity 5 Global Illumination?

    Let's see some AAA eye candy :)
     
  16. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Last edited: Nov 12, 2014
  17. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
  18. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
  19. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Awesome, i'm always looking for a big radius AO. Also have you tried to modified the specular buffer in unity 5, it could be awesome if this also work as specular occlusion.
     
  20. SpreadcampShay

    SpreadcampShay

    Joined:
    Dec 9, 2010
    Posts:
    180
    Hello sonicether, it is great to see you work on something again!

    - Does your SSAO work well in combination with your bloom asset?
    - Is it possible to draw your SSAO more intensely? What I like about SSAO Pro ( https://www.assetstore.unity3d.com/en/#!/content/22369 ) is the intensity of the black in all the crevices and details. I don't see that in quiet the same way on your example screenshot, though it sure is better than the inbuilt SSAO.
    - The main reason I did not buy SSAO Pro is the near clip requirement on your camera. SSAO Pro requires you to set your Camera's near clip plane to at least 0.3, better yet 0.5 or 0.6... and that is unacceptable for my project. How about your asset, does it have the same restriction or does the lowest near clip setting work well too?
    - Does it work well in Unity 5?

    Thanks for answering my questions.
     
  21. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    SSAO Pro works very well with a large outdoor environment. :cool:
     
  22. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    ... and what makes you think that Sonic's SSAO won't? ;)
     
  23. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Waiting for the dev talking about that.
     
  24. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Thanks for the questions, guys.

    I'll get a web player up when I've polished the effect.


    Is there a way to test this? I'd like to see if my SSAO causes the same problem.


    Sure! I'll post some screenshots soon.


    Oh, wow. Indeed, it seems that way. I'm not one for mud slinging, and every SSAO algorithm is going to have its upsides and downsides. However, there are some artifacts that I could point out here that don't exist in my algorithm... :p


    Yep, it works just fine in combination with my bloom asset.
    Yes, it is possible to increase the intensity of the AO.
    I tested a near clip of 0.01 with a far clip of 5000 and everything still looked just fine.
    I'll be working on Unity 5 support as well.


    I'll have to get some sort of test scene to see how my SSAO works out with large outdoor environments. It's something I haven't quite tested yet.
     
  25. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Is there a way to make only dynamic (or certain) objects have SSAO? I generally like having lightmaps that produce decent corner shadows and adding SSAO on top of that makes everything look weird. I do like my main character producing SSAO on the objects around him though.
     
  26. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    Yes. Per object SSAO would be an extremely useful feature of any SSAO asset.
     
    shkar-noori likes this.
  27. spraycanmansam

    spraycanmansam

    Joined:
    Nov 22, 2012
    Posts:
    254
    Hmmm, it would be possible, but it would more than likely come with some kind of performance penalty.. I imagine you would have to generate a custom depth texture for the objects you wanted to be occluded. IIRC Candella SSR does this and good god it's expensive. That said, I could be wrong.. :p

    Great results btw @sonicether :) I love this stuff.. I want to get back into more of it when we finish our project.
     
  28. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Hmm... Could the extra cost of generating some sort of custom depth buffer, be offset that in general you will then need to take much fewer samples?

    Sonic Ether did say that the way he does it samples are pretty cheap though, so maybe not that much.
     
  29. Tanshaydar

    Tanshaydar

    Joined:
    Apr 20, 2011
    Posts:
    33
    I've been going back and forth with many SSAO algorithms and implementations around, and I've used some of them; but eventually went back to Unity's Obscurance script. None of them satisfied me, and some of them were even worse than Unity's standard script.

    This, I must say, looks very nice and I cannot wait to see it in my game, hopefully settle AO things for me.
     
  30. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Hmm, per-object SSAO... At least from what I know, this wouldn't easily be achieved without some sort of material ID buffer, which just isn't possible to create without replacing all shaders in the scene or drawing the scene twice. I'll tinker around and see if I come up with any other ideas.

    I wanted to update you guys on how my progress is going with this algorithm. I've cleaned up the sampling kernel for evenly-distributed samples, which vastly improves image quality for no additional cost.


    Here's the raw AO buffer of the latest version of my SSAO algorithm. In my humble opinion, it resembles raytraced AO! Don't worry, what you see here performs just as well as what I posted in the OP.


    I've been playing around with how the AO is actually applied to the scene. Until Unity 5 comes around, there isn't a good way to apply AO to only ambient light with deferred lighting or forward rendering. AO is typically blended multiplicatively to the scene color whenever direct access to the ambient lighting term is unavailable. I've never liked the look of this. It looks less like what AO tries to approximate (which is indirect soft shadows) and more like smudged charcoal rubbed in crevices.

    I'd like to get some opinions on some experimental blending modes that I'm working on.


    Here's the Robot Lab scene with no SSAO, just for reference.


    Here's the scene with my SSAO blended in the standard way (multiplied). An improvement.


    Here's the new experimental blending technique. In my opinion, it looks less like "black" and more like a simulation of a phenomenon of indirect lighting.


    I thought it would be cool to be able to "tint" the AO buffer with a user-defined color before applying blending to the scene. This provides colored shadows to help alleviate the "charcoal" effect. Different lighting setups will require different tint colors to look best. I picked a warm tone for this scene (because of all of the warm-colored objects in the scene). This screenshot is a combination of AO buffer tinting and the new advanced blending technique.


    Open these images in new tabs and flick between them to get a more direct comparison. I'll likely leave these blending options in. I know some users may prefer the look of traditional multiplicative blending, and that's fine. I'd just like to offer as much flexibility and unique features as possible. Speaking of flexibility, don't worry, everything like number of samples per-pixel, AO radius, AO strength, distance limit, depth tolerance for bilateral filter, depth attenuation, and blending modes will all be configurable.

    I'd love to hear your opinions! :)
     
    Arkade, angrypenguin and Luckymouse like this.
  31. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92

    WHOA!!! O_O this looks amazing!!! :)
     
  32. sonicether

    sonicether

    Joined:
    Jan 12, 2013
    Posts:
    265
    Just made some more progress. I wanted to share what's new.

    So, on the topic of "tinting" the AO buffer, I figured, why not use local color information to do that instead?

    True screen-space global illumination is out of the question, since it requires scene albedo which is unavailable with Unity 4's pipeline. Though, I was messing around with tint color and noticed that, at some values, it almost looked like a secondary bounce of light. Maybe the way I was tinting the ambient occlusion could be applied to locally gathered color from nearby objects, hopefully helping to wipe away all the charcoal.


    Good ol' Robot Lab, with no SSAO for comparison.


    Here's the scene with Unity's SSAO. Suffers from the "charcoal" look.


    Yep, it actually somewhat worked! Here's the scene with my SSAO with color bleed and advanced blending enabled. Surprisingly, even with the additional computations, this technique is neck-and-neck performance-wise with Unity's SSAO. I'm quite enjoying the look that this provides, though its realism is highly debatable. The settings active in this image are quite exaggerated to demonstrate the effect.



    It's not perfect, by any means, and is certainly no substitute for GI. Surface brightness does not affect bounced light intensity. Bounced light is only affected by hue/saturation of nearby surfaces. It may work for some scenes, and may not work for others; I've yet to test it in a scene other than Robot Lab. Again, I'll be fully exposing all parameters so you can get the best look for your particular scenes (light intensity of color bleed and blending modes), or just stick with traditional SSAO blending if you prefer it that way.
     
  33. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    All of them looks great sonic, rather than struggling with the blending mode decision why not just put the blending mode selector so people can choose which one they gonna use that fit their art style.
     
  34. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Bear with me as I air some thoughts. While I think the SSAO presented in this thread is lovely looking, I don't think it's overall the right way for the new consoles or desktops in general. It's just too expensive when used everywhere. However, this isn't what I'm driving at.

    Generally, baking AO will give you a superior look. Nearly everything these days in PBR land is baked, and includes an AO map. So therefore this is a big loss in performance for something you already should have as a baked resource - every model should have available AO maps given the wealth of tools out there to generate them.

    So what can be done? Well my current thinking is, that AO should be reserved only for dynamic objects. Is it possible to dramatically increase performance by only enabling AO for the point of contact between objects which already have AO maps available?

    Would this be possible? localised AO, or failing that, AO for where two objects (of your choosing) are in proximity. I have a feeling this would be a real win overall for a typical game which doesn't have too much dynamic content.
     
  35. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    yeah - he already said that it will be an option :) damn - can't wait to get my hands on it (especially since the built-in Unity ssao is just soooooooo horrible ... I don't think they updated it in like forever)
     
  36. SirStompsalot

    SirStompsalot

    Joined:
    Sep 28, 2013
    Posts:
    112
    I've used SSAO Pro and I was unhappy with it. I have a lot of dynamic, procedurally generated objects that could really use some AO love. Will keep an eye on this.
     
    ThunderTruck likes this.
  37. srmojuze

    srmojuze

    Joined:
    Mar 18, 2013
    Posts:
    127
    Superb. Especially if performance wise it is just as fast as Unity SSAO. Color tinting of AO is a brilliant idea.
     
  38. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Woops....did he?? my bad, that what i got reading a long post while really tired :p
    Using bent sphere AO like naughty dogs did in last of us would be a doable and highly performance for selective AO i think, Dynamic object receive and casting AO while the static object "only" receive AO from dynamic object while also casting AO to dynamic object but not Static to static AO.
     
    shkar-noori, srmojuze and hippocoder like this.
  39. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    yeah - that's a great thing ... apparently the performance is the same for the version that looks super-awesome ... and if you just want the regular non-blended ssao, the performance is waaaaaaaaay better than the built-in one :) which sounds really awesome to me :D
     
  40. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    yeah, he did, lol :p apparently it's going to have A LOT of sliders and toggles, haha :D
     
  41. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Dammit, when is this coming out? I want it :)
     
  42. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    by the looks of it, I'd say - pretty soon :D
     
  43. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
  44. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    yeah ... I agree ... it's gonna be interesting (to say the least) :D
     
  45. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    I think that might only be possible to do in Unity5 ...
     
  46. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Not really, if you read the tech behind shadowgun they also use sphere AO for the main char shadow (Three sphere if i'm not mistaken, One for body two for feet), and it was for mobile. Only they not bend the ray projection like ND.
     
  47. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    ah, I see ... well, in that case we'll have to wait for Sonic to come here and let us know if it's possible or not :)
     
  48. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    Man your AO solution looks sharp! I love how yours shows some very nice contrast and color (important in lighting).
     
  49. Kubold

    Kubold

    Joined:
    May 10, 2012
    Posts:
    359
    I would buy it in a heartbeat.
     
  50. RB_lashman

    RB_lashman

    Joined:
    Aug 15, 2013
    Posts:
    92
    who wouldn't? :p