#version 450

layout(location = 0) in vec4 color;
layout(location = 1) in vec2 lt_pos;
layout(location = 2) in vec2 br_pos;
layout(location = 3) in vec2 lt_tex;
layout(location = 4) in vec2 br_tex;
layout(location = 5) in uint tex_ind;

layout(push_constant, std430) uniform pc {
    float width;
    float height;
};

layout (location=0) flat out vec4 vsout_color;
layout (location=1) out vec2 vsout_tex_cord;
layout (location=2) flat out uint vsout_tex_ind;

float lint(float A1, float B1, float A2, float B2, float x){
    return A2 + (B2 - A2) * (x - A1) / (B1 - A1);
}

float deng(float B1, float x){
    return lint(0, B1, -1, 1, x);
}

void main(){
    const vec2 all_v_pos[6] = vec2[](
        vec2(br_pos.x, lt_pos.y), lt_pos, vec2(lt_pos.x, br_pos.y),
        vec2(br_pos.x, lt_pos.y), vec2(lt_pos.x, br_pos.y), br_pos
    );
    const vec2 all_v_tex[6] = vec2[](
        vec2(br_tex.x, lt_tex.y), lt_tex, vec2(lt_tex.x, br_tex.y),
        vec2(br_tex.x, lt_tex.y), vec2(lt_tex.x, br_tex.y), br_tex
    );
    vsout_color = color;
    vsout_tex_cord = all_v_tex[gl_VertexIndex % 6];
    vsout_tex_ind = tex_ind;
    vec2 pos = all_v_pos[gl_VertexIndex % 6];
    gl_Position = vec4(deng(width, pos.x), deng(height, pos.y), 0, 1);
}
