Direct2D is a powerful interface for hardware accelerated rendering of 2-D textures, shapes, and text. We demonstrate the power and versatility of Direct2D custom image effects, new to Windows 8, through a GPU implementation of the Anti-Aliasing Recovery algorithm.

Photograph and high quality renderings may become aliased as the result of common filtering operations. The Anti-Aliasing Recovery effect takes such a damaged image, and recovers and applies the smooth edges from the original image.

The sample shows a number of custom effect implementation, rising in complexity from the simplest single-in/single-shader/single-out effect, to an effect built from a directed graph of D2D transforms, cascading from a pair of input images through a sequence of shaders to a final output image. The structure of the Antialiasing Recovery Effect is captured in the following diagram:

Features Explored

This application demonstrates a variety of Direct2D Custom Effects of varying complexity. There is a lot of common code between the different effects. In a production setting, this shared code could be refactored down to a few base classes based on connectivity, with specializations for setup of shaders and parameters. But they are left independent here for clarity.

EffectThreshold – Single input image / Single pixel shader / Single output image / One user parameter

EffectThreshold applies a threshold filter, setting all pixels with a greyscale value higher than the threshold to white, and all those lower to black. Accepts a single user input of threshold value. See EffectThreshold.[cpp,h,hlsl]

EffectContrast – Single input image / Single pixel shader /Single output image / Two user parameters

EffectContrast maps the input low value to zero and the high value to one. This is applied channel by channel. See hlsl file for variations. Accepts two user inputs of low value and high value. Note that high value may be less than or equal to low value. See EffectContrast.[cpp,h,hlsl].

EffectBilateral – Single input image / Single pixel shader /Single output image / Two user parameters

Similar in structure to EffectContrast, but slightly more complicated shader. Applies a bilateral filter, typically used for denoising while respecting feature edges. Two user inputs are the standard deviation of Gaussians in the spatial and color dimensions.

EffectEdge – Two input images / Single pixel shader / Single output image / No user parameters

EffectEdge is a diagnostic effect. Its output is the intermediate image computed in the first stage of the AARecEffect described below. It is interesting as a demonstration of a single shader effect which accepts multiple inputs. The shader used is the same shader as in the first transform of the AARecEffect. See EffectEdge.[cpp,h] and AARecovery\AARecInitParms.hlsl.

AARecEffect – Two input images / Multiple pixel shaders / Single output image / No user parameters

Since effects by design have a single output, this is the simplest example of the most complex graph structure buildable with Direct2D Custom Effects. The first stage, or transform, of the effect accepts the two input images, the original image and the filtered (aliased) image. These are assumed to be of equal dimensions and pixel registered. It computes an antialiased edge model for each pixel as a new image. The edge model and the aliased image are passed to the next transform, which computes an improved (antialiased) image. The edge model and each improved image are passed through the refinement transform two more iterations, producing a single output.

See all files in folder AARecovery. Effect definition (graph structure) in AARecovery\AARecEffect.cpp.

System Requirements

Operating System: Windows 8

Hardware: Shader Model 4 (DirectX 10 or higher) graphics adapter

Build Environment: Visual Studio 2012

Running the Sample

Run the sample application from the Visual Studio IDE.

Three windows will appear:

Left Window is original image, middle window is filtered (aliased) image, and right window is repaired image.

Requires mouse input (no touch interface):

Mouse wheel to zoom. Cursor over area of interest, will zoom to cursor position.

Left drag to reposition image windows.

Right drag to reposition within windows.

Right click to:

Open File – browse to new image to load. Currently supports .png and .bmp images.

Click arrows to cycle through built-in aliasing-inducing effects: Contrast enhance, threshold, and bilateral filter. Available parameter sliders appear at top of screen.

More Information

Overview of Direct2D system:

Introduction to Direct2D Effect system:

Antialiasing Recovery project page: