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 0x00开发者_Python百科00FF and 0x00FFFF. Thanks for your help. This has to work in Flash. Thanks!
If you mean per channel "between", here is a simple way to do it.
<languageVersion : 1.0;>
kernel untitled
< namespace : "Your Namespace";
vendor : "Your Vendor";
version : 1;
>
{
input image4 src;
output pixel4 dst;
parameter float rThreshold
<
minValue: 0.0;
maxValue: 1.0;
defaultValue: 0.0;
>;
parameter float gThreshold
<
minValue: 0.0;
maxValue: 1.0;
defaultValue: 0.0;
>;
parameter float bThreshold
<
minValue: 0.0;
maxValue: 1.0;
defaultValue: 0.0;
>;
void
evaluatePixel()
{
pixel4 sourcePixel = sampleNearest(src,outCoord());
if(sourcePixel.r <= rThreshold) sourcePixel.r = 0.0;
if(sourcePixel.g <= gThreshold) sourcePixel.g = 0.0;
if(sourcePixel.b <= bThreshold) sourcePixel.b = 0.0;
dst = sourcePixel;
}
}
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;
}
}
精彩评论