1

当我运行以下像素弯曲代码时:

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

我收到以下错误消息:

错误:(第 21 行):':':错误的操作数类型不存在操作':',它采用'const float' 类型的左操作数和'4-component vector of float' 类型的右操作数(或有是不可接受的转换)

请指教

4

2 回答 2

1

从错误消息中,我觉得 Pixel Bender 不支持三元 (?:) 运算符。将其扩展为 if 语句:

if (distance(current.rgb, color) < threshold)
    dst = float4(0.0);
else
    dst = float4(current);
于 2009-03-18T18:17:55.840 回答
0

我不熟悉 Pixel Bender,但我猜问题是三元?:运算符的最后两个参数必须是相同的类型:

A = condition ? B : C

B并且C必须具有相同的类型,该类型必须与A. 在这种情况下,看起来您正在尝试制作float4s,因此您应该这样做:

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

这样最后两个参数 (float4(0.0)current) 都具有 type float4

于 2009-03-18T18:20:57.203 回答