atan in fragment program?

Hi all,

My application needs to access the atan function in a fragment program.
I noticed that this function is available in GLSL, but I already hand optimized my code using the arb fragment program.
Is there any way to access the atan function in arb fragment program or nv fragment program?

I tried using a texture lookup table, but since the input argument ranges from -inf to inf, I had to clamp the the texture and set the limit values in the edge pixels. Also, because it evolves slowly, I either needed a large texture which reduced performance or a small texture which didn’t have enough accuracy near zero. I could not find a good tradeoff between them.

Nico

Two thoughts:

  1. Find a way to map 0 to 1 texture values to -inf to inf.
  2. Would a polynomial approximation of atan be sufficient?

Thanks for the reply endash.

I’ll try a mcLauren series approximation of the atan function.

Like you suggestes,I can also try it with textures, using 1/(x+constant) for texture access and setting texture mirror once.

Thx for the tips!

Nico

Apparently, the Euler approximation converges faster (and thus needs fewer terms for approximation).

Also, because atan() goes very flat outside the middle range, you could use texture coordinate clamping, and map, say, the range [-10,10] to a texture, and just set the min and max values to -pi/2 and pi/2 respectively.

Everything you ever wanted to know about atan() is available at http://mathworld.wolfram.com/InverseTangent.html by the way (and then some).