Implement compute-shader simulation of particles!
[lovr-particles] / shaders / particles.vert
1 in vec2 vertPosition;
2 out vec2 uv;
3
4 uniform vec3 headPos;
5 uniform int batchSize;
6
7 struct particle_t {
8 vec4 positionAndSize;
9 vec4 velocity;
10 vec4 padding2; // for LÖVR's limited ShaderBlock type :(
11 vec4 padding3; // for LÖVR's limited ShaderBlock type :(
12 };
13 layout(std430) buffer particleData {
14 float reloadFlag;
15 particle_t particles[];
16 };
17
18 vec4 position(mat4 projection, mat4 transform, vec4 vertex) {
19 int index = gl_VertexID / 4 + gl_InstanceID * batchSize;
20 particle_t particle = particles[index];
21 vec3 pos = particle.positionAndSize.xyz;
22 float size = particle.positionAndSize.w;
23 uv = vertPosition * 0.5 + 0.5;
24
25 vec3 forward = normalize(pos - headPos);
26 vec3 right = normalize(cross(forward, vec3(0, 1, 0)));
27 vec3 up = cross(right, forward);
28 vec3 offset = mat2x3(up, right) * (vertPosition * size);
29
30 return projection * transform * vec4(pos + offset, 1.0);
31 }