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

FXAA - Fast Approximate Anti-Aliasing

Discussion in 'Assets and Asset Store' started by Diogo-Teixeira, Jul 17, 2011.

  1. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    Lately, we've been working on a tech demo to showcase our virtual texturing extension. After deciding to go for deferred rendering, we started looking for a good post-process anti-aliasing approximation technique.

    Not long after testing a few AA solutions, including NFAA and Unity's luminance edge blur, we ended up porting FXAA over to Unity. While it isn't without it's problems, it gave us very acceptable results:



    We figured that some of you might also have a use for this AA technique so we decided to share it.

    This FXAA package is available as a free download:
    https://dl.dropboxusercontent.com/u/14079608/FXAA3.unitypackage

    To make it work, simply:
    1) Install the package
    2) Select your camera object
    3) Add the component "Image Effects/FXAA"

    No need to tweak any parameters, just plug and play.

    I was called into attention that a FXAA Unity port has already been accomplished by gaustwick a while before. He's been comparing several techniques with FXAA and posted the results. Feel free to check out his thread.
     
    Last edited: Aug 28, 2013
    jason-fisher and inianbharathi like this.
  2. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Thanks Diego. I am still not decided if use forward, or deffered mode or combine both. Which problems have you find with this technique?
     
    Last edited: Jul 17, 2011
  3. Pedro Afonso

    Pedro Afonso

    Joined:
    Mar 13, 2011
    Posts:
    240
    thank you very much for this!

    looking awesome
     
  4. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    This image shows two major problems with this technique: long poly edges + loss of contrast in non-edge areas



    However, I'm sure these are universal issues in post-processing AA techniques. Overall the results are still very acceptable.

    The second issue might be fixable with a contrast enhancement filter.
     
    Last edited: Jul 17, 2011
  5. brianjkd

    brianjkd

    Joined:
    Feb 3, 2009
    Posts:
    143
    Thanks for sharing this is awesome!
     
  6. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Thanks, this really helped.

    I have some problem with deffered lightning in general, some shadows are blinking like disco when camera is moving. It can be solved by drastic increase of bias, but then majority of shadows is not connected to object. But this is probably Unity BUG, I am curious about promised shadows improvements in 3.4.
     
    Last edited: Jul 17, 2011
  7. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    Cheers, everyone.

    What type of light generates those problems you're having? Cascades help on directional lights. Using a short range might also help precision; this should be valid for all types.
     
  8. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347
    Wow. This looks great. From the images, there's really a lot of difference. :D
     
  9. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    This is impressive, with no tweaking required, I believe it looks better than the luminance edge blur, fantastic!
     
  10. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,051
  11. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Perhaps a stupid question, but bears asking - is this compatible with Unity Indie?
     
  12. chadchat

    chadchat

    Joined:
    Apr 5, 2008
    Posts:
    154
    Great stuff. Thx for passing it along.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Since Indie can't use deferred rendering, it's a moot point.

    --Eric
     
  14. Deleted User

    Deleted User

    Guest

  15. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    I completely missed it, to be honest. I usually just visit the Showcase forum.

    This one was based on 3_9. It's interesting to see how much it evolved.
     
  16. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Very nice! Thanks for sharing with us!
     
  17. SimonAlkemade

    SimonAlkemade

    Joined:
    Feb 4, 2009
    Posts:
    432
    does it work on iOS?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Again, there is no deferred rendering on iOS, so it's a moot point. Just use MSAA if you want anti-aliasing, you don't need a shader that emulates it.

    --Eric
     
  19. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    This new version might work (was excluding the gles target):
    http://dl.dropbox.com/u/14079608/FXAA3.unitypackage

    I don't have access to iOS hw so I can't confirm this. Let me know if that works for you, and how fast.
     
  20. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    MSAA and this FXAA combined creates some serious soft edges, they both work together so even if your not using deferred rendering, you can use this shader along with the built in AA in unity, it makes extremely soft edges.
     
  21. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    I'm getting particularly nice results in my particular scene with:

    #define FXAA_QUALITY__SUBPIX (2.0/4.0)

    I was not able to get it sharp enough with gaustwick's (sorry, I guess I couldn't work out how to tweak it). I take it "3.9" is the newer of the two, given the complexity of the code (and tweaking options).

    Thanks!!!
     
  22. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    Haven't even tried tweaking those parameters but sounds like it's worth a shot.

    3.11 seems to be the latest. I can update the package if you need it.
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Does it work with 3.4?
     
  24. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    It didn't compile, so I'm guessing no it wont.
     
  25. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    I've uploaded a package with FXAA 3.11 and support for Unity 3.4:
    http://dl.dropbox.com/u/14079608/FXAA3_11.unitypackage

    You'll need to install the Image Effects (Pro only) package first.

    The default results seem a bit fishy but I'll have a better look at it later. Quality parameters are now tweakable in the FxaaPixelShader() function call.
     
  26. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Stupid question, How to tweak it?
     
  27. Deleted User

    Deleted User

    Guest

    The main difference between mine and Diogo's shaders is that he has ported the "Quality" shader, and mine was the faster, but lower quality "Console" shader, which has fewer tweakables.

    When I have time I may update my version to 3.11, but I would use Diogo's, as the visual quality is higher, and much more controllable.
     
  28. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    I also have both versions included in 3.9 named Quality and Speed. I got rid of it recently because I noticed this Tim's comment in 3.11's code:
    gaustwick, I honestly didn't mean to step on your toes. BTW, I'm not even sure my latest is working correctly. It looks inferior to 3.9 and I even used all the default settings. Maybe it'd be worth you giving it a shot. I'll happily point the original post to your thread.
     
  29. Deleted User

    Deleted User

    Guest

    No, no - you're not stepping on my toes at all - I just wrote mine as an exercise (+ I wanted to see if I could get a bit more speed out of it).

    Tim's latest version (the quality shader) does seem a lot more fiddly, and does seem to be throwing a lot of the optimisations (free mults/divs by 4 and 8) out of the window. Also, I noticed that in the new console shader there are some odd instruction orders, which I suppose are to take advantage of instruction pairing on Nvidia GPUs, but I don't know what effect they'd have on other GPUs.

    He probably knows a lot more about GPU internals than me though :D
     
  30. Deleted User

    Deleted User

    Guest

    I just implemented the console version of 3.11 - I'm not posting it, as I was unimpressed - on my laptop it was 10-15x slower for no visual improvement from 3.8(which was the last one I did).

    Edit: The slowdown was my fault. It runs at about the same speed as 3.8 when I'm not an idiot.
     
  31. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    What about MLAA?
     
  32. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Yeah, and a pony!
     
  33. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    I take MLAA, you the pony?!
     
  34. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Someone was making an MLAA filter... I don't think they every released it though.

    Also, isn't FXAA3 supposed to be similar or better than MLAA anyway?
     
  35. Deleted User

    Deleted User

    Guest

    I've been looking at GPU implementations of MLAA, and at best it would be a three pass shader with an awful lot more texture calls than FXAA3. It would work on silicon (and is fast on AMD 6 series), but would probably be a lot slower in software, especially on older cards, low end cards or integrated graphics that are memory throughput limited.
     
  36. taumel

    taumel

    Joined:
    Jun 9, 2005
    Posts:
    5,292
    Dunno, maybe there are more cons speaking for FXAA3 but i find the idea behind MLAA interesting.

    Actually it is quite interesting comparing different AA techniques with each other. Wrote this somewhere else already but imaged based, in Unity, i do get the best results with FXAA1, it depends on the scene and situation, but in a whole maybe on pair with 4xMultisampling, sometimes the AA looks better, sometimes it forgets certain pixels or things get too much blurred. The FXAA3 implementation here on the forum looks significantly worse in my test scenario. 8xMultisampling is the best solution if you can life with forward rendering.

    What i generally dislike about the image based approaches is that global blur they tend to add to a scene. I'm not sure how much you can enhance this by tweaking the FXAA1/3 parameters for a given scene/game.
     
    Last edited: Aug 1, 2011
  37. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    591
    i got the message when i install this pack
    the type or namespace name 'PostEffectsBase'cloud not be found.Are you missing a using directive or an assembly reference ?
     
  38. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    You need to install the built-in package "Image Effects (Pro Only)". The one in the original post includes the necessary dependency. I removed it from the latest package to avoid redundancy.
     
  39. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
  40. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    591
    thank's for the quick answer
     
  41. mriegger

    mriegger

    Joined:
    Mar 28, 2009
    Posts:
    7
    Thank you so much for writing this Diogo!
     
  42. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    mriegger, Cheers! I just ported it, 99% of the credit goes to Timothy Lottes.
     
  43. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    What version is in Diogos port? 3.11 or 3.9?
     
  44. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    3.9 in the original post (direct link). Didn't change it to 3.11 because of quality concerns.

    3.11 available as a separate package (direct link)

    Both require "Image Effects (Pro only)" package to compile.
     
    Last edited: Aug 15, 2011
  45. lasco

    lasco

    Joined:
    Nov 12, 2009
    Posts:
    101
    Hi you people,

    First of all thanx to guys that kindly developp and share AA solutions.
    Though I experience some issues using these.


    Runing Unity 3.4 (Pro) on Mac (if this is useful).


    I tried to install fxaa3.unitypackage (guess it's the one you call "3.9") but did'nt get that satisfied of the result (not as smooth than in sample images I had seen). Then I read in this thread this one should not work with Unity 3.4.

    Then I downloaded the other version "FXAA3_11.unitypackage" and installed. But just as installation ended I got several warning messages in the console, which I don't understand at all (not coder at all, unfortunately).


    Assets/FXAA3/Scripts/FXAA3.cs(19,14): warning CS0114: `FXAA3.Start()' hides inherited member `PostEffectsBase.Start()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword

    Assets/FXAA3/Scripts/FXAA3.cs(26,21): warning CS0114: `FXAA3.OnRenderImage(UnityEngine.RenderTexture, UnityEngine.RenderTexture)' hides inherited member `PostEffectsBase.OnRenderImage(UnityEngine.RenderTexture, UnityEngine.RenderTexture)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword


    Assets/FXAA3/Scripts/FXAA3.cs(16,31): error CS0103: The name `CheckShaderAndCreateMaterial' does not exist in the current context

    Assets/FXAA3/Scripts/FXAA3.cs(23,17): error CS0103: The name `CheckSupport' does not exist in the current context



    Any help ? Is there any other package / script I should install or change ?
     
  46. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    Cool , Take rendertexture.
     
  47. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    v4.0 is shaping up nicely!
     
  48. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    Note that in 3.5.0f1, you'll need to add [ImageEffectOqaue] for FXAA3 to work nicely with other Image Effects.

    Code (csharp):
    1. [ImageEffectOpaque]
    2. public void OnRenderImage( RenderTexture source, RenderTexture destination )
     
  49. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    V4.0 ?? where is it?
     
  50. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    950
    Very nice. Although I barely see any difference, there still is one and it's definitely worth the processing power (which is, barely any).