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

[FREE] Subpixel Morphological Antialiasing (SMAA)

Discussion in 'Assets and Asset Store' started by Chman, May 4, 2015.

  1. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    Looking at the C# script... I can just comment the code out...
     
  2. Stormbreaker

    Stormbreaker

    Joined:
    Aug 15, 2012
    Posts:
    161
    Chman, any update on the SSAA?
     
    srmojuze likes this.
  3. srmojuze

    srmojuze

    Joined:
    Mar 18, 2013
    Posts:
    127
    Very nice Chman, thanks much. This is a (tweaked) Republique Tech Demo by Camoflaj screen with your SMAA. Also "Pseudo-SuperSample AA" by capturing at 3K and then downscaled manually.

    Question Chman, what is the parameter to tweak if I want more "softness" or "bluriness"?

     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Not sure this is any good for mobile :p
     
    fakegood and punk like this.
  5. Jeff_B

    Jeff_B

    Joined:
    Mar 12, 2014
    Posts:
    5
    Another "thank you" for your awesomeness.
     
  6. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    1,115
    Had to login and leave a "thank you". This is definitely going into my project.
     
  7. VISIONSBOX

    VISIONSBOX

    Joined:
    Nov 7, 2014
    Posts:
    14
    I tried the different presets in the Effects package of Unity's standard assets. I think the DLAA preset is very good at removing those specular aliasing artifacts. Unfortunately it isn't very good at classic anti-aliasing. Combining DLAA with your SMAA works really well…
     
  8. wetcircuit

    wetcircuit

    Joined:
    Jul 17, 2012
    Posts:
    1,409
    Wow! This has fixed my stray white pixels. Thank you for this!
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'd imagine it's an option to go with forward rendering and hardware MSAA 8x if you're in a position where its necessary to stack post AA. Worth a try at least.
     
    twobob likes this.
  10. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    I'm most likely missing something very obvious, but I can't get it to run. The Shader variable is never initialized, meaning the SMAA script can't run - however, in your custom inspector implementation, you hide the property so clearly you're not meant to set the shader manually in the inspector. Help?
     
  11. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    The Shader variable should be set by default unless something went wrong when you imported it (don't forget the meta files!).

    Select /SMAA/Scripts/SMAA.cs and make sure Shader, Area Tex and Search Tex are set in the inspector. If none are set it probably means you didn't copy the meta files (so Area/Search textures import settings won't be set either and the effect won't work correctly anyway). You're better off deleting the SMAA folder and re-import it.

    If Shader is set... Compilation probably failed. Select /SMAA/Shaders/SMAA.shader and look for errors in the inspector.

    Finally, only use this on Unity 5+ as it won't work with Unity 4 :)
     
  12. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    Aah, the meta files, that's it! I manually placed the scripts and shaders in my own folder structure instead of copying the entire SMAA folder as it is. It's working brilliantly now. Thanks!
     
  13. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Always, always copy meta files :) Cross-references and import settings are stored in these files, so...
     
    Thomas-Mountainborn likes this.
  14. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    Big thanks to Cham for the asset!

    I have a question though. The project I'm working on has a cel-shaded style, which means that every GameObject has an outline. Now, when I apply SSMA, I loose all the outlines for my objects. I tinkered with the settings but it's either the anti-aliasing or the outlines. Is there any way to keep the outlines while using SMAA?
     
  15. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    How are the outlines applied ? Geometry ? Image effect ?
     
  16. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    They're applied on the shader of the material of the object.
     
  17. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Is a custom shader or one from the asset store or wiki or something ?
     
  18. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    It's this one.

    http://wiki.unity3d.com/index.php/Lighted_Bumped_Outline

    Although it is tweaked because I'm using an orthographic camera and I was only getting the outline when using the perspective one. This line that I changed was...

    Code (CSharp):
    1. o.pos.xy += offset * o.pos.z * _Outline;
    .. To this

    Code (CSharp):
    1. o.pos.xy += offset * _Outline;
    Thanks in advance :)
     
  19. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Just tried it, it works for me in perspective and orthographic (with your changes) with OpenGL, DX9 and DX11. The only thing I had to do (aside from fixing an unrelated DX11 bug in your shader) was to make the _Outline range larger than the default because it was way too thin on my scene (with or without SMAA). SMAA is a post-processing effect that takes place after everything has been rendered so I see no reason why it would remove the outlines of an object...

    What are your SMAA settings ?
     
  20. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    I'm using Luma in High quality and with no predication. But I think I've found out what was wrong :p

    As you said, my outline was very thin. And, as the objects that were cel-shaded were reasonably far away from the camera, the algorithm, when correcting the outline, was basically making it practically invisible. So, by increasing the outline width, everything works fine!

    Btw, could you PM me with the DirectX11 bug in the shader? Thanks in advance!
     
  21. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Can't send you a PM, the forum won't let me (maybe you disabled it ?).

    The DX11 fix is quite basic. Around line 25 :
    Code (CSharp):
    1. half3 ramp = tex2D(_Ramp, float2(diff)).rgb;
    Should be :
    Code (CSharp):
    1. half3 ramp = tex2D(_Ramp, float2(diff, diff)).rgb;
    :)
     
    Situacao likes this.
  22. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    Oh, I had already fixed that, but I totally forgot to mention it. Thanks again and sorry for the off-topic!
     
  23. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    Yeah I am getting the same thing:

    Code (csharp):
    1.  
    2. GLSL shader load error (stage 2 shader 95):
    3. ERROR: 0:135: Incompatible types (bvec2 and bool) in assignment (and no available implicit conversion)
    4. ERROR: 0:250: Incompatible types (bvec2 and bool) in assignment (and no available implicit conversion)
    Also I don't like the folder structure of this thing. Shouldn't this all go into Plugins/Editor? And why do I have to copy the .meta files? Which are usually invisible by the way.

    Otherwise great asset, thank you.

     
  24. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Yeah unfortunately this error message isn't helpful as it points to the shader code generated by Unity (looks like a bug in the CG -> GLSL transcompiler). The error does go away when using the new OpenGLCore driver (Unity 5.1+) instead of OpenGL2, maybe try that ?

    It's entirely self contained, what's not to like ? :) It's open source, move the files around if you don't like the way it is, as long as editor classes stay in an Editor folder.

    Because that's how Unity works with version control. Feel free to delete the meta files and link the references afterward if you prefer. Or just set them as invisible once copied.
     
    Last edited: Sep 29, 2015
  25. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
  26. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    That's usually not an AA artefact, it's usually textures not having enough padding on some textures, or bad uv . You shouldn't ever need to antialias to get rid of white bits. That's just avoiding the real problem I think.

    if using speedtree try updating, they had issues with older trees.
     
  27. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Without AA there is no white dots. Default unity AA is what causing them.
     
  28. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    I had this issue a while ago when using Unitys' AA. The quality settings AA. Caused the artifacts when there was a shadow behind. The treecreator shader was causing the problem but the AA made it visible. Here was my question:

    http://answers.unity3d.com/questions/611917/white-pixels-along-tree-creator-trees.html#answer-936342

    Think Lars helped me out on a conversation so I posted the answer. The answer though was for a problem with the shadow texture in Deferred rendering. I found out later the AA issue was different.

    So when testing and using Unitys' quality settings AA in forward rendering the artifacts are still there. So it is still a problem. Though the treecreator shader has many other more severe problems.
     
  29. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Oh I see. the artefacts are *caused* by AA in this case. Problems can happen with fixed function antialiasing and modern engines. I'm not sure how to get around it :/
     
  30. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,526
    I am not using it anyway. Prefer to just use this SMAA. Works amazing.
     
  31. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058

    Thanks for this.
     
    KRGraphics and Gua like this.
  32. Funnybob

    Funnybob

    Joined:
    Jan 26, 2016
    Posts:
    7
    Newbi question here. The instructions says to drop the `SMAA` folder in your project. Where in the project? I tried many places and the only place I could see the option in the Component menu was in the Assets folder. So I assume it's ok. Then I selected the camera, went to the Component -> Image Effects -> Subpixel Morphological Antialiasing menu. SMAA (Script) appeared in the camera inspector but it makes no changes what so ever. I tried to turn off antialiasing in the Project settings, quality because I thought it could get in conflict. Nothing. So how can I make this to work? Thanks! :)
     
  33. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Yep, always drop things into the Asset folder (or a sub-folder inside the Asset folder, that's where all the project data goes).
    First of all, if you can use MSAA ("Antialiasing" in the "Quality Settings") use it ! Unless you have a lot of specular aliasing in your game MSAA will be better than SMAA anyway. SMAA is mostly for people working with HDR or the Deferred rendering path (where you can't enable MSAA) or people that experience a lot of specular aliasing because of their material setup and light rig.

    As for why you don't see any change after adding SMAA and disabling MSAA... Are you sure the effect is turned on in the inspector ? Any error in the console ? Could you post a screenshot of the GameView with SMAA ?
     
    Heykinox and FPires like this.
  34. Funnybob

    Funnybob

    Joined:
    Jan 26, 2016
    Posts:
    7
    Ok, it's working now. When I play the game and turns it on and off I can see it now. :)
     
  35. JoeyDh

    JoeyDh

    Joined:
    Dec 6, 2012
    Posts:
    2
    Just downloaded it from github to my Unity 5.3.3 project and attached the MSAA script to my camera. When I play the scene the script gets disabled and when I try to re-enable it I get the following error:

    UnassignedReferenceException: The variable Shader of SMAA has not been assigned.

    This variable is not visible as a property of the script in the editor so I cannot set it. I am currently trying to fix this issue, but if there is anyone who have had the same issue and/or knows a fix I would love to hear it =]
     
  36. Thomas-Mountainborn

    Thomas-Mountainborn

    Joined:
    Jun 11, 2015
    Posts:
    501
    You're supposed to copy the entire SMAA folder, including its meta files, not just the scripts and shaders. The info in the meta files will set the Shader variable.
     
  37. JoeyDh

    JoeyDh

    Joined:
    Dec 6, 2012
    Posts:
    2
    Thanks for the reply,

    That's exactly what I did earlier.. I deleted the whole SMAA folder, downloaded it again and put it in my assets folder again and this time it magically worked. Anyway again thanks!
     
  38. Kilito

    Kilito

    Joined:
    Jul 8, 2013
    Posts:
    1
    Hey! First of all, I want to thank you for sharing this.

    I'm getting a shader compile error on SMAA.shader:
    Code (CSharp):
    1. failed to open source file: 'SMAA.cginc'
    The thing is that this file is in the same folder as SMAA.shader and I copied all the .meta files and everything, what can I do?

    Thank you!

    Edit: Nevermind, I fixed it by just rewritting the line #include "SMAA.cginc" in the SMAA.shader file.
     
    Last edited: May 13, 2016
  39. Chman

    Chman

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    721
    Next time simply right-click the SMAA folder and choose "Reimport" :)
     
  40. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577
    @Chman what is "predication"?
     
  41. twda

    twda

    Joined:
    Oct 25, 2012
    Posts:
    111
    Your comment was on a different thread, but can you tell me where you read that Unity isn't going to support SMAA? Also, could you give me more insights in which way SMAA isn't going to be supported? Your reply was a bit short. Thank you!
     
    Gua likes this.
  42. Beloudest

    Beloudest

    Joined:
    Mar 13, 2015
    Posts:
    247
    @Chman I've recently downloaded the latest SMAA from git and it looks great in Editor. If I build for PS4 and use Single Pass it breaks badly. I'm using 5.5.3p3 I'm just wondering if these AA shaders are meant to work in Single Pass mode and for PS4? Thanks.
     
  43. Adam-Sowinski

    Adam-Sowinski

    Joined:
    Oct 25, 2013
    Posts:
    129
    @Chman with new Unity render pipeline architecture is it possible to implement SMAA x4?
     
  44. Davood_Kharmanzar

    Davood_Kharmanzar

    Joined:
    Sep 20, 2017
    Posts:
    411
    seems that does not working on unity 2018 :/
     
  45. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577
  46. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
  47. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    hopeful and Gua like this.
  48. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    Click on the green "Clone or download" button and choose one of the things?!
    "Download ZIP" works fine. Then, extract the zip and put the SMAA folder into
    your Unity project's "Assets" folder :)
     
  49. ikemen_blueD

    ikemen_blueD

    Joined:
    Jan 19, 2013
    Posts:
    341
    The new code of SMAA is integrated deeply into the new Unity Post-Processing stack, so unless @Chman decides to give it an update. It would be risky to just cut and paste new code to the existing old version.
     
  50. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    I think I just heavily misread your previous posting. Argh... Sorry! Forget what I said ^^
    I'm with you, though... Would be cool to see the SMAA integration from the PPS as a standalone version.
     
    ikemen_blueD likes this.