MoonWorksComputeSpriteBatch/shaders/spritebatch.comp

45 lines
778 B
Plaintext
Raw Normal View History

2022-01-18 04:39:23 +00:00
#version 450
struct Vertex
{
vec3 position;
vec2 texcoord;
};
// Binding 0: vertices
layout(set = 0, binding = 0) buffer Vertices
{
Vertex vertices[ ];
};
// Binding 1: transform matrices
layout(set = 0, binding = 1) buffer Transforms
{
mat4 transforms[ ];
};
layout(set = 2, binding = 0) uniform UBO
{
uint vertexCount;
} ubo;
layout (local_size_x = 256) in;
void main()
{
// Current buffer index
uint index = gl_GlobalInvocationID.x;
// Don't write past particle count
if (index >= ubo.vertexCount)
{
return;
}
uint transformIndex = index / 4;
mat4 transform = transforms[transformIndex];
vec4 position = vec4(vertices[index].position, 1.0);
vertices[index].position = vec3(transform * position);
}