struct Output
{
    float4 Color : TEXCOORD0;
    float2 UV : TEXCOORD1;
    float4 Position : SV_Position;
};

#include "RootConstants.hlsl"

struct Vertex
{
    float2 Pos;
    float2 UV;
    uint   Color;
};

Output main(uint vertexIndex : SV_VertexID)
{
    Output output;

    ByteAddressBuffer buffer = ResourceDescriptorHeap[BufferIndex];

    uint actualVertexIndex = vertexIndex + VertexOffset;

    uint stride = 20;
    uint offset = actualVertexIndex * stride;

    float2 pos = asfloat(buffer.Load2(offset));
    float2 uv  = asfloat(buffer.Load2(offset + 8));
    uint col   = buffer.Load(offset + 16);

    float4 c;
    c.x = float(col & 0xFF) / 255.0f;
    c.y = float((col >> 8) & 0xFF) / 255.0f;
    c.z = float((col >> 16) & 0xFF) / 255.0f;
    c.w = float((col >> 24) & 0xFF) / 255.0f;

    output.Position = float4(pos * Scale + Translate, 0.0f, 1.0f);
    output.Color = c;
    output.UV = uv;
    
    return output;
}

