Graphics Reference
In-Depth Information
Figure 14-13
Anti-aliased Checkerboard Procedural Texture
the average value of
(v)
of the region covered by this pixel. To determine
this region, we need to know the rate of change of
g(v)
. The OpenGL ES
Shading Language 3.00 contains derivative functions we can use to compute
the rate of change of
g(v)
in
x
and
y
using the functions
dFdx
and
dFdy
.
The rate of change, called the gradient vector, is given by
[dFdx(g(v))
,
dFdy(g(v))]
. The magnitude of the gradient vector is computed as
sqrt
((dFdx(g(v))2 + dFdx(g(v))2)
. This value can also be approximated by
abs(dFdx(g(v)))+abs(dFdy(g(v)))
. The function
fwidth
can be used to
compute the magnitude of this gradient vector. This approach works well if
g(v)
is a scalar expression. If
g(v)
is a point, however, we need to compute
the cross-product of
dFdx(g(v))
and
dFdy(g(v))
. In the case of the
checkerboard texture example, we need to compute the magnitude of the
v_st
.
x
and
v_st.y
scalar expressions and, therefore, the function
fwidth
can be used to compute the filter widths for
v_st.x
and
v_st.y
.
Let
w
be the filter width computed by
fwidth
. We need to know two
additional things about the procedural texture:
• The smallest value of filter width
k
such that the procedural texture
g(v)
will not show any aliasing artifacts for filter widths less than
k/2
.
• The average value of the procedural texture
g(v)
over very large widths.
If
w < k/2
, we should not see any aliasing artifacts. If
w > k/2
(i.e., the
filter width is too large), aliasing will occur. We use the average value