Can you use integers as bools in HLSL just like in C++?

Started by
3 comments, last by dfcollinson 11 years, 6 months ago
In C++ you can have:


int a = 5;
if(a)
{
for(int i = 0;i < a: i++)
{
DoSomething();
}
}


Can you do the same in HLSL?If you could,it would be really convenient to both check if an effect is enabled to begin with and to serve as a parameter to the said effect.
Advertisement
Anything that isn't null is true. I still don't understand why you'd want to do that.
There is no such thing as "null" in HLSL. Integers used as conditionals work similarly to how they do in C/C++, where non-zero values equate to a value of "true".

In C++ you can have:


int a = 5;
if(a)
{
for(int i = 0;i < a: i++)
{
DoSomething();
}
}


Can you do the same in HLSL?If you could,it would be really convenient to both check if an effect is enabled to begin with and to serve as a parameter to the said effect.


it works perfectly, but i would still do the additional

if(a != 0)
// readability
null = 0, you know what I meant.

This topic is closed to new replies.

Advertisement