#version 450
// Per-instance data (input_rate = INSTANCE in the pipeline)
layout(location=0) in vec2 center;
layout(location=1) in vec2 halfsize;
layout(location=2) in vec4 col;
layout(location=0) out vec2 v_uv;
layout(location=1) out vec4 v_col;
void main() {
    // gl_VertexIndex cycles 0..5 per instance (6 vertices = 2 triangles)
    // Vertex order: TL TR BL | TR BR BL  (CCW winding)
    const vec2 offsets[6] = vec2[6](
        vec2(-1.0, 1.0), vec2(1.0, 1.0), vec2(-1.0,-1.0),
        vec2( 1.0, 1.0), vec2(1.0,-1.0), vec2(-1.0,-1.0)
    );
    const vec2 uvs[6] = vec2[6](
        vec2(0.0,0.0), vec2(1.0,0.0), vec2(0.0,1.0),
        vec2(1.0,0.0), vec2(1.0,1.0), vec2(0.0,1.0)
    );
    int vid = gl_VertexIndex;
    gl_Position = vec4(center + offsets[vid] * halfsize, 0.0, 1.0);
    v_uv  = uvs[vid];
    v_col = col;
}
