HLSL to GLSL atan2 Function

Anyone know if there is a GLSL equivalent to HLSLs ‘atan2’ function?

alx

Just use atan(y,x), it’s the equivalent of atan2 in the range [-Pi,Pi].
atan(y/x) is in the range [-Pi/2,Pi/2].

N.

Hi -NiCo-

thanks for getting back to me.
So, I just multiply the result of atan by 2.0 to get the same result as the HLSL atan2 function.

Cheers,

alx

No,

HLSL atan2(x,y) == GLSL atan(y,x)

GLSL provides two atan-operators. One taking 1 parameter and one taking 2 parameters. The one with 2 parameters is the equivalent of atan2.

N.

I see, thanks -NiCo-.
There must be some other reason my HLSL conversion isn’t producing the expected result then…

alx

That shouldn’t be hard to debug…
Make sure that you get the parameter ordering correct. In HLSL it’s (x,y) while in GLSL it’s (y,x)

N.

Cheers -NiCo-!

Ah, yes, I did notice that. Thanks once again!
What I actually in my previous post was, there’s probably some other issues with the code, now that I have been able to eliminate the atan/atan2 issue, thanks to your advice.

alx

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.