Nasty SSAO bug

kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
edited October 2012 in Technical Support
<div class="IPBDescription">with suggested solution</div>SSAO has rather ugly appearance now, there is the worts cases:
medium:
<a href="http://steamcommunity.com/sharedfiles/filedetails/?id=105663419" target="_blank">http://steamcommunity.com/sharedfiles/file...s/?id=105663419</a>
high:
<a href="http://cloud-2.steampowered.com/ugc/937007313307772556/4A317B48413ABD0856ED3F52F11FB0E051E02AB2/" target="_blank">http://cloud-2.steampowered.com/ugc/937007...1FB0E051E02AB2/</a>

you can see black noise all over surfaces at center-to-top

also, random texture in shader produces pretty distracting patterns on the screen.


i tried to fix that by adding normal parameter to ssao shader, here are the results:
medium, now better than high was with old shader:
<a href="http://cloud-2.steampowered.com/ugc/937007313307769067/C33BF4282C33B5B44C6A13198C03D94044C7337E/" target="_blank">http://cloud-2.steampowered.com/ugc/937007...03D94044C7337E/</a>
high, much better:
<a href="http://cloud-2.steampowered.com/ugc/937007313307775030/1D851BE42F21E6797C159FC8FE1D1C808169F062/" target="_blank">http://cloud-2.steampowered.com/ugc/937007...1D1C808169F062/</a>


I tested this for a while on different maps and found no graphical problems with that modification.
hope UWE will consider this fix.


here is the diff file for shader:
----------------

--- D:/steam/steamapps/common/Natural Selection 2/core/renderer/AmbientOcclusion.fx Wed Oct 31 00:11:25 2012
+++ D:/AmbientOcclusion.fx Wed Oct 31 00:23:36 2012
@@ -321,7 +321,13 @@
if (delta >= minO)
{
float d = 1 - min((delta - minO) / (maxO - minO), 1);
- obscurance += pow(d, obscuranceFalloff);
+
+ //more (closer, stronger) ssao -> more impact from normals
+ //more close normals -> weaker ssao
+ half3 testNormal = GetNormal( texCoord );
+ float cn = 1.0 - d*dot(vsNormal, testNormal);
+
+ obscurance += cn*pow(d, obscuranceFalloff);
}

}

----------------
the idea about that change is to reduce noise on flat surfaces, something like that was done in:
<a href="http://www.gamerendering.com/2009/01/14/ssao/" target="_blank">http://www.gamerendering.com/2009/01/14/ssao/</a>
also, maybe downsample 2x and than upsampling again( or just add more blur) would be great to reduce impact from noise texture

PS.
Great engine! it was a pleasure to work with all that on-the-fly modifications!
Would be great if you consider this too:
<a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=122327" target="_blank">http://www.unknownworlds.com/ns2/forums/in...howtopic=122327</a>


P.P.S
speed update for shader
<a href="http://www.unknownworlds.com/ns2/forums/index.php?s=&showtopic=122475&view=findpost&p=2003420" target="_blank">http://www.unknownworlds.com/ns2/forums/in...t&p=2003420</a>

