三角波
asin使う
code:glsl
// (1/TAU)Hz, DC=0, Amp=PI/2, Delta is always abs(1)
// 1Hz, DC=0, Amp=1
#define tri(x) (asin(sin(TAU*x))/HALF_PI) absとfract使う
code:glsl
// Cheaper. 1Hz, DC=0, Amp=1
#define tri(x) (1.-4.*abs(fract(x)-0.5)) // Same as above but the wave starts from 0.0
#define tri(x) (1.-4.*abs(fract(x+0.25)-0.5)) https://gyazo.com/3c1cf442cf013ba7e2d5ae4bbed53f63
clamp使う
code:glsl
// 0.25Hz, DC=0, Amp=1, Delta is always abs(1)
float tri(float x) {
x = mod(x, 4.0) - 2.0;
return x - 2.0 * clamp(x, -1.0, 1.0);
}
https://gyazo.com/186e23fcd8a57bc3a32c124ae25eca0d