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

SSAO in Unity Free

Discussion in 'Works In Progress - Archive' started by Cyrien5100, May 24, 2014.

  1. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    Hi,
    After days of tweaking, testing, writing shaders... i finally got an SSAO effect working in Unity free.
    For now, the result is not perfect, there is halo, some artifact at the edge of the screen, but it looks good.
    I'm currently using a modified version of IndieEffects, and performances are not good currently (drop from 70 to 25 fps),
    so it need some optimizations.
    There is some limitations too : max far range is 50 (but i found a trick), there is a little banding, and a bug with skybox (for now).

    The method i use is Disk to Disk SSAO, which is an hybrid method between SSAO,HBAO and Disk AO.

    Here is some pics :

    No SSAO :
    $WSSAO1.jpg

    With SSAO :
    $WSSAO2.jpg

    No SSAO :
    $WSSAO3.jpg

    With SSAO :
    $WSSAO4.jpg

    AO only :
    $WSSAO5.jpg

    Tell me if you are interested in it ;)
     
  2. MichaelHF15

    MichaelHF15

    Joined:
    Mar 25, 2014
    Posts:
    50
    I am 500% interested in it. Looks FANTASTIC!
    Looking forward to final product here, will buy this :D
     
  3. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,608
    How's performance? What's the advantage over baking it?
     
  4. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    The advantage over baking it is it's in realtime. Performances are as i said, for now, not very good (because it uses ReadPixels).

    PS : Someone has an idea on how i can have a 16 bit depth buffer in Unity free ?
    Because for now i only have an access to a 8bit*2 depth buffer so only 0-512 range.
     
  5. GhostlyET

    GhostlyET

    Joined:
    Jun 12, 2013
    Posts:
    3
    Looks good hope to see more.
     
  6. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    Encode depth (32 bit float) into an ARGB32 texture before you read it back instead of just writing it to R. Unity has builtin functions for it if you look into UnityCG.cginc. Then decompress it on the CPU and voila 32 bit depth. Not that it's gonna be fast ;)
     
  7. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    166
    i want it :O
     
  8. Deleted User

    Deleted User

    Guest

    Looking great. I really like that large radius AO look, creates very nice gradients over surfaces.
     
  9. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    Are you sure i will have a 32 bit depth ? Because i think it's rather 8bit * 4 channel = 0-255 range * 4 = 0-1024 range = 10 bit.
    16 bit have a 0-65535 range.
     
  10. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    Well, if you store in linearly like that, yeah. You're basically converting the float to an integer, which is not want you want to do.
    Instead, use these functions to encode and decode the depth. They're taken straight from UnityCG.cginc, so you can just call EncodeFloatRGBA right away (naturally, presuming you're including UnityCG). Then just decode that into a float on the CPU using the decode function.

    Code (csharp):
    1. inline float4 EncodeFloatRGBA( float v )
    2. {
    3.     float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 160581375.0);
    4.     float kEncodeBit = 1.0/255.0;
    5.     float4 enc = kEncodeMul * v;
    6.     enc = frac (enc);
    7.     enc -= enc.yzww * kEncodeBit;
    8.     return enc;
    9. }
    10. inline float DecodeFloatRGBA( float4 enc )
    11. {
    12.     float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0);
    13.     return dot( enc, kDecodeDot );
    14. }
     
  11. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    I'm currently using EncodeDepthNormals , so 1 texture for both depth and normals. So it's 16 bit for each ?
    The problem i have for now is if i increase the far clip range over 50 (like 100 or 200), the ao effect is only visible for far objects but near doesn't have any ao on it.
    Based on what you say, it would not be a problem of depth precision.

    However here is a webplayer of what i have yet : https://dl.dropboxusercontent.com/s/w9oaujevoyuwp4e/SSAO_Webplayer.html
     
  12. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    Oh right, Unity's depth/normal texture is an ARGB32. Is there any way in Unity free to get depth into a 32 bit texture? I don't remember the exact limitations. Is it possible to create a R32 texture and render only depth via replacement shaders? If that's not possible, then I'm sorry I was wrong and I don't think it's possible to achieve greater precision in Unity free :p
     
    Last edited: May 27, 2014
  13. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    New webplayer : https://dl.dropboxusercontent.com/s/efsnnoeet9ikby3/SSAO_WebPlayerLabo.html
    Tell me how much FPS you have and you configuration please :) .

    Change Log :
    - Far clip increased to ~5000
    - Black halo are removed
    - Better looking SSAO
    - Problem with skyboxes solved

    There is only 2 things i have to do now, optimize the shader and make it to work for particles, trees and grass.

    If you have any comment, suggestion or tip, say it to me ;)
    $SSAO AO.jpg
    $SSAO With.jpg
    $SSAO Without.jpg
     

    Attached Files:

    Last edited: May 28, 2014
  14. Deleted User

    Deleted User

    Guest

    60 fps in webplayer. System specs: CPU FX-8350, GPU GTX 780 on Windows 7

    would like to get a standalone build if possible, to see performance at full resolution and highest Quallity settings
    EDIT: and if you do that please disable v-sync
     
  15. MichaelHF15

    MichaelHF15

    Joined:
    Mar 25, 2014
    Posts:
    50
    I'm getting 80 fps.
     
  16. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
  17. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    ASUS EP121
    Intel i5 (1st Gen Sandy Bridge)
    Intel HD Graphics (1st Gen Sandy Bridge)
    4 GB RAM
    64 MB Dedicated Video
    Windows 8.1 64 bit + current patches
    Chrome v35

    SSAO - 5 FPS
    !SSAO - 8 FPS

    Excellent work though.
     
    Last edited: May 29, 2014
  18. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @Goat: I got higher than that on mine, and it's a core i3! maybe a Win8 prob?
     
  19. FleshKnot

    FleshKnot

    Joined:
    May 4, 2014
    Posts:
    67
    I'm definitely interested for my interior designs on my current project.
     
  20. thetoxicuser

    thetoxicuser

    Joined:
    Jan 11, 2013
    Posts:
    34
    Only 1-3 fps decrease.
    - I average 44-47(sometimes jumps to 55 for a few seconds)

    running on a A8-6500 apu. with an r7 265 discrete graphics card installed

    -Great work!
     
  21. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Excellent work! I have a ton of things on my computer recording both sound and video and I'm still averaging about 65 fps.
     
  22. Ryan-Gatts

    Ryan-Gatts

    Joined:
    Sep 27, 2012
    Posts:
    54
    Well done work :) 80fps drops to 62fps with AO turned on.
    Nvidia Quadro 4000
     
  23. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    131
    40 FPS drops to 35 with my Intel G860 3GHz dual core and HD6450 GDDR5 2GB