Comments

  • Mordecai WalfishMordecai Walfish Join Date: 2012-10-30 Member: 164803Members
    I noticed how nasty ssao looked in the game, no matter what setting I had it on, because of the weird noise that was visible in many places in the map.

    That looks much better on high with the settings you have.. is there a way to implement that in my game also?
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    <!--quoteo(post=2002015:date=Oct 30 2012, 07:50 PM:name=Mordecai Walfish)--><div class='quotetop'>QUOTE (Mordecai Walfish @ Oct 30 2012, 07:50 PM) <a href="index.php?act=findpost&pid=2002015"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I noticed how nasty ssao looked in the game, no matter what setting I had it on, because of the weird noise that was visible in many places in the map.

    That looks much better on high with the settings you have.. is there a way to implement that in my game also?<!--QuoteEnd--></div><!--QuoteEEnd-->

    yes, you need to modify your SSAO shader effect file.
    diff lines are pretty self-explanatory, you might need to read all shader file to get the whole idea though.
  • DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
    Really nice! Thank you. This has also been bothering me for a while but I'm no shader programmer. :)
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    made some performance tests with new shader:

    high setting:
    usual play:
    from 115 to 87 fps, 25% performance hit

    face-to-wall:
    from 84 to 45 fps, 50% performance hit.

    medium:
    usual:
    from 120 to 120, no hit

    face-to-wall:
    from 120 to 95, 20% hit


    for some reason when you stick your face into aome walls, high SSAO gets severe performance drop.
    any ideas of this?
  • IronHorseIronHorse Developer, QA Manager, Technical Support & contributor Join Date: 2010-05-08 Member: 71669Members, Super Administrators, Forum Admins, Forum Moderators, NS2 Developer, NS2 Playtester, Squad Five Blue, Subnautica Playtester, Subnautica PT Lead, Pistachionauts
    edited October 2012
    <strike>Its a known issue with how AO is setup currently.</strike> See the developer's answer below, Steverock
    MAJOR props on the refined version, btw! :-D
  • SteveRockSteveRock Join Date: 2012-10-01 Member: 161215Members, NS2 Developer, Subnautica Developer
    <!--quoteo(post=2003259:date=Oct 31 2012, 12:52 PM:name=kikaxa)--><div class='quotetop'>QUOTE (kikaxa @ Oct 31 2012, 12:52 PM) <a href="index.php?act=findpost&pid=2003259"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->made some performance tests with new shader:

    high setting:
    usual play:
    from 115 to 87 fps, 25% performance hit

    face-to-wall:
    from 84 to 45 fps, 50% performance hit.

    medium:
    usual:
    from 120 to 120, no hit

    face-to-wall:
    from 120 to 95, 20% hit


    for some reason when you stick your face into aome walls, high SSAO gets severe performance drop.
    any ideas of this?<!--QuoteEnd--></div><!--QuoteEEnd-->


    Hey there,
    It's because the samples are more spread out when you're closer, so there's less cache-coherence with the lookups. We are going to fix this soon by simply limiting the sample radius.

    And thanks for your fix! We will discuss it soon - the performance hit is a lot (due to per-sample normal lookup), but it does look better. Now that 1.0 is out, we should have more time to focus on fixing the SSAO. Cheers!
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    edited October 2012
    <!--quoteo(post=2003288:date=Oct 31 2012, 01:00 PM:name=SteveRock)--><div class='quotetop'>QUOTE (SteveRock @ Oct 31 2012, 01:00 PM) <a href="index.php?act=findpost&pid=2003288"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Hey there,
    It's because the samples are more spread out when you're closer, so there's less cache-coherence with the lookups. We are going to fix this soon by simply limiting the sample radius.

    And thanks for your fix! We will discuss it soon - the performance hit is a lot (due to per-sample normal lookup), but it does look better. Now that 1.0 is out, we should have more time to focus on fixing the SSAO. Cheers!<!--QuoteEnd--></div><!--QuoteEEnd-->

    huh, cache makes sense...

    yep, it's pretty big hit even for my gtx 670.
    maybe use it like ultra-high setting), also, patched medium seems like competitor to old high
  • SteveRockSteveRock Join Date: 2012-10-01 Member: 161215Members, NS2 Developer, Subnautica Developer
    <!--quoteo(post=2003351:date=Oct 31 2012, 01:24 PM:name=kikaxa)--><div class='quotetop'>QUOTE (kikaxa @ Oct 31 2012, 01:24 PM) <a href="index.php?act=findpost&pid=2003351"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->huh, cache makes sense...

    yep, it's pretty big hit even for my gtx 670.
    maybe use it like ultra-high setting), also, patched medium seems like competitor to old high<!--QuoteEnd--></div><!--QuoteEEnd-->

    Hmm I do agree about the patched medium. No promises, but we will give it a shot and see if we can roll it out next patch! Thanks a ton, sir.
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    huh, was good idea about limiting radius, got 15-20% performance boost for each shader
    here are the results with this additional fix, for both old and patched ssao:


    high setting:
    usual play:
    from 110 to 100 fps, 10% performance hit

    face-to-wall:
    from 110 to 70 fps, 35% performance hit.

    medium:
    usual:
    from 120 to 120, no hit

    face-to-wall:
    from 120 to 110, 10% hit



    as i thought, simple
    if() continue;
    was terribly slow, so simple hack gave full speed to shader


    patch, for both old and new shaders:
    -------------

    --- D:/AmbientOcclusion - old.fx Thu Nov 1 01:27:30 2012
    +++ D:/AmbientOcclusion.fx Thu Nov 1 01:24:43 2012
    @@ -315,6 +315,10 @@
    texCoord.x = ssPosition.x * 0.5 + 0.5;
    texCoord.y = 1.0 - (ssPosition.y * 0.5 + 0.5);

    + half txDiff = distance(input.texCoord, texCoord);
    + if (txDiff >= 0.2)
    + texCoord = input.texCoord; //continue;
    +
    half testDepth = tex2D(depthTextureSampler, texCoord).r;

    float delta = vsTestPosition.z - testDepth;

    -------------
  • SteveRockSteveRock Join Date: 2012-10-01 Member: 161215Members, NS2 Developer, Subnautica Developer
    OK, after some serious debugging, we've resolved the ceiling artifacts. It was a more fundamental issue related to half-pixel offsets (thanks, DX9).

    We've decided to not use the normal-weighting, since it removes AO on the rich infestation blobs, which looks kinda cool.

    Anyway, thanks for pointing this out and getting us to fix it :)
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    edited November 2012
    <!--quoteo(post=2004781:date=Nov 1 2012, 10:32 AM:name=SteveRock)--><div class='quotetop'>QUOTE (SteveRock @ Nov 1 2012, 10:32 AM) <a href="index.php?act=findpost&pid=2004781"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->OK, after some serious debugging, we've resolved the ceiling artifacts. It was a more fundamental issue related to half-pixel offsets (thanks, DX9).

    We've decided to not use the normal-weighting, since it removes AO on the rich infestation blobs, which looks kinda cool.

    Anyway, thanks for pointing this out and getting us to fix it :)<!--QuoteEnd--></div><!--QuoteEEnd-->

    oh my god, THAT thing...

    well, at least there is speedup patch)
    thanks for fix. hope to see it soon ingame.

    edit: can't notice ssao on rich infestation, unpatched. you gonna buff ssao strength?
  • Mordecai WalfishMordecai Walfish Join Date: 2012-10-30 Member: 164803Members
    Awesome work, both of you, and thanks!!
  • SteveRockSteveRock Join Date: 2012-10-01 Member: 161215Members, NS2 Developer, Subnautica Developer
    <!--quoteo(post=2004924:date=Nov 1 2012, 12:12 PM:name=kikaxa)--><div class='quotetop'>QUOTE (kikaxa @ Nov 1 2012, 12:12 PM) <a href="index.php?act=findpost&pid=2004924"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->oh my god, THAT thing...

    well, at least there is speedup patch)
    thanks for fix. hope to see it soon ingame.

    edit: can't notice ssao on rich infestation, unpatched. you gonna buff ssao strength?<!--QuoteEnd--></div><!--QuoteEEnd-->

    Hmm it should be noticeable. Have you tried switching back and forth? You can bind one key to "r_ao medium" and another to "r_ao off" to do so.
  • kikaxakikaxa Join Date: 2012-08-19 Member: 155845Members
    <!--quoteo(post=2005540:date=Nov 1 2012, 05:29 PM:name=SteveRock)--><div class='quotetop'>QUOTE (SteveRock @ Nov 1 2012, 05:29 PM) <a href="index.php?act=findpost&pid=2005540"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Hmm it should be noticeable. Have you tried switching back and forth? You can bind one key to "r_ao medium" and another to "r_ao off" to do so.<!--QuoteEnd--></div><!--QuoteEEnd-->

    yeah, but effect is so minor compared to ssao in room corners, 95% infestation is same without ssao.

    new version looks good, there is only minor problem left
    blur supposed to completely cancel noise texture effect, so either there is not enough blur, or noise texture has too low frequency.
    i think, it should be freq(noise) <= 1/(2*blur size)
Sign In or Register to comment.