Anti-aliasing refers to a series of techniques used to improve the appearance of geometry with jagged edges, while rendering a picture. Using anti-aliasing in a scene allows for smoother results, while incurring a performance penalty.
When using HPS there are two separate and independent anti-aliasing settings:
- Screen anti-aliasing
- Text anti-aliasing
Note that screen and text anti-aliasing are not mutually exclusive. It is possible to have only one or the other active, or to have them both active at the same time.
Not using anti-aliasing (both off) yields the best performance, and is useful for scenes where aliased geometry is acceptable, or when rendering to a device with very high pixel density. High-DPI devices (e.g. mobile devices, Macs with Retina screens, and PCs equipped with high resolution screens) naturally yield a smoother image than less pixel dense screens even when anti-aliasing is off.
Screen anti-aliasing is a window-level setting. For it to be usable, a Canvas needs to be created with the AntiAliasCapable option turned on.
HPS::ApplicationWindowOptionsKit windowOptions; windowOptions.SetAntiAliasCapable(true, 4); Canvas canvas = HPS::Factory::CreateCanvas(window_id, “my_canvas”, windowOptions);
The second argument of the
SetAntiAliasCapable represents the number of samples which will be used during the anti-aliasing procedure. A higher sample count will yield a smoother image, but also result in higher memory consumption and longer processing times.
After creating the Canvas it is still possible to turn off screen anti-aliasing using the
VisualEffectsControl from the
WindowKey associated with the Canvas.
Screen anti-aliasing works by using an industry standard anti-aliasing technique called Multi-Sample Anti-Aliasing (MSAA). When MSAA is used, each pixel is divided into several fragments, and the output color is calculated for each fragment, instead of it being calculated for each pixel.
At the end of the rendering the color value of each pixel is obtained by averaging the values of the adjacent fragments, resulting into a smoother image. The number of fragments used by Visualize depends on the sample value passed to
SetAntiAliasCapable when the Canvas is created.
Some older graphics cards might not support MSAA. When Visualize detects that MSAA is not available, and the user requested screen anti-aliasing, it will fall back to using a different technique called Super-Sample Anti-Aliasing (SSAA).
SSAA works by rendering the scene at a higher resolution than normal, and then down-sampling the image after the drawing has completed. SSAA is much less performant than MSAA, and therefore it is only used when the hardware does not support MSAA.
In most cases, the performance impact of screen anti-aliasing is small. Reasonably recent graphics cards support MSAA and will execute it on hardware. On devices with very high pixel density screen anti-aliasing might not yield much of a difference; if this is the case in your application, it might be worthwhile to disable it to improve the rendering performance slightly.
In applications where performance is the most important factor, disabling screen anti-aliasing might help performance a bit.
Text anti-aliasing can be enabled at any time by using the
VisualEffectsControl. In contrast to screen anti-aliasing, it can be turned on only for specific segments, instead of affecting the whole window.
NOTE: Text anti-aliasing is not supported for TrueType text which is drawn using vectors.
For example, the following settings on a segment containing text will make it so that text anti-aliasing will not apply to it:
Segment_one.GetTextAttributeControl() .SetFont("Times New Roman"). .SetRenderer(Text::Renderer::Truetype) .SetPreference(Text::Preference::Vector);
In these cases, it is still possible to use screen anti-aliasing to obtain a smoothly rendered image.
When text anti-aliasing is enabled Visualize changes the way text is drawn. Text will be rendered with a slight transparent outline and then blended on the rest of the scene. This process happens before screen anti-aliasing. Note that unlike screen anti-aliasing, text anti-aliasing only works on text.
As a byproduct of this technique, text will look slightly different when using text anti-aliasing, compared to when using screen anti-aliasing.
Text anti-aliasing is much more performance intensive than screen anti-aliasing. Rendering the text and blending it into the background requires multiple passes. As such, the time overhead it will take to complete text anti-aliasing will increase based on the number of text characters present in segments for which text anti-aliasing is enabled.
Applications that usually need to render large quantities of text will get a significant performance upgrade from using screen anti-aliasing rather than text anti-aliasing.
- No Anti-Aliasing
Note the jagged edges of the green polygon and text
No Anti-Aliasing – close-up
- Screen anti-aliasing
Note the improved smoothness of the polygon edges and text outline
Screen anti-aliasing – close-up
- Text anti-aliasing ON, screen anti-aliasing OFF
Note the smooth outline of the text and jagged outline of the green polygon
- Text anti-aliasing ON, screen anti-aliasing OFF – close-up
- Screen anti-aliasing ON and text anti-aliasing ON
- Screen anti-aliasing ON and text anti-aliasing ON – close-up