GPU. Indeed L shapes detection imply deep dynamic
branching and quasi-random access patterns in the
frame which cripples cache efficiency (Nvidia, 2007).
Moreover, as a post-processing technique, MLAA is
unable to handle small scale geometry aliasing, and
as a relatively local filter can suffer from poor tem-
poral coherence, which induces flickering artifacts in
animation. Finally, using luminance for discontinuity
computation can lead to poor quality on RGB render-
ing.
3 MLAA ON THE GPU
3.1 Overview
The initial algorithm was entirely redesigned to fit
with a GPU GLSL implementation thus allowing di-
rect usage in any rendering engine. GPU detection
and storage of L shapes can be avoided since the
main objective is to compute the area of the covering
trapeze on each pixel along discontinuity lines. This
area can be computed using the pixel position on the
L shape. Our algorithm will therefore detect discon-
tinuity segments, determine relative positions of pix-
els along these segments, compute covering trapeze
areas and then do the final blending. The figure 3
shows an overview of the algorithm and samples for
each of these stages. Complete source code, including
shaders, can be found (Biri and Herubel, 2010).
discontinuity
detection
distance
propagation
blending map
computation
pixel
blending
Figure 3: Algorithm overview.
3.2 Discontinuities Detection
In this stage, we seek color discontinuities between
two neighboring pixels. For greyscale images, we de-
tect discontinuity presence if the difference between
greyscale values exceeds a user defined value called
the discontinuity factor, chosen between 0. and 1. For
color images we could use this factor as a threshold
in the luminance of the pixels. However in RGB, red
and blue share the same luminance leading to aliasing
artifacts on textures. Therefore we switch to CIELAB
color space where we are able to compute a color dif-
ference directly based on human perception (Kang,
2006). This discontinuity detection pass creates a tex-
ture containing, for each pixel, the existence of a dis-
continuity at its bottom and its right border. These
two booleans are stored in two different texture chan-
nels.
We also use this first stage to initialize the texture
storing discontinuity line lengths. We simply write 1
to the left and right distance of any pixel belonging to
horizontal lines and 1 to up and down distance to the
ones belonging to vertical lines. This is done simply
using MRT.
3.3 Distance Propagation
In this stage, we want to compute the distance in num-
ber of pixel, from any pixel along discontinuity lines
to their two extremities. In fact, we will propagate
distance from the extremities. This is done in left
and right direction for horizontal lines and on up and
down directions for vertical ones. Adding these two
lengths also gives us the total length of the horizontal
(resp vertical) discontinuity line minus one. And of
course, it gives us the position of the pixel relatively
to this line which will be useful in the next step. All
lengths will be computed in pixel distance.
To propagate the distance to the extremities of
lines, we will use a modification of the recursive dou-
bling approach (Dubois and Rodrigue, 1977; Hensley
et al., 2005). The computation will be done in up to
four steps. The first one will compute length distance
up to four pixels, the second one up to 16, the third
one up to 64 and the final one, up to 256. At each
step, for a given pixel X, we look at its distance d(X)
(for instance for left direction), fetch distance of the
texel at d(X) distance (at left) and add it to the current
distance d(X). Updating the distance is given by :
d(X) := d(X) + d(X.x − d(X).x,X.y) (1)
We do the same for right, up and down direction. We
also do that three times at each step. Figure 4 illus-
trates computation of left distance for the two first
steps of this stage. The reason we split the compu-
tation in several step is that, you can check, for each
step and pixel, if the pixel’s distance is below the max-
imum length we can obtain from the previous step. If
so, the pixel distance is already computed and can be
discarded.
Since distance will be stored in 8-bit precision, we
will restrict ourselves to 255 line length (in pixel).
The interest is that the four distance can be stored in
a regular RGBA texture. You need two such textures
in order to update distance, one texture for reading (in
the shader), and one for writing.
3.4 Computing Blending Factors
To this point we have computed the discontinuity seg-
ments, their lengths and the relative position of any
MORPHOLOGICAL ANTIALIASING AND TOPOLOGICAL RECONSTRUCTION
189