New FXAA Anti-Aliasing Option in ParaView/VTK
One of the most frequently requested features on the ParaView mailing list has been for anti-aliasing support — that is, the ability to smooth out the jagged edges of lines and polygons that aren’t neatly aligned to pixel boundaries. The image below shows a scene rendered with aliased and anti-aliased edges (click to enlarge). Highly aliased areas are enlarged and compared in the bottom portion of the image to demonstrate the effect.
The anti-aliased image was generated using a technique commonly known as FXAA. The effect of FXAA is quite noticeable on the edges of the orange sphere that intersects the pink cone. While the green lines still retain some of the ‘stair-step’ effect in places, they are significantly smoother.
There are many ways to produce an anti-aliased rendering. However, most techniques aren’t feasible in ParaView: Multi-Sampling (MSAA) would introduce artifacts when rendering in parallel, and Super-Sampling (SSAA) is simply too expensive for complex scenes and parallel communication.
Most anti-aliasing techniques modify the rendering process to smooth out edges as they’re drawn. FXAA, or Fast approXimate Anti-Aliasing, however, is a post-processing technique that is applied to the final image of a scene rendered with aliased edges. This offers several advantages:
- The execution time is dependent on the screen size and not the scene complexity, so it scales well for complex scenes with lots of rendered polygons.
- FXAA does not affect the rendering process. This allows us to perform distributed parallel rendering in ParaView, compose each processor’s contribution, and then anti-alias the final image without introducing seams or other artifacts at the processor boundaries.
- FXAA is implemented in the fragment shader of a single OpenGL full-screen pass, and thus takes advantage of highly parallel GPU resources. The glsl source for the shader is freely available on github.
How does it work?
The FXAA implementation in VTK is an extension of the algorithm described by NVIDIA in their whitepaper. It addresses two types of aliasing:
- Subpixel Aliasing: A single pixel that has high contrast with its immediate neighbors (often caused by specular highlights and shadow effects).
- Edge Aliasing: The jagged, ‘stair-step’ edges produced when an object is rasterized to a display of finite pixels.
Subpixel aliasing is detected by computing the contrast between a pixel and its neighbors. It is corrected by blending an average of the pixel’s 3×3 neighborhood into the pixel’s final color.
Correcting edge aliasing is more complex. First, an edge detection method is used to determine whether the pixel is part of a horizontal or vertical edge. Second, a search is performed along the edge direction to identify the endpoints of the edge (i.e. the extent of the ‘stair’ in the stair-step). Finally, based on the pixel’s distance from the nearest edge endpoint, its color is adjusted to create a gradual blur that runs along the edge, smoothing the jagged appearance of the rasterized edge.
FXAA is disabled by default in ParaView, but can be enabled in the ParaView Settings dialog under Render View >> Antialiasing Options. The default settings for FXAA balance quality with performance, but these can be adjusted to achieve a desired result. Each option has a brief description that explains its effect on the final image:
The addition of this feature was made possible by Timothy Lottes of NVIDIA, who designed the original FXAA algorithm, and the VTK/ParaView implementation was funded by Sandia National Laboratories.