Anti-aliasing has an intimidating name, but what it does for our computer displays is rather fundamental. Think of it this way -- a line has infinite resolution, but our digital displays do not. So when we "snap" a line to the pixel grid on our display, we can compensate by imagineering partial pixels along the line, pretending we have a much higher resolution display than we actually do. Like so:
As you can see on these little squiggly black lines I drew, anti-aliasing produces a superior image by using grey pixels to simulate partial pixels along the edges of the line. It is a hack, but as hacks go, it's pretty darn effective. Of course, the proper solution to this problem is to have extremely high resolution displays in the first place. But other than tiny handheld devices, I wouldn't hold your breath for that to happen any time soon.
This also applies to much more complex 3D graphics scenes. Perhaps even more so, since adding motion amplifies the aliasing effects of all those crawling lines that make up the edges of the scene.
But anti-aliasing, particularly at 30 or 60 frames per second in a complex state of the art game, with millions of polygons and effects active, is not cheap. Per my answer here, you can generally expect a performance cost of at least 25% for proper 4X anti-aliasing. And that is for the most optimized version of anti-aliasing we've been able to come up with:
Super-Sampled Anti-Aliasing (SSAA). The oldest trick in the book - I list it as universal because you can use it pretty much anywhere: forward or deferred rendering, it also anti-aliases alpha cutouts, and it gives you better texture sampling at high anisotropy too. Basically, you render the image at a higher resolution and down-sample with a filter when done. Sharp edges become anti-aliased as they are down-sized. Of course, there's a reason why people don't use SSAA: it costs a fortune. Whatever your fill rate bill, it's 4x for even minimal SSAA.
Multi-Sampled Anti-Aliasing (MSAA). This is what you typically have in hardware on a modern graphics card. The graphics card renders to a surface that is larger than the final image, but in shading each "cluster" of samples (that will end up in a single pixel on the final screen) the pixel shader is run only once. We save a ton of fill rate, but we still burn memory bandwidth. This technique does not anti-alias any effects coming out of the shader, because the shader runs at 1x, so alpha cutouts are jagged. This is the most common way to run a forward-rendering game. MSAA does not work for a deferred renderer because lighting decisions are made after the MSAA is "resolved" (down-sized) to its final image size.
Coverage Sample Anti-Aliasing (CSAA). A further optimization on MSAA from NVidia [ed: ATI has an equivalent]. Besides running the shader at 1x and the framebuffer at 4x, the GPU's rasterizer is run at 16x. So while the depth buffer produces better anti-aliasing, the intermediate shades of blending produced are even better.
Pretty much all "modern" anti-aliasing is some variant of the MSAA hack, and even that costs a quarter of your framerate. That's prohibitively expensive, unless you have so much performance you don't even care, which will rarely be true for any recent game. While the crawling lines of aliasing do bother me, I don't feel anti-aliasing alone is worth giving up a quarter of my framerate and/or turning down other details to pay for it.
But that was before I learned that there are some emerging alternatives to MSAA. And then, much to my surprise, these alternatives started showing up as actual graphics options in this season's PC games -- Battlefield 3, Skyrim, Batman: Arkham City, and so on. What is this FXAA thing, and how does it work? Let's see it in action:
| No AA | 4x MSAA | FXAA |
|
|
|
|
(this is a zoomed fragment; click through to see the full screen)
FXAA stands for Fast Approximate Anti-Aliasing, and it's an even more clever hack than MSAA, because it ignores polygons and line edges, and simply analyzes the pixels on the screen. It is a pixel shader program documented in this PDF that runs every frame in a scant millisecond or two. Where it sees pixels that create an artificial edge, it smooths them. It is, in the words of the author, "the simplest and easiest thing to integrate and use".
FXAA has two major advantages:
The only downside, and it is minor, is that you may see a bit of unwanted edge "reduction" inside textures or in other places. I'm not sure if it's fair to call this a downside, but FXAA can't directly be applied to older games; games have to be specifically coded to call the FXAA pixel shader before they draw the game's user interface, otherwise it will happily smooth the edges of on-screen HUD elements, too.
The FXAA method is so good, in fact, it makes all other forms of full-screen anti-aliasing pretty much obsolete overnight. If you have an FXAA option in your game, you should enable it immediately and ignore any other AA options.
FXAA is an excellent example of the power of simple hacks and heuristics. But it's also a great demonstration of how attacking programming problems from a different angle -- that is, rather than thinking of the screen as a collection of polygons and lines, think of it as a collection of pixels -- can enable you to solve computationally difficult problems faster and arguably better than anyone thought possible.
| [advertisement] What's your next career move? Stack Overflow Careers has the best job listings from great companies, whether you're looking for opportunities at a startup or Fortune 500. You can search our job listings or create a profile and let employers find you. |
SMAA is even better and faster than FXAA.
http://www.iryoku.com/smaa/
Also there is software that automatically injects SMAA into your d3d9, d3d10 or d3d11 games: http://mrhaandi.blogspot.com/p/injectsmaa.html
Mārtiņš Možeiko on December 7, 2011 5:42 PMAnother example of how optimization for human perception can be extremely effective even if it's not the most accurate.
See also photographic image compression (e.g., JPEG), video compression (e.g., MPEG 4), audio compression (MPEG Layer 3).
Jeff, I am looking at your three screenshots and I have to make an effort to notice any difference between them. I mean, if you hadn't included those big block white captions explaining which ones have AA or not I'd be pressed to make the pick... Your three screenshots are an ode to the state of the art of PC gaming. Not to play down the technical achievement of FXAA, but maybe you should ignore your barely pixeled edges and enjoy the game!
Almost as interesting is how searching for "SMAA WebGL" confuses Google but not Bing.
Donpark on December 7, 2011 6:18 PMIt's very possible that I'm being overly prickly about terminology, but I have to take exception to calling anti-aliasing in general a 'hack'.
Aliasing is a well-understood artefact of sampling. If your continuous ('infinite resolution') image contains frequency components above the nyquist frequencies of sampling, aliasing occurs. You remove aliasing by increasing your sampling frequency, or removing those high frequency components before sampling. (Or you sample above your nyquist frequency, remove high frequency components, and then resample, which is SSAA).
Anti-aliasing (in general) is an analytically rigorous solution to a well-understood problem. This is not the description of a 'hack'.
(The things people do to fake anti-aliasing because the real thing is too expensive, on the other hand...)
Iain Peet on December 7, 2011 6:19 PMThanks for informing us about this. Hopefully, nVidia makes this an option on their graphics cards. At least for my card, the nVidia control panel gives you the option to set antialiasing for any program (so when you choose HDR in Oblivion, even if Oblivion disables antialiasing the control panels enables it). Does there have to be support for the technique in the game?
Or I could try Mārtiņš suggestion which enables SMAA in any d3d9-11 program.
Roberto Sanchez on December 7, 2011 6:32 PMFXAA looks less sharp, though. Just look at the tree leaves or wires.
Max Katsev on December 7, 2011 6:35 PMThis has got to be the most uninteresting thing you've ever blogged about (and yes, I did read about Bias Lighting). Of course, I'm just kidding. Keep up the good work.
Ronnie Overby on December 7, 2011 7:28 PMI'm looking at the
Interesting and somewhat more quantitative take on this here:
http://www.geforce.com/Optimize/Guides/the-elder-scrolls-v-skyrim-tweak-guide
(jump to the "FXAA & Water" section; source is Nvidia, so it's geared towards their stuff, but it applies to AMD as well)
As with so many things, there are tradeoffs, and the cost/value of those tradeoffs will vary from person to person. Personally, in the middle of the action and at high resolution I'm hard-pressed to notice a difference between MSAA, FXAA, and nothing.
That said, I always turn one of them on.
Lookatmike on December 7, 2011 7:57 PMHey, in addition to using FXAA, we should use JPG instead of PNG for screenshots!
After all, because JPG uses less resources it must be better, right?
Powerlord on December 7, 2011 9:41 PMI found it amusing you felt it necessary to spend a couple paragraphs defining what anti-aliasing is, but assumed the reader understood the intricacies of pixel shaders and fill rate. :)
Seriously, though... great post-- and a great example of lateral thinking in software architecture.
--- JRJ
Joseph Jones on December 7, 2011 9:45 PMIf course, doing AA as a render-buffer pass requires a loss of detail, while doing it at fragment shading time requires an increase - FXAA might be lower requirements, but it's objectively worse. Myself, I hate the overly even smoothness (or "blurryness") and inconsistent element volume across movement, to the point it's sampling AA or nothing for me. This is easier when you have a 2560x1440 monitor - still only 110 dpi, but it's getting there (come *on* manufacturers, I want my 300 dpi monitor, then it doesn't *matter* if I can't render at that resolution or read unscaled text - re-sampling doesn't look like crap!)
And yeah, don't use .jpgs of non-integer zooms for images about image quality. And don't have textures as a major image element - mipmaps neatly solve aliasing for them. And those wires are being drawn with a shader (a Half-life 2 technique, I think), so they don't alias as badly, even with no AA option enabled.
Simon on December 7, 2011 10:26 PMI see EA *still* can't get Arabic text right (and I assume Farsi too, Wikipedia tells me Battlefield 3 is set in Iraq and Iran), as seen on the shop signs on the left in the screenshot. For the millionth time, Arabic is written right-to-left, and the words *must* be written in cursive (it's not optional). For comparison, if they butchered English text, the word "Best" would be written as "T S E B". It's terrible, unreadable, and distracting to Arabic speakers.
Honestly, why can't they get it right?
Ibrahim M. Ghazal on December 7, 2011 10:44 PMMy Commodore 64 had exceptional hardware supported high-performance full screen anti-aliasing on all games with no drop in frame rate.
It was called a TV set.
Perhaps running your monitor in a non-native resolution would have the same effect?
www.google.com/accounts/o8/id?id=AItOawmG9DLXrVDPeknuVSaxT00AR3E0ORKm9Wg on December 8, 2011 2:12 AMTHANK YOU for explaining this. I never got off my lazy butt to look up what the FXAA option was in Skyrim, so I never enabled it, fearing it was some sort of Superhuman AA that would kill performance. But now that mothereffer is getting turned on all the way.
Kamran Ayub on December 8, 2011 5:11 AMSeriously wtf? They didn't do that already? Even I did something similar at the time I was still interested in 3D graphics programming in elder time on my Atari ST. At that time it was out of the question to use an oversampling algorithm to make some anti-aliasing. It was obvious to interpolate the colours using the adjacent pixels. The downside was a blurring of the image, which was a little bit annoying at 320x200, but at 1920x1080 it should even add realism (i.e. making it more like TV) to the picture.
You should take a look at MLAA. We shipped God of War 3 with it at the beginning of last year.
Phil Wilkins on December 8, 2011 11:26 AMMārtiņš, great tip on SMAA.
Noting Phil Wilkin's comment, I see that it's an implementation of MLAA.
This video comparing SMAA to FXAA and other techniques is impressive: http://vimeo.com/31247769.
Has anyone tried InjectSMAA with DX?
smithee on December 8, 2011 11:51 AMThe problem with FXAA is that it tends to blurs textures and other items that shouldn't be blurred by its very nature.
ATI use a similar form of AA called "Morphological Anti-aliasing" (MLAA). It has exactly the same idea of FXAA - run a shader pass over the entire image and clean up highly contrasting parts. It also blurs textures and aliasing. The difference between FXAA and MLAA is that MLAA is run after then entire scene is drawn. That means that text, hud elements, etc are also slightly blurred. However, it can be theoretically used for any game.
MSAA doesn't blur shaders unlike MLAA/FXAA which is a credit to them too.
FXAA is a pretty neat idea around for underpowered systems, and especially consoles and handhelds, but since I have the horsepower to enable 4xMSAA on practically every game, and 8xMSAA on most of them, I much prefer to use these forms of AA. True that MSAA doesn't affect the shaders, but I don't notice it most of the time anyway.
About SMAA - That's pretty neat. I did notice that Crysis 2 had a very sweet AA going on and it seemed pretty fast too. I'll have to look into SMAA more. From what I've seen though, I would love for it to appear in a diver update for my Nvidia GTX 560Ti
Chris Beamond on December 8, 2011 1:31 PM@Iain Peet: The problem with computer graphics is, that the signal is not band-limited and therefore the nyquist-theorem doesn't hold. Imagine the simple step function (one black pixel adjacent to a white pixel). This function is not band-limited and therefore you cannot sample at a high enough rate to correctly reconstruct the signal.
Therefore, the bitter truth for computer graphics is that anti-aliasing is always a bit of a "hack" - you can only approximate the truth. But that's not too much of a problem since in computer graphics (especially games) it only has to "look good" not "correct" (in the mathematical sense).
As a result, it makes most sense to treat computer graphics within an error-framework rather than the "nyquist-framework". It's better to ask the question "how close am I to the truth?" instead of "How do I reconstruct the truth?"
I recommend Michael Unser's excellent paper "Sampling - 50 Years After Shannon" for a very nice theoretical background overview on that topic.
Bernhard Finkbeiner on December 8, 2011 2:05 PM@Chris: That's a limitation of ATI's driver level implementation of MLAA.
Phil Wilkins on December 8, 2011 6:32 PMToms Hardware had a very summary of the whole anti alias stuff:
http://www.tomshardware.com/reviews/anti-aliasing-nvidia-geforce-amd-radeon,2868-3.html
For myself I think this anti alias is complete unnessary. The resolution of the monitors is already almost that high, that it is very hard two distinguish pixels (depends of course of your setup, like screen size, dpi, viewing distance, etc...). But if I would get the impression that there are too much aliasing artifacts I have an very easy solution
(which not every can do): I wear (weak) glasses. I just put them off, afterwards everything I can still see fine, but its slightly smoothed => no stairs ;-)
FXAA is a clever technique but in practice is not nearly as good as mentioned in this article. It might look good on screenshots but it does little to eliminate temporal artifacts due to aliasing.
The reason is simple: it doesn't have enough information to work with as visibility is evaluated only once per pixel. FXAA won't do much for sub-pixel features.
Obviously this doesn't make FXAA a useless technique but there is no free lunch in computer graphics and if you want to eliminate the byproduct of an insufficient sampling rate (aliasing) you need to increase the sampling rate one way or another.
FXAA does this implicitly by reconstructing a signal making certain assumptions, when those assumptions fail FXAA (or any other AA technique) fails.
BTW, unlike what is mentioned in this article MSAA is imo way less hacky than FXAA, it's actually a very good way of attacking the problem and it is much more effective than many post-processing techniques in reducing the amount of spatial and temporal aliasing. MSAA and variations of it are here to stay because it is a clever way of handling anti-aliasing without increasing too much the cost of shading.
FXAA and similar approaches are so cheap and easy to use but on the long run techniques that properly decouple visibility from shading and that handle visibility at higher rates are the way to go and the video linked by smithee shows this very well given that the AA methods based purely on post-processing the image clearly do a terrible job at eliminating temporal aliasing.
*The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way*
Marcosalvi on December 10, 2011 9:21 AMPretty much all "modern" anti-aliasing is some variant of the MSAA hack, and even that costs a quarter of your framerate. That's prohibitively expensive, unless you have so much performance you don't even care, which will rarely be true for any recent game. While the crawling lines of aliasing do bother me, I don't feel anti-aliasing alone is worth giving up a quarter of my framerate and/or turning down other details to pay for it.
Well, I don't know about that.
Given that we don't need to tie mouse polling to frame scan these days, and that anything over, say, 60 fps won't really be noticeable, how much do we really need? Are you sure you're actually hitting framerate barriers that matter, now?
(Ie, given that many games cap at 60, and many monitors don't do faster than 60-76hz refresh, losing 25% of your, say, 100fps gets you... still faster than it'll display. And still faster than you'll be able to see, most of the time if ever.)
A $199 video card can run full-HD, high-detail, 4xAA (16x oversample) at a framerate fast enough that I don't notice the rate - which is all that matters.
Given the slow adoption of greater-than-HD display sizes, GPU power is making the "problem" of AA go away at the moment; perhaps this will change when you can get the 27" super-HD monitors for a sane price.
Things has been changed a lot on picture quality from Video quality to HD is a long way. when I saw black and white movie and 80's color print I feel at that time everybody was fancy for that quality which is not acceptable in today's video. technology is changing over everyday and today's HD may not remain same in future.
Javabuddy on December 13, 2011 5:56 AMNot sure this is a product of "attacking a problem from a different angle" as it is a case of "new technology finally made it a viable solution."
There were age-old AA methods using final-scene pixel filters 20 yrs ago. The main problem was that they were actually much slower (back then) than doing poly-edge AA. This because both the cost of per-pixel filtering was very expensive and also because poly counts were much lower, so edge-aliasing made a mot more sense on a bandwidth level as well.
Furthermore, increased texture res helps the filters out as well: the effect it had on the (often blocky and low-res) textures wasn't particularly inspiring, and you'd spend your time trying to have the filter account for that (unsuccessfully). Nowdays, it is no longer a concern. (yay!)
Jake Stine on December 18, 2011 8:32 AMI somehow fail to see how running a edge-detecting blur filter via pixel shader is that great of an achievement. I mean, trying this is obvious, isn't it? Also, it won't improve actual quality, it will just blur the high frequency parts, even inside textures.
Or am I missing something?
Shannon's sampling theorem tells us that at a given sampling frequency f, the sample can exactly represent the signal up to the Nyquist frequency, which is f/2.
The problem is not that the screen is too low resolution, if you can't see the individual pixels. The problem is that the signal is aliased, which means that it contains components with a frequency (detail level) too high for the screen. The correct answer is not to smooth the image after you have created it; that will lower the Nyquist frequency of the image, but not improve the original signal.
The correct answer is to reduce the frequency of the signal. This means doing MPAA to get the higher-res sampling (and capture the original signal better) then do Guassian convolution over the image, before finally sampling that for the screen.
All you have with FXAA is vaseline on the screen.
Philip Howard on December 29, 2011 3:54 AMSSAA is the more better resolution than FXAA, but both are same like MSAA and it's really worth reading, better news for the resolutions of display of PC.
Authentication and Permissions
Visual Gaurd on January 4, 2012 7:14 AMFrankly it's a great blog thanks to this site I learned many things I love thisblog continues ...
Kikilala Moboloo on January 16, 2012 6:45 AMThe comments to this entry are closed.
|
|
Traffic Stats |