This May Improve SSAO Performance

Discussion in 'Ideas and Suggestions' started by VirtualPenguinGaming, Jun 15, 2017.

  1. VirtualPenguinGaming

    VirtualPenguinGaming
    Expand Collapse

    Joined:
    Jun 15, 2017
    Messages:
    26
    Hello, BeamNG.drive players!

    One thing I was searching up was about how to optimize SSAO in BeamNG, but I couldn't find anything very effective, but I did find one thing which is to do with the game files.
    Link:
    https://www.garagegames.com/community/blogs/view/21022

    It's a thing called SSAO2. I haven't tried it or anything but maybe giving that a try would be good. It is supposed to work with Torque3D. SSAO seems to take a big hit on my framerate (about 15 fps lower).
     
    • Agree Agree x 2
  2. AllTerrainOutlaw

    AllTerrainOutlaw
    Expand Collapse

    Joined:
    Feb 7, 2015
    Messages:
    375
    first off this is not a suggestion.

    next off try posting it it another thread like off topic or general discussions.
     
  3. VirtualPenguinGaming

    VirtualPenguinGaming
    Expand Collapse

    Joined:
    Jun 15, 2017
    Messages:
    26
    This is a suggestion for SSAO improvement.
     
    • Agree Agree x 3
  4. BombBoy4

    BombBoy4
    Expand Collapse

    Joined:
    May 16, 2015
    Messages:
    1,601
    Wat? This is actually a good idea, not sure where you came from.
     
    • Agree Agree x 3
  5. AllTerrainOutlaw

    AllTerrainOutlaw
    Expand Collapse

    Joined:
    Feb 7, 2015
    Messages:
    375
    my bad it didnt sound like a suggestion.
     
  6. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Thought id chip in after 2 years!

    Ive tried it on the Techdemo and its way superior to the ingame ssao. No weird artifacts (non-AA edges around the ssao), way more crisp, doesnt look weird like the ingame ssao which can look like a black cloud rather than shadows, and so on.

    I hastingly tried it for 0.16 but no luck yet. Ive replaced the COLOR code in the files with SV_TARGET0, put in a few '_' where seemed to be needed BUT it makes use of torque.hlsl where BeamNG use bge.hlsl and simply replacing the code didnt work so i might look into what specific part is used.
     
    • Agree Agree x 1
  7. r1pzor

    r1pzor
    Expand Collapse

    Joined:
    Dec 2, 2017
    Messages:
    86
    I cannot look at this website due to my computer blocking it from being an "Unsafe website" but I do agree this would be a great idea for Performance improvements. I like it
     
  8. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Heres the text. Ive visited the page without problems, bypassing the warning.

    "Improving SSAO for Torque3D
    by Ryan Mounts · 05/17/2011 (9:47 am) · 32 comments

    Download Updated 5/21/11. See post #24 for details.

    Although the SSAO implementation has improved through the Torque3D iterations, it still suffers from a few problems.

    First, and arguably the most undesirable artifact, is its lack of temporal fidelity (consistency from frame to frame through time). The ambient occlusion does not seem to stick to the surface because of a very low frequency noise, which is a result of the next issue.

    Second is a lack of spatial accuracy. The AO is calculated on a half-resolution buffer (the down-sample is equivalent to a blur operation when up-sampled again), then the result goes through two more blur passes. The intention is to smooth the AO result, but the practical affect is to reduce the ability to achieve detailed, precise occlusion while inadvertently exaggerating other undesired effects like haloing (the AO disappears prematurely near surfaces of differing depths). In addition, the blur passes are fairly expensive.

    Third, the controls for the current SSAO are somewhat cumbersome. There are a lot of parameter sets to tweak (general, near, and far), and some controls are not very intuitive. This makes getting the desired result more labor intensive.

    Fourth, it is slow. Enough said.

    The New Kid on the Block: SSAO2

    Okay the name is not very creative, SSAO2, but for simplicity's sake, that is what I'm calling this new implementation.

    It is basically a Torque3D PostFx implementation of this article at GameDev. The algorithm uses a view-space position buffer instead of a depth buffer, so I used this article to help convert the prepass depth into a view-space position buffer.

    The result is an improvement on all the problems discussed above: better temporal fidelity, better spatial accuracy, simplified controls, and better performance. The only downside is the AO is noisier (because I don't blur the result), but I find that this is much more visually appealing than a smooth AO that doesn't stick.

    Results

    Below are a few figures and numbers to illustrate some of the differences between the current SSAO and SSAO2.

    The Controls


    The Current SSAO


    The New SSAO2
    .

    The numbers indicate that SSAO2 is much more efficient than the current SSAO. In fact, they indicate that performing full-resolution SSAO2 should be faster than the low quality SSAO. In practice, however, full-resolution SSAO2 performance is basically equivalent (or slightly slower) than the low quality SSAO. One drawback to SSAO2 that can hopefully be addressed is a larger performance hit when the camera is in close quarters. The current SSAO does not suffer from this, perhaps due to the separate handling of near and far AO calculations. Using SSAO2 at three-quarter or half resolution provides a substantial performance boost, but introduces some visual artifacts due to down-sampling.

    Take It for a Spin

    Images and numbers can't really provide the full picture, so try it out for yourself (ssoa2.zip). Unzip the package in your game folder. Doing so will overwrite these files in your /game/core/scripts/client/postFx folder:

    • default.postfxpreset.cs
    • postFXManager.gui
    • postFxManager.gui.cs
    • postFxManager.gui.settings.cs

    So if you have already modified these files for other purposes, I suggest merging the changes individually. All changes are marked by the tag "RDM SSAO".

    Navigate to the /game/core/scripts/client/postFx folder. You should now have three different SSAO effects here:

    • ssao.cs // the original effect
    • ssao2.cs // the new effect
    • ssao2_half_blur // a test effect, ssoa2 half-res with one blur pass

    Only one SSAO effect can be loaded at a time, so unfortunately you can't toggle between the two ingame. So remove the ".cs" extension from the ssao.cs file to keep it from getting loaded (delete any dso files, if necessary). Run Torque3D and load a level. From the console, type Canvas.PushDialog(PostFXManager). On the PostFXManager GUI, you should now have an SSAO2 tab. Enable it and play with the parameters. You can view the AO mask by typing ssao2VizPostFx.enable().

    To revert to a particular SSAO effect, simply add the ".cs" extension to the corresponding file above and remove the ".cs" extension from the other two SSAO files and restart Torque.

    I don't really like the blurred SSAO2 effect because it seems to worsen the down-sampling artifacts. I included it, though, so people could see some of the possibilities. Also, try changing the target scale in ssao2.cs to different sizes (must restart Torque). I would suggest these values:

    $SSAO2PostFx::targetScale = "0.5 0.5"; // Low quality
    // OR
    $SSAO2PostFx::targetScale = "0.75 0.75"; // Medium quality
    // OR
    $SSAO2PostFx::targetScale = "1.0 1.0"; // High quality

    Conclusion

    In closing, I should mention that I am not a shader expert by any means and have not attempted to optimize this code at all. I'm sure there is room for improvement. I'm also sure others could do a better job of quantifying the performance comparison of these shaders (please post any interesting findings here). As it stands, however, this seems to be a promising alternative to the current SSAO implementation. If anyone is able to improve upon it, I would only ask that you share it with all of us, as it has been freely shared with you."



    Ive attached the file too!

    The SSAO2 is from 2011 but JeffR just said, we're talking 9 years later, the 13th of june this year 8yes, a few days ago) that he would implement it in Torque3D 4.0 :)
    Id say it would be awesome to have in Beamng and it shouldnt (?) be hard to get up and running for those that want it. It looks way better than the ingame SSAO and JeffR mentioned in a post i came across, some 10 years ago, that the Torque3D SSAO (which BeamNG uses afaik) is very basic and incorrect.

    Ive managed to get it to load but the objects ingame just flickers when enabling SSAO2. Ill attach my modded files below.
    --- Post updated ---





    Ok so ive added my modded files, in the ssao2BNGWIP.zip

    Ive added one file, the postFx.cs from core/scripts/client/ where ive removed the loading of ingame SSAO.cs shader and added SSAO2.cs, since its mentioned in hte original post that it cant handle both but i havent tried it in BeamNG, might load both if both are there.

    Now, this is NOT working in any way and will go bananas if used but its intended in the future to be extracted into Documents/BeamNG/. Reason i added my files is for anyone with coding/shaders/Beamng PostFx knowledge to dig some more and maybe get it running.

    One thing that is good though is that the PostFxManager*-files seem to bring back the Bloom from the Tech Demo, its not giving that weird squares anymore. Will happily use that in my Alternative Lighting mods in the future.
     

    Attached Files:

    • Like Like x 3
  9. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Updated file, not working anything more than the last one.

    The original SSAO2 shader files has= #include "shadergen:/autogenConditioners.h" which im not sure what it does. May not be needed at all but is probably helping speed things up. Replaced that with reference to bge.hlsl but probably wont do the trick. Also tried replacing it with= #include "../../ShaderModelAutoGen.hlsl" from Torque3D 3.10 without success. That file does have very specific Torque3D referemces so didnt excpect anything else.

    Added torque.hlsl for comparison to bge.hlsl to see what is referenced to in \shaders\common\postFx\ssao2\ssao_pos_v.hlsl

    Basicly, dont know what im doing o_O
     

    Attached Files:

    • Like Like x 1
  10. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Just posting for those that wonder how it looks. First is without SSAO2, second is with. Exxagerated strength to make the effect obvious. No comparison with ingame SSAO but its more of a dark cloud, way less distinct IMO.
     

    Attached Files:

    • screenshot_00001.png
    • screenshot_00002.png
    • screenshot_00003.png
    • screenshot_00004.png
  11. Nicholes Dorey

    Nicholes Dorey
    Expand Collapse

    Joined:
    Oct 24, 2016
    Messages:
    42
    I followed you instructions and it didnt work help it gives me an gpu error when enable it
     
  12. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    As stated in my commenta your NOT supposed to install it, it will NOT work :)

    Delete the files youve unzipped/installed. Clear your cache and you should be good.
     
  13. Nicholes Dorey

    Nicholes Dorey
    Expand Collapse

    Joined:
    Oct 24, 2016
    Messages:
    42
  14. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Might need to give this another go now that lighting has seen an official update. Looking at the screenshots it does seem to give a better depth darkness, looking at the foliage/bush in the lower right screenshot. I find myself constantly trying to get that type of depth shading with the ingame "Far" ssao setting but cant quite get it to look good enough.
     
  15. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    I did find settings for SSAO2 in the default.postfxpreset in BeamNG but no other files or references so probably not on the way.
    I have come so far that the game doesnt flicker when enabling SSAO2 but nothing AO-related appears though so might need to dig some more. At this point it would be good if i knew shader coding.. :D
     
  16. Brother_Dave

    Brother_Dave
    Expand Collapse

    Joined:
    Aug 16, 2012
    Messages:
    1,662
    Heres what ive got so far. This is non-functional, I dont know what is missing or what should be named what to get this running but one of the files reference torque.hlsl which ive changed to bge.hlsl (BeamNGs corresponding file) but not sure if theres something missing in bge.hlsl for it to work or not.

    The zip is made to be extracted into the Documents/Beamng.drive-folder but as i said, nothing will happen other than that the SSAO2 will show up in the PostFx window as ive incooperated everything into its corresponding BeamNG files.

    Its based on the SSAO2.zip further up in this thread.
     

    Attached Files:

  17. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,686
    Both the game SSAO, and the one above, are based off really old and inefficient methods.
    I'm not sure it's worth spending any time trying to that to work, as it could be made obsolete by future updates.
     
    • Agree Agree x 2
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice