#version 330 core

layout(location = 0) in vec2 aLocal;
layout(location = 1) in vec2 aUV;

out vec2 vUV;
out vec2 vLocal;

uniform vec2 iResolution;
uniform vec4 uRect;
uniform float uRotation;
uniform float uTime;
uniform float uWaveAmount;
uniform float uWaveSpeed;

void main()
{
    vUV = aUV;
    vLocal = aLocal;

    vec2 pos = uRect.xy + aLocal * uRect.zw;
    float wave = sin((aLocal.x * 8.0) + uTime * uWaveSpeed) * uWaveAmount;
    pos.y += wave;

    vec2 center = uRect.xy + uRect.zw * 0.5;
    float c = cos(uRotation);
    float s = sin(uRotation);
    vec2 d = pos - center;
    pos = center + vec2(d.x * c - d.y * s, d.x * s + d.y * c);

    vec2 ndc = vec2(pos.x / iResolution.x * 2.0 - 1.0, 1.0 - pos.y / iResolution.y * 2.0);
    gl_Position = vec4(ndc, 0.0, 1.0);
}
