Below is another simple Pixel Bender filter that I created last night. This one basically, converts an image to gray scale, using the ITU-R Recommendation BT.709 algorithm described here.
Here is the filter:
<languageVersion : 1.0;>
kernel GrayScale
< namespace : "mesh";
vendor : "Mike Chambers";
version : 1;
description : "Gray scale filter";
>
{
input image4 src;
output pixel4 dst;
void
evaluatePixel()
{
dst = sampleNearest(src,outCoord());
//algorithm from ITU-R Recommendation BT.709
//http://local.wasp.uwa.edu.au/~pbourke/texture_colour/imageprocess/
float avg = 0.2125 * dst.r + 0.7154 * dst.g + 0.0721 * dst.b;
dst = float4(avg, avg, avg, dst.a);
}
}
Again, its pretty simple, but I am trying to learn both Pixel Bender and image processing in general. The biggest thing I learned for this example is how to work with different vector sizes (which can be a little confusing). Im still wrapping my head around it, but once I get it down, Ill make a post on vectors in Pixel Bender.
After seeing all of the cool stuff people have been doing with Pixel Bender, I finally decided to spend a little time and start learning how to build them myself.
The learning curve isn’t too difficult, although you do have to learn some new concepts, and deal with some limitations (at least when creating filters for Flash). The most difficult part for me thus far, is just understanding color and pixel math and manipulation (something I need to read up on more).