#version 430 core

layout (location = 0) in vec2 aPos;

layout (location = 1) in vec2 iPos;
layout (location = 2) in vec2 iSize;
layout (location = 3) in float iRot;
layout (location = 4) in vec4 iColor;
layout (location = 5) in float iRoundness; // 0 to 1 rounded

uniform vec2 uScreen;

out vec4 vColor;
out float vRoundness;
out vec2 vUV;


void main()
{
    float cosR = cos(iRot);
    float sinR = sin(iRot);

    vec2 scaled = aPos * iSize;
    vec2 rotated = vec2(
        scaled.x * cosR - scaled.y * sinR,
        scaled.x * sinR + scaled.y * cosR
    );

    vec2 finalPos = iPos + rotated;

    gl_Position = vec4((finalPos / uScreen * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0);
    
    // Map [-0.5, 0.5] to [0.0, 1.0]
    vUV = aPos + vec2(0.5);
    vColor = iColor;
    vRoundness = iRoundness;
}
