Search Unity

Better fake AA for deferred lighting

Discussion in 'Made With Unity' started by multivac, Oct 10, 2010.

  1. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    I adapted NFAA(Normal Filter Antialiasing) for Unity 3.0.
    I think it looks better than the included Edge Blur,which always ends up losing all the sharpness in the edges.
    Compare the edges of the guns in the attached screen,to see how it smoothes out aliasing.(Left side is NFAA,right has no smoothing)

    Unity 3.3 version available here: http://dl.dropbox.com/u/10887020/NFAA/NFAA.unitypackage

     
    Last edited: Mar 31, 2011
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Hmm... that does look better! How big a performance hit is there?
     
  3. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    I didn't register much of an effect on performance,but it probably takes about as much as default edge blur,possibly a little less as it has only one iteration.

    I do subpixel offsets in the shader and it seems they are sometimes clamped to zero in Unity editor when window is not maximized.
    So try it maximized or published,if it doesn't seem to work in Editor window.
     
  4. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    Another comparison with no antialiasing,it actually emulates forward rendering antialiasing pretty well:D
    One thing it cannot do though, is invent detail where there is none, so e.g. thin wires in the distance won't look as good as with MSAA.

     
  5. ColossalDuck

    ColossalDuck

    Joined:
    Jun 6, 2009
    Posts:
    3,246
    Wow dude, this is pretty epic.
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Outstanding work. I'll give it a try at work tomorrow.
     
  7. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Multivac that works great!!

    I am using also color correction and when the CC filter is above the nfaa filter in the script stack the nfaa doesn't work ...
    If I put the cc filter after the nfaa filter it works.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,756
  9. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    yeah,its the same approach,I made some improvements though,I should probably post them in that thread.
    the version posted in the thread doesn't really give good results,but with some better sampling patterns and subpixel offsets it works really well.
     
  10. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    :-( Doesn´t seem to work with me. I only get a blue screen. Deactivating the Debug mode seems to turn the effect off(?), because I can´t see any difference. What exactly do you mean by "play around with the effect´s position in the stack" ?
     
  11. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,756
    Fog, remove all other post effects from the Camera to see if it works or not.

    It does indeed seem that it doesn't like having the CC fillter above it or example.
     
  12. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    Thanks, but I´m still having problems with the filter script. I´ve removed all ther effects from the camera, but if I look at the scene in "game-mode" I just see a blue screen.

    If I compile the game and run it as "standalone" I can see the blue normal map, but that´s all.

    My rig:

    Windows 7 Pro, 64 bit
    ATI Radeon 4800 Series
     
  13. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    @fogGobbler: uncheck the "debug" checkbox from the script dialog.
     
  14. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    Yeah, if I turn the debugmode off, I can see the image, but I don´t see any kind of "antialias"-effect. It looks exactly like the version without the effect.
     
  15. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Have you build the application?
    It doesn't work pressing the play button. You have to build.
     
  16. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    Thanks for your help, I finally got it working and it looks great :) .
     
  17. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    Well, I got it running in my scene, but when I try it in the bootcamp project all I get is just a black screen. I´ve deactivated all other effects on the soldier cam and built the project.

    Anybody else having problems?
     
  18. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    The screen in bootcamp demo is black until you press escape,have you tried that? ;)
     
  19. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    thanks :) never thought of that....
     
  20. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    So this is kind of a substitue for anti alising... So should we be setting the game to 4x AA and then using this or does it even matter if we use 16x, it would look really crisp on the edges.
     
  21. adriaanza

    adriaanza

    Joined:
    Jun 24, 2010
    Posts:
    41
    Artimese I think where it would be most appropriate is where deferred lighting is used, which currently doesn't have AA support. Unity recommends using their included image effect to fake it. This is just a better implementation of that unique.
     
  22. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Artimese, this shader is for the deferred renderer where you can't have hardware AA, thus the shader.
     
  23. flim

    flim

    Joined:
    Mar 22, 2008
    Posts:
    326
  24. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Oh i see, this would make so much more sense if i knew what deferred renderer ment :(
     
  25. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    Thanks for porting the NFAA.
    I made changes for it to run on Unity 2.6.1.
    Also removed the debug function in the shader which decreased the arithmetic count enough to run on shader model 2.
    Great work multivac.
     
  26. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    Its great that you found it useful, but why use it on 2.6 though?
    I think built-in antialiasing is always cheaper and has higher quality.
     
  27. MEGATON

    MEGATON

    Guest

    Joined:
    Mar 3, 2008
    Posts:
    28
    I created a deferred renderer in 2.6.1 using position reconstruction from depth.
    I've previously toyed with AA using various techniques - from Stalker, Tabula rasa to 3D max's simple cubic filter.
    I'm gonna stick w NFAA for now until I get around to really studying its potential against previous filters.
     
  28. fktt

    fktt

    Joined:
    Jul 5, 2009
    Posts:
    29
    Damn, you all way's blow my mind, loved the Chromatic aberration, and love this, awesome! :3
     
  29. jcarpay

    jcarpay

    Joined:
    Aug 15, 2008
    Posts:
    561
    Nice! Can you post a UnityR3 version of your modified shader?
     
  30. sandolkakos

    sandolkakos

    Joined:
    Jun 3, 2009
    Posts:
    285
    Thanks very much.
    This work is being great usefull.
     
  31. Yann

    Yann

    Joined:
    Oct 20, 2007
    Posts:
    432
    OMG ! Thanks so much, multivac :D
     
  32. chai

    chai

    Joined:
    Jun 3, 2009
    Posts:
    84
    Thanks for sharing the plugin, but unfortunately it didn't work for my game. (isometric with low FOV 9.5°)

    Does this plugin do micro sampling like traditional AA, Or is it a fancy edge blurring ? (in which case I guess it won't work for me)
     
  33. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    chai, check if u have multiple cameras running. I know if i have multiple cameras, lots of camera image effects get broken if a hud camera is running and both are on deferred rendering. I fixed my god rays and this AA by having the hud camera use vertex lit instead of deferred.. while the main camera uses deferred
     
    Last edited: Oct 26, 2010
  34. chai

    chai

    Joined:
    Jun 3, 2009
    Posts:
    84
    cheers Kurylo3d - but my problem is caused by the camera's unique low FOV and high distance I believe.
    MSAA seems the only option for me if I go deferred.
     
  35. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    604
    Thank you multivac. It works perfect!
     
  36. Deleted User

    Deleted User

    Guest

    Could someone re-upload please? The link is broken :(
     
  37. Rond

    Rond

    Joined:
    Oct 21, 2009
    Posts:
    175
    I can't use it on windows?
    When i a attach the script on the camera it says that my platform is not supported..
     
  38. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I'm using it on Windows, works here. Perhaps the error message relates to what your target player setting is, did you check that?
     
  39. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    It seems that the 3.2 update broke this shader and script.
    multivac is there any chance to fix this?
     
  40. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    If you have Pro there's a new image effect that replaces this.
     
  41. FogGobbler

    FogGobbler

    Joined:
    Mar 25, 2009
    Posts:
    147
    I seem to be blind...which one? can´t find it :-(
     
  42. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
  43. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Ah ok.
    Thanks.
     
  44. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    This is great!

    Thanks a ton for this!

    -Mike
     
  45. ubhkid

    ubhkid

    Joined:
    Jul 31, 2010
    Posts:
    73
    Is this working in 3.2 for everyone?

    I'm getting a log out put saying - "The shader Hidden/EdgeDetectNormalsHQ (UnityEngine.Shader) on effect Camera (NormalFilterAA) is not part of the Unity 3.2 effects suite anymore. For best performance and quality, please ensure you are using the latest Standard Assets Image Effects (Pro only) package"
     
    Last edited: Feb 18, 2011
  46. Din

    Din

    Joined:
    Jan 11, 2011
    Posts:
    146
    Have another error Unity 3.3:

     
  47. multivac

    multivac

    Joined:
    Oct 27, 2009
    Posts:
    133
    I suggest everyone use the Luminance Edge Blur that Unity included.
    It is essentially the same thing that I wrote, only with some changed variable names,optimization and added comments. Even the sampling pattern is the same one that I came up with.
    Plus my package actually replaces the Unity's one if I import it, they probably use the same internal asset, just renamed.
    But both I and the original creator released it for free so its okay I guess. No need for a shiny new name though Unity, its still NFAA.
     
  48. Artimese

    Artimese

    Joined:
    Nov 22, 2009
    Posts:
    794
    Imho, luminance edge blur is terrible, your shader was 30x better and you should definetly re-write one for 3.3, it was really amazing
     
  49. h20

    h20

    Joined:
    Dec 8, 2009
    Posts:
    50
    Hi, I'm looking for the Luminance edge blur effect?

    Is it the Component > Image effect > blur


    because I have nothing that says luminance edge blur

    Thank you

    h20
     
  50. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Are you using Pro? Version 3.2 or later?