0

I am new to pixel bender.

I am programming with as3. I want to do a green screen calibrator. I have manage to turn one rgb(Hex) color alpha to 0 with shader filter (with online search):

{
    input image4 src;
    output pixel4 dst;

    parameter float3 keyColor0;

    parameter float tolerance
    <
        minValue: 0.0;
        maxValue: 3.0;
        defaultValue: 0.02;
    >;

    parameter float ramp
    <
        minValue: 0.0;
        maxValue: 1.0;
        defaultValue: 0.005;
    >;

     parameter float gamma
    <
        minValue: 0.0;
        maxValue: 10.0;
        defaultValue: 1.00;
    >;

    void
    evaluatePixel()
    {
        dst = sampleNearest(src,outCoord());
        float diff = length( dst.rgb - keyColor0);
        if ( diff < tolerance )
        {
            dst.a = 0.0;
        } else if ( diff < tolerance + ramp )
        {
            dst.a = pow( (diff - tolerance) / ramp, gamma );
        }            
    }
}

But, What I would like to do is to give it two rgb colors and it will make all the colors between the two given rgb(Hex) colors to set alpha 0 as well.

For example I pick a range of colors from a image. It is a set of difference green colors, then I find the min and max out of the set of colors by using HSV.

With the min and max, I would like to set all colors between the two colors to alpha 0.

Thanks

  • Given that Pixel Bender filters are pixel-based, you need to do the pre-processing outside of the shader, then feed the value(s) to the shader and make it check HSV of its current pixel, and make alpha 0 if HSV region of this pixel match the supplied pair. Note that you will have to make complex checks on HSV values of a grabbed "current" pixel. – Vesper Jun 10 '16 at 08:13
  • Hi @Vesper, I have tried something like: { dst = sampleNearest(src,outCoord()); float luminance = dst.r * 0.29900 + dst.g * 0.58700 + dst.b * 0.14400; float u = - dst.r * 0.14714 - dst.g * 0.28886 + dst.b * 0.43600; float v = dst.r * 0.61500 - dst.g * 0.51499 - dst.b * 0.10001; float hue = atan( v, u ); float saturation = length(float2( u,v)); } from [link](http://www.quasimondo.com/archives/000696.php) also pass two rgb color and did the same thing, but still not working. Could you give me a hand, please?Thanks – Martin Chan Jun 16 '16 at 10:30
  • hmm, you can use that YUV color representation to separate hue/sat based colors, you will have to measure distance from this pixel's UV to the *line* between two other UVs provided to the shader, and if it's close enough, drop that alpha. It's just a matter of coding some geometry. PS you'd better pre-process as much as you can, meaning you should give UVs to the shader directly. – Vesper Jun 16 '16 at 14:43

0 Answers0