Search Unity

Question Can someone explain how to use all the different forms of Anti-Aliasing in Unity?

Discussion in 'General Graphics' started by StripeGuy, Mar 22, 2023.

  1. StripeGuy

    StripeGuy

    Joined:
    Dec 30, 2016
    Posts:
    52
    To make it simple and give an example to work with for my question, I've got a line renderer object being rendered to a render texture, then another camera pointing towards that texture and sending it to another render texture (I know, but my project requires it). I'm trying to find the best way to anti-alias my line and all other objects in my game.

    Currently there are several ways of anti-aliasing and I'm not sure which I should be using and if "doubling" it up with different methods will make it worse.

    1. Render Texture has Anti-Aliasing
    2. Project Settings - Quality has an Anti-Aliasing option
    3. Camera "Post-processing" effects can add Anti-Aliasing
    And if I'm using post-processing on a camera, do I have to add it to all other camera using that render texture from the post-processing camera?

    Also, since I'm rendering through 2 render texture, do I have to have anti-aliasing on both?

    Sorry, it seems so complicated, but it is to me too! haha

    Hopefully someone can clear things up for me.

    Thanks.
     
    valentin56610 likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The project settings enable whether or not the frame buffer or internally created render textures use MSAA (Mult-Sample Anti-Aliasing). MSAA is a hardware feature that renders the edges of triangles N times per pixel. This only does anything when using the forward rendering path. If you use deferred, this setting is ignored as using MSAA with deferred rendering is difficult or in some cases impossible.

    By default Render Textures ignore the project setting, so you can either force MSAA on or off, or set it to use the same level of MSAA as in the project's settings. But the project settings and those you set on a render texture are mutually exclusive.

    Post-process Anti-Aliasing is a completely different beast. This is "software" based anti-aliasing, in that it's using shaders to do the anti-aliasing rather than relying on something already implemented in the hardware. You can use some forms of post process AA with MSAA, like FXAA (Fast approXimate Anti-Aliasing, yes really) or SMAA (Subpixel Morphological Anti-Alaising), and in some cases that can even be desired. FXAA and SMAA both work in similar ways in that they look for diagonal edges of high contrast and blur the pixels along that edge's direction, though their implementation is different. These work decently well to hide long jagged edges, but don't handle very thin details or small movement well as they work only on the data they have in the originally rendered image. I mention both of those because different versions of Unity's post-processing stack have included one, or the other, or both as options.

    TAA (Temporal Anti-Aliasing) is more intended as a total replacement for MSAA. This uses image data from previously rendered frames to improve the appearance of the current frame. And while it's technically possible to use MSAA with TAA, it's not generally advised as there can be visual weirdness when doing so, hence why Unity complains when both are enabled. Also with TAA you shouldn't even need MSAA. The one thing is TAA requires accurate motion vectors. If you're already using motion blur, then enabling TAA is nearly free. If not, then there is some (possibly significant) cost to TAA over FXAA or SMAA.


    Recent Call of Duty games use a special hybrid of SMAA & TAA called Filmic SMAA, and the original implementations of SMAA by Crytek was actually included a precursor to modern TAA called SMAA T2x, but Unity's implementation is not a hybrid implementation and does not allow you to use more than one form of post-process AA at one time, not that you'd actually want to enable them both.
     
  3. StripeGuy

    StripeGuy

    Joined:
    Dec 30, 2016
    Posts:
    52
    Thanks so much for taking the time to explain all this. :) Usually don't get that much luck with answers on here. It does help put things into perspective and see which one I should use. Much appreciated.