#version 450 struct RectangleInstance { vec4 rect; vec4 color; vec4 borderColor; vec4 borderAttr; }; layout(set = 0, binding = 0) readonly buffer RectangleInstances { RectangleInstance data[]; } rectInstances; layout(location = 0) out vec4 out_color; layout(location = 1) out vec4 out_borderColor; layout(location = 2) out vec2 out_local; // pixel-space pos relative to rect center layout(location = 3) out vec2 out_halfSize; layout(location = 4) out vec2 out_borderRound; // borderWidth, roundness layout(set = 1, binding = 0) uniform PushConstants { vec4 params; // window width, height, and instance-buffer offset } pc; void main() { RectangleInstance rectangle = rectInstances.data[gl_InstanceIndex + uint(pc.params.z)]; vec2 rectPos = rectangle.rect.xy; vec2 rectSize = rectangle.rect.zw; vec2 cornerOffset = vec2( float(gl_VertexIndex & 1), float((gl_VertexIndex >> 1) & 1) ); vec2 pixelPos = rectPos + (cornerOffset * rectSize); vec2 ndc = (pixelPos / pc.params.xy) * 2.0 - 1.0; ndc.y = -ndc.y; gl_Position = vec4(ndc, 0.0, 1.0); out_local = (cornerOffset - 0.5) * rectSize; // centered, pixel units out_halfSize = rectSize * 0.5; out_color = rectangle.color; out_borderColor = rectangle.borderColor; out_borderRound = rectangle.borderAttr.xy; }