像素弯曲机白色到透明

时间:2009-03-18 18:11:21

标签: pixel-bender

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

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-vector vector of float'的右操作数(或者没有可接受的转换)

请咨询

2 个答案:

答案 0 :(得分:1)

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

if (distance(current.rgb, color) < threshold)
    dst = float4(0.0);
else
    dst = float4(current);

答案 1 :(得分:0)

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

A = condition ? B : C

BC必须具有相同的类型,其类型必须与A相同。在这种情况下,看起来你正试图制作float4,所以你应该这样做:

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

这样最后两个参数(float4(0.0)current)都有float4类型。

相关问题