#version 330 core

in vec2 uv;
out vec4 FragColor;

uniform vec3 iResolution;
uniform float iTime;
uniform float uAlpha;
uniform float uStartDelay;
uniform sampler2D iChannel0;

void main()
{
    float t = iTime - uStartDelay;
    if (t < 0.0) discard;

    vec2 fragCoord = uv * iResolution.xy;
    vec2 fragUv = fragCoord.xy / iResolution.xy;

    const float amount = 0.035;
    const float speed = 2.5;

    vec2 uvRed = fragUv;
    vec2 uvBlue = fragUv;
    float s = abs(sin(t * speed)) * amount;
    uvRed.x += s;
    uvBlue.x -= s;

    vec4 result = texture(iChannel0, fragUv);

    result.r = texture(iChannel0, uvRed).r;
    result.b = texture(iChannel0, uvBlue).b;

    result.a *= uAlpha;

    FragColor = result;
}
