Skip to main content
gamedev.net
🔒 Locked

HLSL - problems with isinf(x) function

Started by blairhartley 1 reply 1.7k views
Original Post
blairhartley
blairhartley
I'm using the isinf(x) function in a pixel shader to trap some calculation I'm doing spiralling to infinity. My code looks something like this...

float4 my_vector;

// Calculations on my_vector in here...

if (isinf(my_vector))
    // Do something here...
I get a compilation error saying "float expected". However the DirectX documentation for isinf(x) suggests "x" can be a scalar, vector or matrix. What have I done wrong here? Incidentally, what I am assuming from trying to make this call is that isinf will return TRUE if any of the components of my_vector are +/- infinity. Is that correct? I have tried the following... if ((isinf(my_vector.x) + isinf(my_vector.y) + isinf(my_vector.z) + isinf(my_vector.a)) > 0) and it's worked fine, but I assumed if I could use isinf(my_vector), that it would be faster.
xyzzy00
xyzzy00
You're right: "isinf()" will work with scalar, vector, or matrix types. It will test each component and return a similarly sized scalar, vector, or matrix of booleans. The "if()" statement requires the condition to be scalar. What you probably want to write is:
if(any(isinf(my_vector)))  // do something

xyzzy
blairhartley
blairhartley
Many thanks xyzzy00 - that explains it! It all works fine now...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.