Friday, January 23, 2009

error C1019: scalar Boolean expression expected

While working on my GPU raytracer, I've come across the following Cg error a few times: error C1019: scalar Boolean expression expected. Weirdly, it only threw this error on the machines at school (the Cg shader code is compiled at run-time). Though the line numbers don't make this clear, the problem code appears to be this:

float4 val = readFloat4FromTexture();
if (val != float4(1,1,1,1)) {
...
}


I haven't investigated why this works at home and not school (different Cg compiler versions?), but I fixed it by changing to this:

...
if (val.x != 1 && val.y != 1 && val.z != 1 && val.w != 1) {
...
}


I wasn't able to find *anything* about the error on Google or in the Cg documentation, so hopefully this is useful if anyone else has this problem.

2 comments:

Unknown said...

Bump. Coincidentally, I'm actually getting this same issue with my Cg Raytracer. Hmm, here's my code:

if((info.point.z > -h/2.f) && (info.point < h/2.f))
info.num = 1;

info.normal = info.point; //<-- happens here
info.color = color;

... not sure if that helps. I haven't tested mine at school, so I can't confirm if different versions of cg have an effect.

I'll post if I get it.

Unknown said...

Oh wait, I got mine working just now. that second info.point should have a .z

I bet cgc just doesn't like comparing vectors directly for some reason (boolean values can only be scalars?).