tags:

views:

350

answers:

2

When I run the following pixel bender code:

input image4 src;
output float4 dst;

// How close of a match you want
parameter float threshold
<
  minValue:     0.0;
  maxValue:     1.0;
  defaultValue: 0.4;
>;

// Color you are matching against.
parameter float3 color
<
  defaultValue: float3(1.0, 1.0, 1.0);
>;

void evaluatePixel()
{
  float4 current = sampleNearest(src, outCoord());
  dst = float4((distance(current.rgb, color) < threshold) ? 0.0 : current);
}

I got the following error message:

ERROR: (line 21): ':' : wrong operand types no operation ':' exists that takes a left-hand operand of type 'const float' and a right operand of type '4-component vector of float' (or there is no acceptable conversion)

Please advice

+1  A: 

From the error message, it sounds to me like Pixel Bender doesn't support the ternary (?:) operator. Expand it out into an if-statement:

if (distance(current.rgb, color) < threshold)
    dst = float4(0.0);
else
    dst = float4(current);
Chad Birch
Chad Birch,thanks you, it seems it work! you are great!
Hi michael, if it works, please accept Chad's answer as the answer for your question :-)
unforgiven3
unforgiven3, thanks, because I am not fimilar with the site.
A: 

I'm not familiar with Pixel Bender, but I'm guessing the problem is that the last two arguments of the ternary ?: operator must be the same type:

A = condition ? B : C

B and C must have the same type, which must be the same type as A. In this case, it looks like you're trying to make float4s, so you should do:

dst = (distance(current.rgb, color) < threshold) ? float4(0.0) : current;

So that both of the last arguments (float4(0.0) and current) have type float4.

Adam Rosenfield
Thanks, Adam, your answer work also. Thank you.