BlendedAA Sample
Description
This sample implements a two-pass additive blending anti-aliasing technique using Target-Independent Rasterization (TIR), which should give comparable results to MSAA with a reduced memory footprint.
APIs Used
- GL_LINES
- glLineWidth
- glGenFramebuffers
- glFramebufferTexture2D
- glBindFramebuffer
- glRasterSamplesEXT
- glCoverageModulationNV
Shared User Interface
The Graphics samples all share a common app framework and certain user interface elements, centered around the "Tweakbar" panel on the left side of the screen which lets you interactively control certain variables in each sample.
To show and hide the Tweakbar, simply click or touch the triangular button positioned in the top-left of the view.
Technical Details
Overview
This blended anti-aliasing technique uses Target-Independent Rasterization (TIR) to perform a two-pass forward-rending algorithm which gives identical results to normal multisampling (MSAA) with a smaller memory footprint.
Target-Independent Rasterization allows the rasterizer's sample rate to differ from that of the render target. It then uses a configurable process to resolve the samples and write to the render target. For this sample, we modulate the final color by the percentage of samples covered, and use additive blending combined with a Z-prepass to accumulate the visible colors for each pixel. The result should be the same as running MSAA at the same frequency and resolving.
Benefits
With Target-Independent Rasterization, we can rasterize primitives at a high sample rate while keeping render targets at a lower sample rate, significantly reducing the memory footprint of the application compared to MSAA at the same frequency, especially as resolution scales up. The final resulting image is identical to that generated by a full MSAA pass with a normal resolve.
Caveats
Due to the need to use the high frequency coverage for each individual primitive to modulate the final color, this algorithm will only work with forward rendering. Also, to ensure that the additive blending only affects those pixels in which the primitive is actually visible, we need to do a Z-prepass to cull out occluded samples. Finally, rendering transparent geometry at the higher sample rate requires an alternative approach to the traditional SOURCE_ALPHA
, ONE_MINUS_SOURCE_ALPHA
back-to-front blending technique. For example, we can use SRC_ALPHA_SATURATE
combined with additive blending and draw primitives front-to-back.
Memory Allocations
This sample provides a counter under the FPS display, which shows the current allocated GPU memory. Due to how the GPU allocates and frees memory as needed, it may not always equal the exact amount of memory the application actually needs in order to run. If we toggle between different AA modes, we will see that the reported memory usage will depend not only on the current setting, but some history of previous settings as well. However, we should still see a general trend that TIR will require less memory than MSAA, but more than no AA at all.