# atan2 in vs 1.1

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

## Recommended Posts

Hello, in my vertex shader 1.1 written in HLSL I used atan2 for a per vertex horizon map texture coordinate calculation. I calculate a per vertex coordinate system resulting in three vectors S,T,R. The Lights position is L. Then I do a (1/2PI)*atan2(dot(T,L), dot(S,L)) for getting the r texture coordinate (the direction) between -0.5 and 0.5. This works quite well except for the case when dot(S,L) or dot(T,L) are zero (not at the same time) what leads to a wrong texture coordinate. Is atan2 really fully continous? Have you any idea what else goes wrong? Thank you. Markus [Edited by - muhkuh on October 14, 2004 4:16:19 AM]

##### Share on other sites
When you have a dot product = 0, then you've got orthogonal vectors.

If the range of atan2 is (-pi/2, pi/2) rather than [-pi/2, pi/2], as I suspect it is, then it won't work. And it would make sense, since tangent isn't actually defined at 90 degrees.

##### Share on other sites
From the DirectX SDK doc:

atan2 - HLSL

Syntax

ret atan2(x, y)

--------------------------------------------------------------------------------

Returns the arctangent of x/y. The signs of x and y are used to determine the quadrant of the return values in the range [-pi, pi]. atan2 is well-defined for every point other than the origin, even if y equals 0 and x does not equal 0.

##### Share on other sites
I think my problem is another. atan2 works as it should. It's the interpolation of texture coordinates that isn't working properly.

I've got a texture coordinate between 0 and 1 that corresponds to a direction (azimuth) in a horizon map. The problem are triangles with one vertex at 0.001 and another at 0.999 or something. What I want is a value between 0.999 and 1.001 or -0.001 and 0.001 as the texture adressing mode is set to repeat. What I get is something between 0.001 and 0.999 of course.

Is there any way to tell the hardware to interpolate like that?

[Edited by - muhkuh on October 12, 2004 5:36:20 AM]

##### Share on other sites
Problem solved: Texture wrapping :rollingeyes

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 10
• 9
• 15
• 22