SMAA: improved subpixel morphological anti-aliasing
- Transfer
This article is based on the journal Jorge Jimenez, José Echevarría, Tiago Sousa and Diego Gutierrez.
You can see their demos of the SMAA implementation here (the .exe file). On my GTX 960 2GB, it works quite fine.
Old anti-aliasing methods
For many years, MSAA (Multisampling Antialiasing) and SSAA (Supersampling Antialiasing) have been the standards for the implementation of smoothing. In fact, they still provide the highest quality among all modernsmoothing methods. As we know, aliasing arises due to a lack of samples, both at the spatial (broken lines) and at the temporal level (flicker), usually near the edges and areas of the image with high / low contrast. To combat it, we have two ways that were once the only solutions: Supersampling and Multisampling. When supersampling, we increase the image, and then reduce its sampling to the desired resolution. This principle works great because it covers all aspects of the problem. When multisempling uses a similar solution. In this method, each sample is duplicated on the basis of a certain coefficient. With modern high resolutions, this requires quite powerful graphics cards. Therefore, we need new methods of smoothing, both on spatial, and at the time levels. All these methods use one algorithm in their work - edge recognition. But they perform other operations.
Modern smoothing methods
There are many modern filtering-based methods that do a good job, although they are inferior to the two listed above. FXAA, DEAA, GPAA, GBAA, CSAA, EQAA, DLAA ... In this article we will talk about SMAA, and its predecessor - MLAA. These modern filtering-based methods have their own problems:
- Most edge recognition algorithms that underlie these methods take into account only numerical differences between pixels and ignore how they are displayed to the viewer.
- The original shape of the object is not always preserved, the overall rounding of the corners is almost always clearly visible on the text, sharp corners and sub-pixel elements.
- Most solutions are designed to process only horizontal or vertical patterns, and ignore diagonals.
- Real sub-pixel elements and sub-pixel motion are processed incorrectly. Aliasing reflections (specular) and shading (shading) are not completely eliminated.
As you might guess, we raised these problems because we want to eliminate them.
Morphological Antialiasing (Morphological Antialiasing, MLAA)
MLAA is trying to estimate the coverage of the original geometry. To precisely rasterize a smoothed triangle, it is necessary to calculate the coverage area of each pixel inside the triangle in order to properly mix it with the background. MLAA begins with an image without smoothing, and then reverses the process, vectoring the silhouettes to calculate the areas they cover. Since the background cannot be recognized after rasterization, MLAA then mixes it with the neighbor, assuming that its value is close to the value of the original background. In other words, the algorithm recognizes borders (using color or depth information), and then detects specific patterns in them. Smoothing is provided by intelligent mixing of pixels in the borders. MLAA has implementations on DirectX 10 and Mono Game (XNA). It is honestly implemented in games like Fable II. The creators of MLAA later created SMAA, or Enhanced Subpixel Morphological Antialiasing (improved sub-pixel morphological anti-aliasing), which is the main theme of this article.
MLAA in action
Enhanced Subpixel Morphological Antialiasing (SMAA)
Comparing SMAA and other methods in Crysis 2
SMAA provides reliable edge detection, as well as a simple and effective way to handle sharp geometric elements and diagonal lines. In addition, SMAA does not change the shape of the geometry, as many other methods do.
Above - AA not; in the middle - MLAA; SMAA at the bottom
SMAA is built on the MLAA pipeline, and improves or rethinks each stage. In particular, edge recognition is enhanced by using color information along with local contrast adaptation to create clearer edges. The method expands the number of patterns used to preserve sharp geometric elements and diagonals. Finally, it shows how morphological anti-aliasing can be precisely combined with multisampling or supersampling and temporal re-design.
Edge recognition
Edge recognition is a crucial step, because unrecognized edges remain distorted. On the other hand, too many filtered edges reduce the quality of the smoothed image. Various information can be used for edge recognition: chromaticity, brightness, depth, surface normal, and their combination. SMAA uses luma for four reasons:
- Less artifacts.
- Brightness is always visible.
- It can cope with shading distortions.
- And finally, it is faster than chroma.
On the left and in the center: other edge recognition methods that lead to the appearance of red intersections and artifacts; Right: SMAA's sharp edges.
Remember this image. Here's how edge detection works: the final calculated value is a boolean value, called the left edge . The Boolean values for the top edge are calculated in the same way. Formula:
All values of c are called contrast deltas .
Pattern Processing
Pattern recognition SMAA allows you to save sharp geometric elements, such as angles, handles diagonals and provides an accurate search for distances.
Sharp geometric elements: the re-orchestration of silhouettes in MLAA is prone to round corners. To avoid this, SMAA uses the observation that the intersection of edges in contour lines has a maximum size of one pixel, and for acute angles this length is likely to be longer. Therefore, SMAA takes two-pixel intersecting edges, which allows for less aggressive corner processing.
Diagonal patterns: we have added a completely new way to recognize diagonal patterns. It consists of the following two steps:
- Search for diagonal distance and left and right of the diagonal lines.
- Getting intersected edges and .
- Using this input, we define a specific diagonal pattern to access the pre-computed region texture, getting the regions and .
If the recognition of diagonal patterns failed, then the recognition of orthogonal patterns is triggered.
Accurate search for distances: the key to recognizing and classifying patterns is to get an exact edge distance (length to both ends of the line). To speed up this process, MLAA actively applies hardware interpolation. Hardware bilinear filtering can be used to obtain and encode up to four different values in a single memory access operation. This linear interpolation of two binary values (that is, bilinear ) creates a single floating point value, described by the following formula:
Where and - these are two binary values (0 or 1), and - interpolation value.
results
MLAA works with one sample per pixel. That leads to sub-sampling, due to which real sub-pixel elements cannot be recreated.
Comparison of MLAA with SMAA and the absence of AA
However, SMAA operates at the subpixel level. This leads to the following:
- Local contrast
- Diagonal Pattern Recognition
- Sharp geometric elements
- Exact search
All this can be seen in the image below, where these aspects are compared with the results of other methods. In fact, SMAA can produce results close to SSAA 16x.
The overhead incurred by each of these solutions is negligible. In particular, the adaptation of local contrast takes only 0.08 ms, the recognition of sharp geometric elements and exact distances take 0.01 ms, and the processing of diagonals adds an extra 0.12 ms. Simply put, SMAA is fairly fast, slower than SSAA and MSAA, but more fruitful and less resource intensive.