Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
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++?

4: Adsense

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 mrheisenberg   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 Daniel_RT   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 MJP   Moderators   

19483
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 Muzzy A   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 Daniel_RT   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.