views:

442

answers:

1

Hi there,

I am using the following code to create a dynamic reflection of an image:

{
input image4 src;
output pixel4 dst;

parameter float imageheight
<
    minValue: 0.0;
    maxValue : 1000.0;
    defaultValue :300.0;

>;

parameter float fadeheight
<
    minValue : 0.0;
    maxValue: 1000.0;
    defaultValue: 50.0;
>;

parameter float fadealpha
<
    minValue : 0.0;
    maxValue : 1.0;
    defaultValue : 0.5;
>;

void
evaluatePixel()
{
    float2 coord = outCoord();

    if ( coord[ 1 ] < imageheight ) {
        dst = sampleNearest(src, coord );
    } else {

        float alpha = 1.0 - ( coord[ 1 ] - imageheight ) / fadeheight;

        coord[ 1 ] = imageheight - ( coord[ 1 ] - imageheight );

        dst = sampleNearest( src, coord );            
        alpha *= fadealpha;
        dst.a *= alpha;
        dst.r *= alpha;
        dst.g *= alpha;
        dst.b *= alpha;

        float2 pos = outCoord();
        pixel4 color = sampleNearest(src,pos);

        color+=0.75*sampleNearest(src, pos+float2(0.5*2, 0))+0.25*sampleNearest(src, pos+float2(2, 0));
        color+=0.75*sampleNearest(src, pos-float2(0.5*2, 0))+0.25*sampleNearest(src, pos-float2(2, 0)); 
        color+=0.75*sampleNearest(src, pos+float2(0, 0.5*2))+0.25*sampleNearest(src, pos+float2(0, 2));
        color+=0.75*sampleNearest(src, pos-float2(0, 0.5*2))+0.25*sampleNearest(src, pos-float2(0, 2));

        dst = color/5.0;
    }       
}

}

It's working nicely, but I'd really like to blur the output of the reflection slightly to give it a glossy look. I've had a google, but all the results seem incredibly complicated. Is creating a blur effect (similar to the Flash inbuilt filter) very difficult to do in Pixel Bender?

In this instance, I am not able to apply the Flash filter, so it has to be done in Pixel Bender.

+2  A: 

It's quite simple actually, all you need to do is take a create a new image of the same size, and then make each pixel of it an average of the pixels at that position and surrounding in the image you want to blur. The output is more blurry the more pixels you take. For example you could blur each pixel with the pixels above, below, left and right. Or you could use the pixel and all 8 others touching... If you want you can also give the previous pixel value more weight than the surrounding ones, for a different effect. Best way is to just try stuff out until you get the desired effect.

By the way that first kind of blur is referred to as "Average". The latter way can be done by using a Gaussian distribution to weight the pixels if you're using many of them - a Gaussian blur.

KernelJ