Should I just use the built-in sin() function or my custom sine function?
I'm concerned about performance here. I don't care about accuracy much here because I use it to just get wave effects in my shader.
The shader is for mobile platforms (OpenGL ES)
Here's my code
float customSin(float x){
x = fract( 0.75 + x*0.159155 )*2.0 - 1.0;
return x*x * (6.0 - 4.0*x) - 1.0;
}
Here's my algorithm
x is the input, y is the output
r = 0.75 + x/(π*2)
a = | r- floor(r) - 0.5 |*2
y = ( 3(a^2) - 2(a^3) )*2 - 1
I checked the graph, and it's pretty close to the actual sine.
Which one should I go with?