Converting pixel bender to AS3

467 views Asked by At

I'm writing an android app using AIR + AS3. Since pixel bender files are not supported in GPU mode, I'm trying to convert this chroma key filter to pure AS3. Any suggestions, tools or help will be appreciated:

<languageVersion : 1.0;>



kernel DifferenceKey

<   namespace : "com.quasimondo";

    vendor : "Quasimondo";

    version : 1;

    description : "A simple difference key for chroma keying";

>

{

    input image4 src;

    output pixel4 dst;



    parameter float3 keyColor;



    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 - keyColor );

        if ( diff < tolerance )

        {

            dst.a = 0.0;

        } else if ( diff < tolerance + ramp )

        {

            dst.a = pow( (diff - tolerance) / ramp, gamma );

        }



    }

}
1

There are 1 answers

3
jpop On BEST ANSWER

I'm afraid it won't work that way. Iterating over every pixel in AS3 will probably be painfully slow (which is why pixel bender was originally made), even more so on mobile which have puny CPUs (compared to desktops).

I would suggest you look in to Stage3D which leverages graphic card to do the heavy lifting (pretty much the only way to achieve decent performance with flash on mobile) and various frameworks based on it. Starling for 2D graphics, Feathers for UI (based on Starling), Away3D for full blown 3D stuff. That's where momentum is right now, especially on mobile. Stage3D supports various blend modes and filters which might help you easily achieve what you're looking for. Unfortunately, converting old school display list app to Starling isn't trivial, but IMHO it's worth it.

Starling

Feathers UI

Away3D