in vec2 texCoord;
out vec4 fragColor;

uniform sampler2D texture0;
uniform float horizontalScrollAmount;
uniform float verticalScrollAmount;
uniform float mirrorX;
uniform float mirrorY;

void main()
{
    vec2 uv = texCoord.st;

    float xDir = uv.x < 0.5 ? -1.0 : 1.0;
    float yDir = uv.y < 0.5 ? -1.0 : 1.0;

    uv.x = fract(uv.x + xDir * horizontalScrollAmount);
    uv.y = fract(uv.y + yDir * verticalScrollAmount);

    if (mirrorX >= 0.5 && uv.x > 0.5) {
        uv.x = 1.0 - uv.x;
    }

    if (mirrorY >= 0.5 && uv.y > 0.5) {
        uv.y = 1.0 - uv.y;
    }

    fragColor = texture(texture0, uv);
}
