Fast Estimated Sine and Cosine
From XNAWiki
These are by no means 100% accurate sine and cosine functions, but they are pretty good estimates which are considerably faster than the GPU functions on some older GPUs. These aren't really intended to be used in a low frequency scenario, but instead in a scenario where your using a lot of sine and cosines per shader execution.
#ifndef FAST_SINCOS
#define FAST_SINCOS
float Sine(float x)
{
const float B = 4 / Pi;
const float C = -4 / (Pi * Pi);
const float P = 0.225;
x = x % Pi;
x = B * x + C * x * abs(x);
x = P * (x * abs(x) - x) + x;
return x;
}
float Cosine(float x)
{
x = x + PiOver2;
x = x + (min(sign(Pi - x), 0) * TwoPi);
return Sine(x);
}
void SinCosine(float v, out float2 sc)
{
const float B = 4 / Pi;
const float C = -4 / (Pi * Pi);
const float P = 0.225;
sc = float2(v % Pi, (v + PiOver2));
sc.y = (sc.y + (min(sign(Pi - sc.y), 0) * TwoPi)) % Pi;
sc = B * sc + C * sc * abs(sc);
sc = P * (sc * abs(sc) - sc) + sc;
}
void SinCosine(float v, out float x, out float y)
{
float2 sc;
SinCosine(v, sc);
x = sc.x;
y = sc.y;
}
#endif