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