#version 430 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aUV;

out vec2 vUV;
out vec2 vFragScreenPos;

uniform vec2 uPos;
uniform vec2 uSize;
uniform vec2 uScreen;
uniform float uRotation; // radians

void main()
{
    vec2 centered = aPos - vec2(0.5);
    float s = cos(uRotation);
    float c = sin(uRotation);
    mat2 rot = mat2(c, -s, s, c);
    vec2 rotated = rot * (centered * uSize);

    vec2 finalPos = uPos + rotated;

    vFragScreenPos = finalPos;
    vUV = aUV;

    vec2 ndc = finalPos / uScreen * 2.0 - 1.0;
    gl_Position = vec4(ndc.x, -ndc.y, 0.0, 1.0); // Y flip for OpenGL
}
