Jump to content
  • Advertisement
Sign in to follow this  
jaafit

sin/cos in HLSL vs_2_0

This topic is 4139 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

How exactly are sin/cos supposed to work in HLSL? I'm getting two very different results from what looks like the same code:
	float theta = 0;
	windUV.x = cos(theta) * worldPos.x - sin(theta) * worldPos.y;
	windUV.y = sin(theta) * worldPos.x + cos(theta) * worldPos.y;



The above results in the same value for windUV for each vertex.
	windUV.x = cos(0) * worldPos.x - sin(0) * worldPos.y;
	windUV.y = sin(0) * worldPos.x + cos(0) * worldPos.y;



The above works as expected. ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Asesh
The argument to sin/cos is the angle in radians


Shouldn't really make a difference.

Keep in mind, the shader compiler probably optimises out the entire second example and just sets the variables to 0 instead of going through the sin/cos.

Share this post


Link to post
Share on other sites
I'd suggest looking at the resulting assembly code, and seeing what the difference is.

Share this post


Link to post
Share on other sites
Indeed, the only difference between the two samples is that one will invoke the sin and cos functions each frame and the other compiles them out to static code. Neglecting floating-point error, they are equivalent. Are you sure that the error can't lie elsewhere?

If not, then perhaps your problems are floating-inaccuracy-based. I'm not sure if video hardware treats sin and cos of zero as special cases, but if it doesn't, and your camera happens to be zoomed in on a patch of land that is very far away from the origin, the minute imprecision may be scaled up arbitrarily.

Admiral

Share this post


Link to post
Share on other sites
Another way to check this further would be to change the first example to assign cos(theta) and sin(theta) to variables and look at them.

Also, when you say that you get the same value for windUV, knowing what value might provide a clue.

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!