Easy Full-Screen Anti-Aliasing to Reduce Jaggies
Click the image to go to the WebGL version of the sample (it doesn't seem to work in Safari).
Hello. I'm Hirayama from the Technology Department.
This time I looked into the anti-aliasing techniques available in Unity and put together an overview. "Anti-aliasing" here means processing that makes the jagged edges that appear on screen (jaggies) less noticeable.
Conclusion
First, the conclusion.
- With Forward rendering, MSAA x2 is a reasonable choice
- x4 makes performance drop dramatically on some devices, so it looks fairly risky
- For Deferred rendering, or when the area drawn is large, FXAA is better in theory, but for some reason the free implementation didn't work on the Android phones I have.
Comparing the pictures
Let's see what anti-aliasing does to the image.

These are enlargements of part of the outline of a red sphere drawn on a black background. In order, they show no anti-aliasing, MSAA x2, MSAA x4 and FXAA.
In the untreated image, a single pixel sticks out near the top, which looks pretty bad. What should be a gentle curve clearly shows steps.
With MSAA x2, the odd bump is gone and it's much smoother. x2 is relatively cheap to apply, yet it works reasonably well. However, x2 has "angles it's bad at", and in this image the jaggies on the diagonal near the left end haven't gone away much.
Then with MSAA x4, you can see the quality improve even at the angles where x2 didn't quite clean things up.
The last one, FXAA, isn't Unity's standard one but one I found on the Asset Store. The jaggies are less noticeable everywhere, but it has a few quirks. I'll come back to that later.
Some measurement results
Here are the measurement results. The numbers are frame rates (FPS).
Sharp Android One S3 (Snapdragon430)
| AA type | 16 screens of fill | 32 screens of fill |
|---|---|---|
| None | 35.8 | 19.1 |
| MSAA x2 | 35.5 | 19.3 |
| MSAA x4 | 31.3 | 17.6 |
The resolution is 1920x1080.
Kyocera Android One S2 (Snapdragon425)
| AA type | 16 screens of fill | 32 screens of fill |
|---|---|---|
| None | 41.7 | 23.2 |
| MSAA x2 | 32.0 | 18.2 |
| MSAA x4 | 23.5 | 13.6 |
The resolution is 1280x720.
A rough comparison
I'll explain exactly what the test does later, but first let's take a rough look at the numbers.
On the S3, enabling MSAA x2 hardly lowers performance at all. Setting MSAA to x4 does lower performance, as you'd expect, but only by about 10%.
On the S2, on the other hand, performance drops by 20% at x2, and by more than 40% at x4. Even x2 reduces jaggies a lot compared with doing nothing, so depending on the product a 20% drop may be acceptable, but 40% at x4 really is hard to swallow. The S2's GPU is an Adreno306, and the Adreno 300 series is a very common chip found in a great many smartphones. If other models in the 300 series have the same weakness, you could say x4 is a bit hard to use.
So if I were to draw any conclusion from these two models, it would be "x2 seems about right". If I get a chance to test other chips, I'll update this article.
This project is on GitHub too. I got the FXAA from the Asset Store, so it isn't included. Add it yourself if you need it. Without it, the project simply runs with MSAA only.
Kinds of anti-aliasing
Let's go over the basics.
Jaggies appear on screen in the first place because pixels have a size, are square, and aren't blurred.

Whether it's a smartphone or a TV, if you look closely, you'll see square pixels lined up. If you zoom in further, even within a single pixel there are green, blue and red parts in all sorts of shapes, but for our purposes, pixels are square. And an LCD's pixels don't leak light into the neighboring pixels, so you see crisp square shapes. This is the source of jaggies. With a CRT, the picture isn't made of squares in the first place and the light bleeds, so the jagginess is softer. Try comparing the Famicom Mini's screen output that imitates a CRT with the crisp, square-pixel output (I found a page showing this).
That said, you don't see many jaggies in 2D games. That's because they're painted with alpha blending, which blurs the boundary between opaque and transparent. In 3DCG, though, that's hard to do, because "today's GPUs are machines that draw triangles", and the edges of those triangles can't be blurred.

This is a diagram of a GPU drawing a triangle. The pixels are divided by the thin green lines, and say we draw the triangle shown in red on top of them. For each pixel, the GPU tests whether the center of the pixel is inside the triangle; if it is, the pixel is painted (= the fragment shader runs), and if not, it isn't. It's a binary choice, paint or don't paint. That's why jaggies appear. This mechanism itself can't easily be changed.
So to reduce jaggies, you either somehow make the pixels bleed so the color changes more gently, or raise the resolution to make the pixels smaller. And since the resolution is fixed for each smartphone and can't be raised, the only thing you can do is "make them bleed".
Smartphone resolutions really are high, and on high-resolution models I can't see jaggies. If a 5-inch screen has a full 1920x1080, I don't think you need to do anything. But using such a high resolution as is means a heavy load and fast battery drain, so deliberately lowering the resolution should be one option. It's then worth considering deliberately "making them bleed" to make up for the image quality you lose.
Blurring
Now, the fact that pixels are square is hard to get around, and you can't physically "make them bleed". All you can do is change the color of each pixel. So let's mix in the colors of neighboring pixels to soften the change. In other words, blur it.

Around the boundary between white and black, I've mixed white and black into gray. The change becomes gentler, so the steps are less noticeable. At this size it's hard to tell, but if you shrink it down a bit, it starts to look like "a diagonal line" rather than "steps".
There are two ways to do this blurring.
One is to draw the picture at a larger resolution in the first place and then shrink it. For example, draw at twice the height and twice the width, and average the color of each 2x2 block of pixels.

To make a 4x4 image, first prepare 8x8, split white and black diagonally at that resolution, and then take the average of each 2x2 block. If all 4 are white the average is white, and if all 4 are black the average is black, but around the boundary you get combinations like 1 white and 3 black, which average out to gray.
The other method is to skip the bother of drawing at double size beforehand, and instead look at the finished picture and blur it "just right". You look at the 4x4 black-and-white image and think something like "it's jaggy around here, but it was probably a diagonal line originally, right? I'll make it a bit gray".
MSAA is one form of the first approach, "draw it big to begin with and shrink it", and FXAA is a technique of the second kind, "blur the parts that look sort of jaggy".
The shrinking techniques: SSAA and MSAA
The technique of simply drawing big is called SSAA (Super-sample Anti-Aliasing). Drawing at 1024x1024 and then shrinking to 512x512 is exactly that. The fragment shader runs for every one of the 1024x1024 pixels. It's the simplest, but the computational load is large, so it isn't normally done.
So a technique was developed that specializes in the triangle outlines I introduced earlier. That's MSAA (Multisample Anti-Aliasing). It draws at double the resolution in the same way, but keeps the number of fragment shader executions unchanged. For example, when drawing at twice the height and twice the width, it runs the fragment shader at the coordinates of the center of the 4 pixels and paints all 4 pixels the same color. However, pixels that didn't fall inside the triangle are excluded, so near the outlines, colors from different triangles get mixed within the 2x2. Averaging them mixes the colors and produces the blur.
You can think of MSAA x2 as doubling only one of the height or width, and x4 as doubling both the height and the width (though that isn't necessarily so). x2 had angles it was bad at because the resolution goes up only vertically or horizontally (though that isn't necessarily so either). With x4, that weakness goes away.
MSAA multiplies the memory used and increases the load of the Z test and memory writes, but depending on the hardware, a clever trick (tile processing) can make that load remarkably small. That's probably why the cost of x2 was barely visible on the Sharp S3 above. I'd guess the same kind of thing happens on iPhones and the like.
MSAA only works on triangle outlines. It's powerless against textures that are jaggy to begin with, jaggies from sharp highlights produced by lighting, jaggies made by alpha testing (also called CutOut, alpha kill or punch-through) and the like. SSAA can take care of those too.
Techniques that fix it afterwards
MSAA is the simple method of "drawing it big to begin with", so it's wasteful in various ways. Also, the render target's resolution has to be doubled at the very moment the triangles are drawn, so it needs preparation.
So techniques were developed that "remove the jaggies by modifying the picture already drawn". MLAA and FXAA are probably the leading examples. Recently there's also talk of having AI do it, or of using information from the picture produced in the previous frame to guess "what it would have looked like if it had been drawn big" (super-resolution), but these aren't at the point where you can do them in a game at 60fps.
The theory of FXAA is complicated and I've never implemented it myself, so I won't go into detail, but its appeal is that it needs no preparation and adds no extra load during normal drawing. Also, it handles every place that looks jaggy, regardless of whether it's a triangle outline.
But that can also be a problem. Look at this.


The left is the original image and the right has FXAA applied. It's nice that the jaggies on the polygon outlines are gone, but even the text has been blurred. Whether that's convenient or not depends on the situation. That's what I meant when I wrote that it "has quirks".
How this sample is designed, and the limitations that follow
This test looks at how the frame rate changes with each kind of anti-aliasing.
But as mentioned above, MSAA by its nature "raises the load whenever something is drawn", so the load differs between "painting the screen over and over again with translucency" and "painting something opaque just once to finish it".
I added a step that paints the screen with translucent fills, and the slider at the bottom of the screen sets how many times it does so. That's what "16 screens of fill" and "32 screens of fill" in the tables of measurements refer to. Painting the screen takes time even without MSAA, but enabling MSAA makes that time longer.
FXAA, on the other hand, has a fixed load however many times you paint the screen, so which of MSAA and FXAA is faster can vary depending on "what you're drawing on screen and how much of it". With little overdraw, MSAA has the advantage, and if you layer translucency over and over with effects and the like, MSAA will be at a disadvantage.
However, what makes MSAA slow is processing like "the Z test", "alpha blending" and "writing to the render target", which runs in parallel with the fragment shader, so if the shader is heavy to begin with, it may not be a problem. If you paint a lot with a shader that just does tex2D and returns, it'll be at a disadvantage, but if you're doing lots of lighting calculations and it already takes time, enabling MSAA may make hardly any difference. In this test I'm not even applying textures, just painting solid red or gray, so you could say it's a test in which MSAA is especially prone to lowering performance.
That was a lot of words, but in short, keep it simple: "turn it on in the product you're making now, and if the performance drop is acceptable and you think it's effective, leave it on." Information like "FXAA was faster in another product" or "MSAA was faster in another scene" isn't very useful. It's just one switch, so rather than thinking about the theory, it's best to just flip the switch on and off and see how it goes.
The conclusion, again
Let's sum up the pros and cons of MSAA and FXAA.
- MSAA eats memory on some hardware, and its load is proportional to the area drawn
- On some hardware it hardly slows down at all
- FXAA is done as post-processing, so its load is fixed at one screen's worth of fragment shader load
- That shader is fairly heavy
As for Unity-specific factors,
- MSAA is a standard feature, so you can use it with one switch
- FXAA has to be brought in from the Asset Store or implemented yourself (though apparently it's included in URP)
- For some reason, the implementation I tried this time showed no effect on these two Android models, and I couldn't tell whether it was working
- So its load is unknown too
- In addition, it doesn't work properly with a camera that draws to a RenderTexture
Considering all this, my impression is that for a smartphone product, MSAA x2 is the safe choice. I think if the resolution is 400 DPI (dots per inch) or more, even that isn't needed, but conversely, with even a little MSAA, a low resolution isn't very noticeable. I think the technique once called "resolution fraud" is still effective today: with MSAA enabled, draw only the 3D part at a slightly lower resolution, stretch it to the original resolution, and then draw the UI at full resolution.
With the method I introduced in the article on the FixedDPI setting, the UI's resolution drops too, and the blurring of text in particular tends to be noticeable, but if you lower the resolution of only the 3D part, it's not so noticeable. When the vertical and horizontal resolutions differ a lot, as on smartphones, I feel that halving only the long side works quite well. For example, the iPhone X is 2436x1125, so how about halving the long side to 1218x1125 (not that I've tried it)?
