⌚ February 17, 2014
SweetFX SMAA (Subpixel Morphological Anti-Aliasing) is the one effect that probably justifies SweetFX’s existence. Sure, the other effects, such as Technicolor, Border, and HDR, provide novel post-processing enhancements, but SMAA is a serious anti-aliasing effect that often improves a game’s scene better than the game’s built-in anti-aliasing settings and without the additional slowdown that is usually introduced with high anti-aliasing modes. Think of SMAA as SweetFX’s killer app.
A Quick Background About Anti-Aliasing
3D generated games consisting of polygons, textures, and more are continually rendered by the CPU or GPU (video card, if present and capable). However, the rendered scene often appears to have jagged lines that are most noticeable around curved lines and polygon edges. This is called aliasing, and it has mainly to do with resolution, which is how many pixels the display viewport allows when presenting the scene through a display device. Resolution is often expressed in an X by Y pixel count, such as 1920×1080 pixels.
In the ideal situation, resolution would be infinite, so the rendered scene would appear perfectly smooth around edges and curved lines. However, monitors on which 3D scenes are displayed are limited in their resolutions, which could be 640×480, 800×600, or HDTV quality at 1920×1080.
The lower the resolution, the more pronounced the aliasing will be, and the higher the resolution, the less pronounced. Either way, the aliasing is still present, and one of the most persistent challenges over the years has been to devise a way to reduce or eliminate the jagged lines.
A plethora of various techniques exist, and many become obsolete as they are replaced by superior techniques — often from graphics chips vendors seeking an edge over the competition.
To better understand SMAA, let’s look at a few other anti-aliasing techniques first. There are four anti-aliasing techniques that, for now, remain popular in the 3D gaming world: SSAA, MSAA, FXAA, and SMAA.
(Many, many, many other anti-aliasing techniques exist, but they are usually tweaks or combinations of existing algorithms. For now, these four should suffice to illustrate the concepts of supersampling, multisampling, and post-processing anti-aliasing, which are the three main types of anti-aliasing.)
Supersampling Anti-Aliasing is the original and considered to be the “true” anti-aliasing. Everything is anti-aliased, including transparency sections, such as chain link fences. However, SSAA is a heavy performance hitter, and it can make systems drop to a crawl.
Multisampling Anti-Aliasing attempts to address the performance problems of SSAA. MSAA antialiases only the edges of polygons, not internal areas, so transparent sections, such as chain link fences, will remain jagged while the edges of the fence itself will be smoothed out.
MSAA is practically the standard or default anti-aliasing technique in use today, and it is supported by many games and graphics cards. If a game or graphics card provides a setting of 2xAA, 4xAA, or 8xAA, for example, then chances are good that it is using MSAA unless otherwise noted.
However, MSAA is still slow, and games will suffer a performance hit. There must be a better way, right?
Post-Processing Anti-Aliasing: FXAA and SMAA
Once reason SSAA and MSAA are slow is that they anti-alias the scene as the scene is rendered. For example, SSAA renders the scene at a much higher internal resolution than actually viewed at and then scales the final scene into the smaller resolution supported by the monitor. The higher the SSAA anti-aliasing desired for improved smoothing, the higher the internal resolution at which the game scene is rendered. At 8xSSAA, a game must be rendered at a resolution of 7680×2160 for playback on a 1920×1080 monitor.
(8xSSAA: 1920 x 4 = 7680, 1080 x 2 = 2160. 4 x 2 = 8xSSAA)
The exact implementation details might vary according to the specific algorithm used, but in general, this is what is happening behind the scenes. The result is that the game runs much, much slower compared to no SSAA.
A post-processing anti-aliasing technique applies anti-aliasing after the scene has been rendered. This results in very little to almost no performance hit while maintaining a decent anti-aliasing effect. This is where algorithms play a big role in the quality of the final image. Not all post-processing effects look good, but two techniques, FXAA and SMAA, produce excellent results.
Fast Approximate Anti-Aliasing (FXAA) is a post-processing anti-aliasing effect pioneered by NVIDIA that anti-aliases a scene with surprisingly good quality while introducing very little slowdown. Results may depend upon the exact scene and system, but FXAA is generally as good as 2xMSAA or 4xMSAA without the performance drop.
SweetFX supports FXAA, but it is a work in progress that only works with DirectX 9 using injector DLLs according to the comments in SweetFX_settings.txt. If using an NVIDIA graphics card with FXAA support, it is simpler to enable FXAA from the graphics card settings.
What Is SMAA?
Subpixel Morphological Anti-Aliasing (SMAA) is one of the newer anti-aliasing techniques that yields highly impressive results with practically zero slowdown or performance loss. Do not confuse SMAA with the older MSAA. They both contain the same letters, but they are entirely different anti-aliasing techniques.
During testing a variety of games, the SweetFX SMAA ultra settings produced far better scenes than 8xMSAA and on par with 16xMSAA when combined with hardware FXAA. SMAA was able to anti-alias curved edges better than anything MSAA or the NVIDIA graphics card could do and did so without any slowdown. If a game ran at 60fps without anti-aliasing, it still ran at near 60fps with SMAA. This was especially noticeable in the game Fallout: New Vegas.
On the other hand, the built-in anti-aliasing settings (MSAA 2x, 4x, and 8x) of Fallout: New Vegas and the graphics card’s MSAA both slowed the game down as the sampling increased, and neither anti-aliased the game as good as SMAA.
For more information and advanced details about SMAA, visit the http://www.iryoku.com/smaa/ web site for high-definition video demonstrations, slides, an executable demo, and a presentation PDF. The PDF is informative for those mathematically inclined.
Combining Anti-Aliasing Modes
SMAA by itself is not perfect. No anti-aliasing algorithm is. However, SMAA can be combined with the anti-aliasing of the graphics card for improved anti-aliasing. The purpose for doing this is to refine and make the scene look better without introducing slowdown.
SMAA already does a fine task of smoothing out jagged lines, but when combined with FXAA, the resulting scene appears even more refined. SMAA + FXAA can often smooth subtle curves that the highest MSAA settings miss, and it does so with hardly any loss of performance.
However, some anti-aliasing modes do not play well together, and they will degrade the scene rather than enhance it. One example, is SMAA + MSAA when used with the game Fallout: New Vegas. SMAA looks good by itself, so adding MSAA must improve it further, right? Not so, and we will see an example below. Different games might produce different results, so experimentation is key.
Below are various anti-aliasing comparisons from the game Fallout: New Vegas (tested at 1920×1080 resolution) located in the town of Goodsprings. Fallout: New Vegas supports in-game MSAA at 2x, 4x, and 8x. These modes are compared with SweetFX SMAA and combinations of in-game MSAA + SMAA.
1. Game MSAA OFF. No SMAA
No anti-aliasing is used here whether it be in-game, SMAA, or hardware. This is what Fallout: New Vegas looks like bare. The game plays at a full 60 fps during high-action scenes because there is no additional processing for anti-aliasing.
Take note of the lines around the transformer on the power pole and the curved electrical lines. This is a very difficult area to anti-alias in this game and many hardware settings missed it. Therefore, this particular area was chosen to test SMAA’s ability.
Notice edges, such as the mountains in the background and the roof of the gas station. We want to smooth these edges so they appear as natural as possible while keeping the game’s framerate as high as possible (60 fps is the limit for this game).
2. Game MSAA 2x. No SMAA
In-game 2x MSAA enabled at the launch screen. Slightly smoother, but it could be better. Notice that the vertical lines in the electrical pole are less pronounced compared to the original image. Mountain edge is smoother.
3. Game MSAA 4x. No SMAA
In-game 4x MSAA. At this point, the game begins to decrease in framerate slightly during high-action scenes, so computer hardware becomes a factor in performance.
The scene is improved over MSAA 2x, but the jagged lines are still noticeable.
4. Game MSAA 8x. No SMAA
This is the highest anti-aliasing setting available from within the game, and this is as good as it gets without an SMAA injector or adjusting the graphics hardware settings. At 8x, the game lags in framerate on lesser hardware — and many jagged edges are still apparent.
Increased anti-aliasing can be achieved by forcing specific anti-aliasing in the graphics hardware, but this depends upon the specific video card used and screenshots could not be captured using the Fallout: New Vegas screenshot key. All attempts resulted in a scene absent of any hardware anti-aliasing. Third-party screenshot tools are needed to resolve this issue.
5. Game MSAA OFF. SweetFX SMAA Ultra
This is the test we have been waiting for. What can SMAA do? Here, only the SweetFX SMAA effect is enabled and performing the anti-aliasing. The in-game anti-aliasing is set to off, and there is no hardware anti-aliasing enabled either.
Though the difference is subtle in the screenshots, SMAA by itself achieves results comparable to the in-game MSAA 8x but without the slowdown. The curved electrical lines are smoothed better with SMAA than with MSAA at 8x. SweetFX SMAA is set to its highest ultra setting for best results, and the game still runs at 60fps — even during high-action moments. Pure joy!
However, all is not perfect. Look at the vertical jagged edges on the electrical pole. This is one issue that SMAA never smoothed satisfactorily, nor did any other anti-aliasing method tried. The only technique that worked to a decent effect was SMAA + FXAA (NVIDIA hardware). However, this was a software + hardware solution, so capturing a screenshot of it was not possible.
6. Game SMAA 4x + SMAA Ultra
We can combine anti-aliasing modes together, so what happens if we enable the in-game MSAA with the SweetFX SMAA?
Uh-oh. Not good. Overall, the resulting scene actually looks worse than either MSAA or SMAA by itself. The sharp vertical jagged lines on the electrical pole are smoothed out better, but the curved electric lines and mountain edges — in fact, all edges in the game — are chunky and slightly blurred. The jagged edges have returned!
This was apparent with all SMAA + MSAA combining. Apparently, these two modes do not enjoy each other’s company in Fallout: New Vegas. Neither is pure SMAA or pure MSAA. The result is an ugly blend. Also, enabling MSAA brought the slowdown issues with it, so there is no point in using MSAA with SMAA hoping for better anti-aliasing.
Why is MSAA 2x + SMAA not shown? When tested, there was no apparent difference using MSAA 2x with SMAA.
7. Game MSAA 8x + SMAA Ultra
Here, we combine SMAA with the highest in-game MSAA setting, 8x, and we get the same blocky, blurry result as with MSAA 4x + SMAA. Again, we see that MSAA + SMAA ruins the image rather than helping it. MSAA 8x also brings back the increased slowdown.
Which Is the Best AA Setting?
To begin with, always use the highest resolution possible because this affects anti-aliasing more than anything. If the resolution is too low, then aliasing will still be present to some degree. For example, at 320×240 resolution there is no anti-aliasing technique available that will produce perfectly smooth curved lines. Anti-aliasing might help improve the image, but the result will be nowhere near what is possible at 1920×1080. The 320×240 resolution is simply too low for the needed detail.
In the screenshots above, SMAA by itself produced the smoothest effect without any slowdown. If using SMAA, disable MSAA or else the image will be degraded. Whether this is a game-specific issue is not known, but it was consistent in Fallout: New Vegas.
But what is the best anti-aliasing combination possible?
Answer: SweetFX SMAA + NVIDIA FXAA in hardware.
SMAA + FXAA easily produced the smoothest, most natural results. SMAA acted as a foundation, and then the NVIDIA FXAA refined the image further. When used together, almost all jagged edges were removed from Fallout: New Vegas and the game still ran at 60fps during high-action scenes. Yes, the vertical aliasing on the electric pole was still visible to some degree, but it was still better than SMAA alone. Hardware FXAA has a positive effect without degradation.
Software FXAA was not tested because it was easier to enable in the graphics settings. Screenshots showing the full effect were not possible without using third-party screenshot tools because. However, the game shows a definite improvement that exceeds the visual enhancement using MSAA 8x and competes with MSAA 32x (hardware) without introducing the additional slowdown associated with MSAA.
SweetFX SMAA Settings
First, enable SMAA in SweetFX_Settings.txt.
#define USE_SMAA_ANTIALIASING 1 //[0 or 1] SMAA Anti-aliasing : Smoothens jagged lines using the SMAA technique.
There are six settings that affect the SMAA anti-aliasing.
These are located in the SMAA Anti-aliasing settings section of SweetFX_settings.txt as shown below. (Misspellings kept intact).
/*-----------------------------------------------------------. / SMAA Anti-aliasing settings / '-----------------------------------------------------------*/ #define SMAA_THRESHOLD 0.10 //[0.05 to 0.20] Edge detection threshold. If SMAA misses some edges try lowering this slightly. I prefer between 0.08 and 0.12. #define SMAA_MAX_SEARCH_STEPS 16 //[0 to 98] Determines the radius SMAA will search for aliased edges #define SMAA_MAX_SEARCH_STEPS_DIAG 6 //[0 to 16] Determines the radius SMAA will search for diagonal aliased edges #define SMAA_CORNER_ROUNDING 0 //[0 to 100] Determines the percent of antialiasing to apply to corners. 0 seems to affect fine text the least so it's the default. // -- Advanced SMAA settings -- #define COLOR_EDGE_DETECTION 1 //[0 or 1] 1 Enables color edge detection (slower but slightly more acurate) - 0 uses luma edge detection (faster) #define SMAA_DIRECTX9_LINEAR_BLEND 0 //[0 or 1] Using DX9 HARDWARE? (software version doesn't matter) if so this needs to be 1 - If not, leave it at 0. //Enable this only if you use a Geforce 7xxx series or older card, or a Radeon X1xxx series or older card.
Leave COLOR_EDGE_DETECTION at 1 and SMAA_DIRECTX9_LINEAR_BLEND at 0 unless there is a need to change them. These are advanced settings, and there is no real need to tamper with them.
The actual code for SMAA as used by SweetFX is located in SweetFX/Shaders/SMAA.h. There is no need to change this file unless curiosity beckons.
SweetFX SMAA Ultra Settings
By default, SMAA is set to a normal setting, which is fine for most uses, but it can be increased to higher settings for improved anti-aliasing. Below is the SMAA setting used during testing and in creating the screenshots.
#define SMAA_THRESHOLD 0.05 #define SMAA_MAX_SEARCH_STEPS 64 // 32 also works well #define SMAA_MAX_SEARCH_STEPS_DIAG 16 #define SMAA_CORNER_ROUNDING 25
These can be thought of as “ultra” settings. There is a separate ultra specifier for SMAA elsewhere, but editing these values directly provides finer per-game adjustment over the anti-aliasing settings.
Absolutely no slowdown occurred after increasing these values.
The SweetFX SMAA Advantage
In theory, any game that works with SweetFX should allow SMAA even if the game does not support SMAA natively. This is a benefit because games that do not support anti-aliasing well or offer low settings can be enhanced with SMAA along with the other SweetFX effects. This can vary by the game, so experiment.
After testing, SMAA emerged as the new darling of anti-aliasing and quite possibly one of the best methods to ever be devised due to its combination of high-quality smoothing and almost no loss in framerate.
While not completely perfect, SMAA can be enhanced for even better image results when combined with the NVIDIA FXAA effect in the graphics hardware. The final image is a superbly rendered 3D scene with hardly any slowdown or lag (if at all) compared to traditional SSAA and MSAA.
- SweetFX Shader Suite
- SweetFX – Splitscreen
- SweetFX – Cartoon
- SweetFX – Technicolor
- SweetFX – Monochrome
- SweetFX – Bloom
- SweetFX – Border
- SweetFX – HDR
- SweetFX – Sepia
- SweetFX – SMAA
- SweetFX – Vibrance
- SweetFX – Cineon DPX
- SweetFX – Explosion
- SweetFX – LumaSharpen
- SweetFX – Tonemap
- SweetFX – Lift Gamma Gain
- SweetFX – Vignette
- SweetFX – Levels