varying vec2 v_TexCoord;
varying vec2 v_Position;
uniform sampler2D u_Tex0;
uniform float u_Time;

// CONFIG
float speed = 10.0;
float height = 11.5;
float angle = 45.0; // degrees
float intensity = 0.8;
// CONFIG END

vec2 rotate(vec2 v, float a) {
    float s = sin(a);
    float c = cos(a);
    mat2 m = mat2(c, -s, s, c);
    return m * v;
}

void main()
{
    gl_FragColor = texture2D(u_Tex0, v_TexCoord);

    vec2 p = rotate(v_Position, (angle / 180.0) * 3.14);
    float frame = mod(p.y, height);
    float timeFrame = mod(u_Time * speed, height);
    float dist = min(abs(frame - timeFrame), min(abs(frame - timeFrame - height), abs(frame - timeFrame + height)));
    gl_FragColor.xyz *= intensity / sqrt(max(1.0, dist));

    if(gl_FragColor.a < 0.01) discard;
}
