2011-02-23 120 views

回答

0

不知道这是否是最好的方式,但它的工作。这个想法是模拟Pixel Bender中的uint颜色值。

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; 
    } 
} 
0

如果你的意思是每个频道“之间”,这是一个简单的方法来做到这一点。

<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; 
    } 
} 
+0

谢谢@sean,这不是很完美,因为我不得不根据颜色的数值键入一个范围。 – 2011-02-25 15:41:12