07 Dec 2011 Fast Approximate Anti-Aliasing (FXAA)

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 bởi vì not.

Bạn đang xem: Pc graphics options explained: page 2

So when we "snap" a line khổng lồ the px 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 vày. 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 haông chồng, but as hacks go, it"s pretty darn effective sầu. Of course, the proper solution lớn this problem is to have sầu extremely high resolution displays in the first place. But other than tiny handheld devices, I wouldn"t hold your breath for that khổng lồ happen any time soon.

This also applies to lớn much more complex 3D graphics scenes. Perhaps even more so, since adding motion amplifies the aliasing effects of all those crawling lines that 3D 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 & 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 sầu been able to come up with:Super-Sampled Anti-Aliasing (SSAA). The oldest triông chồng in the book - I menu it as universal because you can use it pretty much anywhere: forward or deferred rendering, it also anti-aliases alpha cutouts, và 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).

Xem thêm: Miss Fortune Sp, Ad Mùa 11: Bảng Ngọc Bổ Trợ, Lên Đồ Miss Fortune Ap

This is what you typically have in hardware on a modern graphics card. The graphics thẻ renders to a surface that is larger than the final image, but in shading each "cluster" of samples (that will kết thúc up in a single px on the final screen) the px 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 altrộn cutouts are jagged. This is the most comtháng way to lớn 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 . 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 haông chồng, và even that costs a quarter of your framerate. That"s prohibitively expensive sầu, unless you have sầu 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 lớn pay for it.But that was before I learned that there are some emerging alternatives to lớn MSAA. And then, much to my surprise, these alternatives started showing up as actual graphics options in this season"s PC games -- Battlefield 3, Skyryên ổn, Batman: Arkmê mệt City, & so on. What is this FXAA thing, and how does it work? Let"s see it in action:

(this is a zoomed fragment; cliông chồng through khổng lồ see the full screen)FXAA stands for Fast Approximate Anti-Aliasing, và it"s an even more clever haông xã than MSAA, because it ignores polygons and line edges, và 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 và easiest thing to lớn integrate and use".
FXAA has two major advantages:FXAA smooths edges in all pixels on the screen, including those inside alpha-blended textures and those resulting from px shader effects, which were previously immune lớn the effects of MSAA without oddball workarounds.It"s fast. Very, very fast. Version 3 of the FXAA algorithm takes about 1.3 milliseconds per frame on a $100 đoạn Clip card. Earlier versions were found lớn be double the tốc độ of 4x MSAA, so you"re looking at a modest 12 or 13 percent cost in framerate lớn enable FXAA -- and in return you get a considerable reduction in aliasing.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 lớn Call this a downside, but FXAA can"t directly be applied lớn older games; games have sầu to be specifically coded to lớn Điện thoại tư vấn 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 & 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 & 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. 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 protệp tin and let employers find you.