#version 450 // Per instance; layout must match SpriteRenderSystem::Instance. layout (location = 0) in mat4 model; // Maps the unit quad to world space. layout (location = 4) in vec4 color; layout (location = 5) in vec4 uvRect; layout (location = 0) out vec4 fragColor; layout (location = 1) out vec2 fragUv; layout (push_constant) uniform Push { mat4 viewProjection; } push; // Two triangles covering the unit quad (0,0)-(1,1). const vec2 CORNERS[6] = vec2[]( vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0), vec2(1.0, 1.0), vec2(0.0, 1.0), vec2(0.0, 0.0) ); void main() { vec2 corner = CORNERS[gl_VertexIndex]; gl_Position = push.viewProjection * model * vec4(corner, 0.0, 1.0); // Draw order comes from the CPU-side sort, so flatten depth; sprites should // never be clipped by the camera's near/far planes. gl_Position.z = 0.0; fragColor = color; fragUv = mix(uvRect.xy, uvRect.zw, corner); }