- Home /
Question by
Tim-Michels · Dec 20, 2016 at 02:41 PM ·
mathshader programming
How can I get shader variable to map into a certain range?
I have a shader variable that expresses an angle. This value is a float an can be large numbers (multiple rotations)
Now I need to map that value to fit within the range of -PI and PI.
Here's a dirty example: (used degrees for this example, just to express the main idea)
float angle = 370;
while(angle > 360) angle -= 360;
while(angle < -360) angle += 360;
Is there a mathematical way or a shader function that provides this functionality? Basically I want to replace those 2 while-statements with something that's much faster.
Thanks in advance,
Tim
Comment
Your answer
Follow this Question
Related Questions
Changing the Play Rate (Frequency) of a sine wave in real-time 1 Answer
problem with mathf.tan 2 Answers
Need a little help with quick angle equation 2 Answers
CharacterController on Moving Surface 4 Answers