Search Unity

SMAA for unity (subpixel morphological aliasing)

Discussion in 'Shaders' started by damonwall, Sep 19, 2013.

  1. damonwall

    damonwall

    Joined:
    Jan 22, 2013
    Posts:
    14
    Hey everybody!
    Based on http://www.iryoku.com/smaa/, i've made an implementation of this feature for unity. It works okay, just wanted to get your opinion. Still some work to be done (like stencil optimization), but this version is testible

    https://github.com/m10914/SMAA-Unity

    Waiting for your commentaries, guys!
     
    ksam2 likes this.
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Nice one! I tried to port it myself, but I kept getting wrong results.

    So, thanks! I'll test it out later.
     
  3. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    will test it some later, thanks)
     
  4. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    some problems with shader - some errors in compile of shader and it looks like this
    $smaaBug.jpg
     
  5. tabor

    tabor

    Joined:
    Nov 29, 2011
    Posts:
    42
    I am getting errors too but am excited to see it working!
     
  6. damonwall

    damonwall

    Joined:
    Jan 22, 2013
    Posts:
    14
    I'd like to fix everything for your case, if you just send it to me!
    It worked fine for me on test cases, what could possibly go so wrong?)
     
  7. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    can you sent your test scene?
    problems with compiling of shaders i show at screenshot, maybe console show other errors, i dont remember.
    and i use Unity 4.2.0 pro version. tryed dx9 and dx11 rendering.
     
  8. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Any news on this? I get the same result as CTPEJIOK22 . Not working.
     
  9. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    its a pity. i checked console output - only two errors about 94 line and 725, as at screenshot.
    i found ine solution - using smaa injector, sometimes it work. http://mrhaandi.blogspot.ru/p/injectsmaa.html
    but its interesting to see smaa shader directly in unity
     
  10. mangax

    mangax

    Joined:
    Jul 17, 2013
    Posts:
    336
    same error as CTPEJIOK22 ..
     
  11. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
    CTPEJIOK22, Strange. I have it shows:
    $4FbGoCX.png $SMAA2.PNG
    Unity v. 4.2.1f4.

    But script still does not work properly. If I switch the state=3 little effect visible on the foliage of trees.
     
    Last edited: Oct 3, 2013
  12. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Didn't you forget to set a few textures over there? I know Area and Search tex are included with SMAA source on their page, but I'm not sure about the others
     
  13. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    heh) maybe its a key. downloaded 2 textures, will test others.
     
  14. damonwall

    damonwall

    Joined:
    Jan 22, 2013
    Posts:
    14
    Guys, areatex and searchtex are generated programatically in AreaTex and SearchTex classes!!! no need to download anything!!! =)

    I added to git my own test scene, in which there's only a sphere (+properly configured effect). It should work properly, as i think.
    There was another one, clone of smaa's DirectX demo sample, if you'd like that, i can add it too.
     
  15. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
  16. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
    I noticed looking through the shader:
    I switched the camera to 1280x720 and then shader works! :D

    $SMAA.PNG

    But shader is dependent on the resolution :(

    In any case, thanks damonwall!
    I have the idea as it can be solved.
     
    Last edited: Dec 28, 2013
  17. Deleted User

    Deleted User

    Guest

  18. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Code (csharp):
    1. #define SMAA_RT_METRICS float4(1.0 / _ScreenParams.x, 1.0 / _ScreenParams.y, _ScreenParams.x, _ScreenParams.y)
     
  19. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
    Thanks! Much easier than I thought.
     
  20. damonwall

    damonwall

    Joined:
    Jan 22, 2013
    Posts:
    14
    A-a-ah, here's the explanation, why this shader worked fine on my computer, but it didn't on others =) Pixel-perfect algorythm, huh =) Thanks much!
    I've made a fixed version, based on your fork. Thank you, i hope now someone will find it useful)

    Btw, if someone interested, this version will be used in our game "VoidExpanse", details can be found here: http://atomictorch.com
     
    Last edited: Jan 2, 2014
  21. Soumya

    Soumya

    Joined:
    Jan 14, 2013
    Posts:
    8
    Thanks a ton for this, this is far better than the AA solutions that come with Unity.

    Thanks a lot :D
     
  22. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Hmm, just tried throwing this in my scene and weirdly it turns entirely black (with exception to the NGUI gui I have up). Does this conflict with HDR/Linear/Deferred? Have you tested this in Unity 4.3.3 by chance?

    Thanks!
     
  23. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
    Works for me without problems. Need more details. State 3 must be set.
     
  24. xenius

    xenius

    Joined:
    Sep 30, 2010
    Posts:
    523
    Derp, there we go. Setting State 3 made everything work. Looks wonderful. What's the perf cost of this compared to FXAA roughly? I really like what it does.
     
  25. Soumya

    Soumya

    Joined:
    Jan 14, 2013
    Posts:
    8
    Hey this is awesome! Everything works, but when I try to build the game, it give 2 errors
    , $Capture.PNG

    Please help :(

    PS : Unity v4.3.2
     
  26. EvilFox

    EvilFox

    Joined:
    Jul 23, 2013
    Posts:
    83
  27. Soumya

    Soumya

    Joined:
    Jan 14, 2013
    Posts:
    8
  28. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    @damonwall: I was about to make my own port when I found yours. Thanks a lot for your hard work !

    If anyone's interested, I've forked the original code and make a few updates / enhancements / bug fixes.

    You'll find it here : https://github.com/Chman/uSMAA (see the commit history for a proper changelog).
     
  29. CTPEJIOK22

    CTPEJIOK22

    Joined:
    Sep 4, 2013
    Posts:
    85
    thank you)
     
  30. Simon_says

    Simon_says

    Joined:
    Oct 19, 2013
    Posts:
    141
    Hello, I'm using MSAA together with SMAA(from here: https://github.com/Chman/uSMAA ) and I have the flip problem, could someone give some details on how to fix it? I've tried editing SMAA shader from the link above but I always got errors since I'm not much into coding shaders.

    I've tried putting this in all vertOUT vertex:

    #if UNITY_UV_STARTS_AT_TOP
    OUT.offset1.xy = IN.texcoord;
    if (_MainTex_TexelSize.y < 0)
    OUT.offset1.y = 1-OUT.offset1.y;
    #endif
     
  31. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    @Simon_says: why would you use two AA solutions together?! that sounds like overkill... o_O
     
  32. DoPie

    DoPie

    Joined:
    Jun 20, 2013
    Posts:
    64
    SMAA for unity is that supported also on Mobile Devices?
     
  33. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    I wouldn't even think about it. It could work, but the performances would be quite bad.
     
  34. Jefemcownage

    Jefemcownage

    Joined:
    May 29, 2012
    Posts:
    8
    How do you enable super sampling?