struct VSInput {
    float2 pos;
    float2 scale;
    float2 uv;
    float4 color;
    float  alpha;

    uint vertex_index : SV_VertexID;
};

struct VSOutput {
    float4 pos : SV_POSITION;
    float2 uv;
    float4 color;
    float alpha;
    //uint32_t tex_id;
};

struct Uniforms {
    float4x4 proj;
};

ConstantBuffer<Uniforms> uniforms : register(b1);

Texture2D colorTexture : register(t0);
SamplerState samplerState;

static const float2 square[6] = {
    float2(-0.5, -0.5), // Top-left
    float2(-0.5,  0.5), // Bottom-left
    float2( 0.5, -0.5), // Top-right

    float2( 0.5, -0.5), // Top-right
    float2(-0.5,  0.5), // Bottom-left
    float2( 0.5,  0.5)  // Bottom-right
};

[shader ("vertex")]
VSOutput vs_main(VSInput input) {
    VSOutput output;

    float2 vertex_pos = square[input.vertex_index % 6];
    float2 final_pos = (vertex_pos * input.scale) + input.pos;

    output.pos = mul(uniforms.proj, float4(final_pos, 0.0, 1.0));
    output.uv = input.uv;
    output.color = input.color;
    output.alpha = input.alpha;
    //output.tex_id = input.textureID;

    return output;
}

[shader("fragment")]
float4 fs_main(VSOutput input) {
    float4 texColor = colorTexture.Sample(samplerState, input.uv);
    return texColor * float4(input.color.rgb, input.alpha);
}
