Fast, inaccurate sin function without searching

For the ocean shader, I need a quick function that calculates a very approximate value for sin (x). The only requirement is periodicity and roughly resembles a sine wave.

The Taylor series of sin is too slow, since I need to calculate to the 9th power of x to get the full period.

Any suggestions?

EDIT: Sorry, I didn’t mention, I cannot use the lookup table since this is in the vertex shader. The lookup table will include a texture sample, which is slower in the vertex shader than the built-in sin function. It doesn't have to be accurate, you just need to look good.

+5
source share
5

Chebyshev , . , , (-Ο€.. + Ο€ 0.. 2Ο€), . 2 3 9.

+6

sin .

+2

, , . 2/pi -2/pi [0, pi/2], [pi/2, 3 * pi/2], [3 * pi/2, 2 * pi ]. mod 2 * pi.

+1

sin (x) :

f = (C1 * x) / (C2 * x^2 + 1.) 

:

c1 =   1.043406062 
c2 =  .2508691922 

, DHFTI, . 0 & pi;/2, - :

IF (t  < pi) THEN
  IF (t < pi/2) THEN
    x = t
  ELSE
      x = pi - t
   END IF
 ELSE 
   IF (t < (3./2)*pi) THEN
     x = t - pi
  ELSE
     x = twopi - t
   END IF
END IF

:

f = (C1 * x) / (C2 * x*x + 1.0)
IF (t > pi) f = -f

[0, 2 & pi;], x mod 2 & pi;

5% .

+1

, , .

0

All Articles