#version 330 core
out vec4 color;
in vec2 TexCoord;

uniform sampler2D textTexture;
uniform float time_f;
uniform vec2 iResolution;

mat2 rotationMatrixZ(float angle) {
    return mat2(
        cos(angle), -sin(angle),
        sin(angle),  cos(angle)
    );
}

vec2 vortexDistortion(vec2 uv, float time) {
    vec2 center = vec2(0.5, 0.5);
    vec2 offset = uv - center;
    float distance = length(offset);
    float angle = atan(offset.y, offset.x) + sin(time + distance * 10.0) * 0.5;
    return center + vec2(cos(angle), sin(angle)) * distance;
}

void main(void) {
    vec2 tc = TexCoord;
    vec2 uv = tc;
    float angle = time_f * 0.5;
    mat2 rotation = rotationMatrixZ(angle);
    uv = (rotation * (uv - 0.5)) + 0.5;
    uv = vortexDistortion(uv, time_f);
    vec4 texColor = texture(textTexture, uv);
    color = texColor;
}

