Search code examples
flashactionscript-3pixel-shaderpixel-bender

Turn off color ranges in Pixel Bender


What is the best way to turn turn off (using PixelBender) colors that fall within a certain range. For example, turn off all colors between 0x0000FF and 0x00FFFF. Thanks for your help. This has to work in Flash. Thanks!


Solution

  • Not sure whether this is the best way but it worked. The idea is to simulate uint color value in Pixel Bender.

    evaluatePixel()
    {
        float4 color = sampleNearest(src,outCoord());
    
        float minInt = 0.0;
        if(minColor.r > 0.0) minInt += minColor.r + 3.0;
        if(minColor.g > 0.0) minInt += minColor.g + 2.0;
        if(minColor.g > 0.0) minInt += minColor.b + 1.0;
    
        float maxInt = 0.0;
        if(maxColor.r > 0.0) maxInt += maxColor.r + 3.0;
        if(maxColor.g > 0.0) maxInt += maxColor.g + 2.0;
        if(maxColor.g > 0.0) maxInt += maxColor.b + 1.0;
    
        float colInt = 0.0;
        if(color.r > 0.0) colInt += color.r + 3.0;
        if(color.g > 0.0) colInt += color.g + 2.0;
        if(color.g > 0.0) colInt += color.b + 1.0;
    
        if(colInt >= minInt && colInt <= maxInt)
        {
            dst = float4(0.0);
        }else{
            dst = color;
        }
    }