Hello.
Microsoft lists a HLSL boolean "?" operator here: http://msdn.microsof..._Math_Operators but then gives absolutely no information about it, examples or otherwise.
Does anybody know what this is and how to use it?
Thanks
HLSL boolean "?" operator ?
It works like it does in a normal programming language, so you probably never used it before anywhere
int y=x<10?0:1 // == if(x<10) y= 0 else y=1
Hello.
Microsoft lists a HLSL boolean "?" operator here: http://msdn.microsof..._Math_Operators but then gives absolutely no information about it, examples or otherwise.
Does anybody know what this is and how to use it?
It's actually the ?: operator. In C++, and I'm guessing HLSL too, the ternary operator is used like this:
(boolean-statement) ? (result-if-true) : (result-if-false)
It's a short-hand form of writing this:
if(boolean-statement)
return result-if-true;
else
return result-if-false;
Example:
bool lastNameFirst;
std::cout << (lastNameFirst? "Henry, John" : "John Henry");
Another example: (return the larger of the two values)
int maxValue = (valueA > valueB ? valueA : valueB);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement