Graphics Reference
In-Depth Information
Examples of these two filters' effects are shown in Figure 11.5 and are
compared with an original unblurred image, both to show you the blurred
images and to let you compare the amount of blurring generated by each of
these filters. Because blurring is not very easy to see in reduced-size natural-
istic images, we have chosen an original visualization image whose edges are
particularly pronounced.
Below is a fragment shader that applies the 3 × 3 blur convolution filter
above to a set of pixels to blur an image. The computation is done without
formal matrix multiplication as the pixels with weight 1.0 are gathered, as are
those with weight 2.0 and the single pixel with weight 4, and the result is
divided by the overall weight. The code for a 5 × 5 blur filter would look quite
similar, and both are included with the resources for this topic; the diference
is that four additional pixel addresses are needed, and 25 individual pixel col-
ors are generated, instead of the nine shown here.
uniform sampler2D uImageUnit;
in vec2 vST
out vec4 fFragColor;
void main( )
{
ivec2 ires = textureSize( uImageUnit, 0 );
float ResS = float( ires.s );
float ResT = float( ires.t );
vec3 irgb = texture( uImageUnit, vST ).rgb;
vec2 stp0 = vec2(1./ResS, 0. ); // texel offsets
vec2 st0p = vec2(0. , 1./ResT);
vec2 stpp = vec2(1./ResS, 1./ResT);
vec2 stpm = vec2(1./ResS, -1./ResT);
// 3x3 pixel colors next
vec3 i00 = texture( uImageUnit, vST ).rgb;
vec3 im1m1 = texture( uImageUnit, vST-stpp ).rgb;
vec3 ip1p1 = texture( uImageUnit, vST+stpp ).rgb;
vec3 im1p1 = texture( uImageUnit, vST-stpm ).rgb;
vec3 ip1m1 = texture( uImageUnit, vST+stpm ).rgb;
vec3 im10 = texture( uImageUnit, vST-stp0 ).rgb;
vec3 ip10 = texture( uImageUnit, vST+stp0 ).rgb;
vec3 i0m1 = texture( uImageUnit, vST-st0p ).rgb;
vec3 i0p1 = texture( uImageUnit, vST+st0p ).rgb;
Search WWH ::




Custom Search