Jump to content
  • Advertisement
Sign in to follow this  
lomateron

sign(a)

This topic is 1470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just discovered that sign() is slow,and that it returns an int
 
So is there shorter faster code to do something like this?
 
float3 a;
if (a.x>0.0f){ a.x = 1.0f; } else{a.x = -1.0f;}
if (a.y>0.0f){ a.y = 1.0f; } else{a.y = -1.0f;}
if (a.z>0.0f){ a.z = 1.0f; } else{a.z = -1.0f;}

 

Share this post


Link to post
Share on other sites
Advertisement

You can try doing: "a = (a > 0) * 2 - 1;" Depending on architecture, that may (or may not) be faster. (We use several different options, depending on platform, for example).

Share this post


Link to post
Share on other sites

Ah, sorry - in our actual scenario, we're operating on the Face semantic (or equivalent), which works differently on different platforms. There are some cases where it's already a bool, so we do less math. On all platforms where it's a float, we either use sign or the above math.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!