Search code examples
actionscript-3flashapache-flexflash-builder

Gradient Map Filter - Pixel Bender for AS3


i need some help to create a filter in Pixel Bender for AS3 to make this effect in the right side in this image:

http://a.imageshack.us/img829/1488/gradientmap.jpg

Can you help me?

Thank you.


Solution

  • A little late, but this seems to do the trick:

    <languageVersion : 1.0;>
    
    kernel Darken
    <   namespace : "omino";
        vendor : "omino";
        version : 1;
        description : "darken the right part of an image";
    >
    {
        input image4 src;
        output pixel4 dst;
    
        parameter float leftEdgeOfEffect <minValue: 0.0 ; maxValue: 2000.0; defaultValue: 200.0;>;
        parameter float darkness <minValue: 0.0 ; maxValue: 1.0; defaultValue: 0.75;>;
    
        void
        evaluatePixel()
        {
            float2 co = outCoord();
            pixel4 p = sampleNearest(src,co);
            if(co.x >= leftEdgeOfEffect)
                p.rgb = p.rgb * (1.0 - darkness);
            dst = p;
        }
    }
    

    The actual pixel manipulation happens here: p.rgb = p.rgb * (1.0 - darkness);

    It's just darkening the R, G, and B. You could get trickier here for more interesting effects.