]> Witch of Git - lovr-particles/blob - shaders/particles.vert
Render lots of particles with SSBOs!
[lovr-particles] / shaders / particles.vert
1 in vec2 vertPosition;
2 out vec2 uv;
3 uniform vec3 headPos;
4 uniform int batchSize;
5 layout(std430) buffer particleDataBuffer { vec4 particleData[]; };
6
7 vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
8 int index = gl_VertexID / 4 + gl_InstanceID * batchSize;
9 vec3 pos = particleData[index].xyz;
10 float size = particleData[index].w;
11 uv = vertPosition * 0.5 + 0.5;
12
13 vec3 forward = normalize(pos - headPos);
14 vec3 right = normalize(cross(forward, vec3(0, 1, 0)));
15 vec3 up = cross(right, forward);
16 vec3 offset = mat2x3(up, right) * (vertPosition * size);
17
18 return projection * transform * vec4(pos + offset, 1.0);
19 }