Jump to content

  • Log In with Google      Sign In   
  • Create Account

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.


  • You cannot reply to this topic
4 replies to this topic

#1   Members   

360
Like
0Likes
Like

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.

#2   Members   

484
Like
0Likes
Like

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.

#3   Moderators   

18184
Like
0Likes
Like

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

#4   Members   

737
Like
0Likes
Like

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

#5   Members   

484
Like
0Likes
Like

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.