Nasty SSAO bug
kikaxa
Join Date: 2012-08-19 Member: 155845Members
<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>
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
That looks much better on high with the settings you have.. is there a way to implement that in my game also?
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.
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?
MAJOR props on the refined version, btw! :-D
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!
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
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.
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;
-------------
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 :)
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?
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.
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)