• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1mrheisenberg  Members

Posted 14 October 2012 - 04:00 PM

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.

### #2Daniel_RT  Members

Posted 14 October 2012 - 05:20 PM

Anything that isn't null is true. I still don't understand why you'd want to do that.

### #3MJP  Moderators

Posted 14 October 2012 - 09:44 PM

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".

### #4Muzzy A  Members

Posted 14 October 2012 - 10:12 PM

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

### #5Daniel_RT  Members

Posted 15 October 2012 - 03:23 AM

null = 0, you know what I meant.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.