| [845a2cb] | 1 | #version 450
 | 
|---|
 | 2 | #extension GL_ARB_separate_shader_objects : enable
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 | struct Object {
 | 
|---|
 | 5 |    mat4 model;
 | 
|---|
 | 6 |    float explosion_start_time;
 | 
|---|
 | 7 |    float explosion_duration;
 | 
|---|
 | 8 |    bool deleted;
 | 
|---|
 | 9 | };
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | layout (binding = 0) uniform UniformBufferObject {
 | 
|---|
 | 12 |    mat4 view;
 | 
|---|
 | 13 |    mat4 proj;
 | 
|---|
 | 14 |    float cur_time;
 | 
|---|
 | 15 | } ubo;
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | layout(binding = 1) readonly buffer StorageBufferObject {
 | 
|---|
 | 18 |    Object objects[];
 | 
|---|
 | 19 | } sbo;
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | layout(location = 0) in vec3 particle_start_velocity;
 | 
|---|
 | 22 | layout(location = 1) in float particle_start_time;
 | 
|---|
 | 23 | layout(location = 2) in uint obj_index;
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | layout(location = 0) out float opacity;
 | 
|---|
 | 26 | 
 | 
|---|
 | 27 | void main() {
 | 
|---|
 | 28 |    /*
 | 
|---|
 | 29 |    mat4 model = sbo.objects[obj_index].model;
 | 
|---|
 | 30 |    float explosion_start_time = sbo.objects[obj_index].explosion_start_time;
 | 
|---|
 | 31 |    float explosion_duration = sbo.objects[obj_index].explosion_duration;
 | 
|---|
 | 32 |    bool deleted = sbo.objects[obj_index].deleted;
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |    float t = ubo.cur_time - explosion_start_time - particle_start_time;
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 |    if (t < 0.0) {
 | 
|---|
 | 37 |       opacity = 0.0;
 | 
|---|
 | 38 |    } else {
 | 
|---|
 | 39 |       // Need to find out the last time this particle was at the origin
 | 
|---|
 | 40 |       // If that is greater than the duration, hide the particle
 | 
|---|
 | 41 |       float cur = floor(t / explosion_duration);
 | 
|---|
 | 42 |       float end = floor((explosion_duration - particle_start_time) / explosion_duration);
 | 
|---|
 | 43 |       if (cur > end) {
 | 
|---|
 | 44 |          opacity = 0.0;
 | 
|---|
 | 45 |       } else {
 | 
|---|
 | 46 |          opacity = 1.0 - (t / explosion_duration);
 | 
|---|
 | 47 |       }
 | 
|---|
 | 48 |    }
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 |    if (deleted) {
 | 
|---|
 | 51 |       gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
 | 
|---|
 | 52 |    } else {
 | 
|---|
 | 53 |       //  this is the center of the explosion
 | 
|---|
 | 54 |       vec3 p = vec3(0.0, 0.0, 0.0);
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |       // allow time to loop around so particle emitter keeps going
 | 
|---|
 | 57 |       p += normalize(particle_start_velocity) * mod(t, explosion_duration) / explosion_duration * 0.3;
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 |       gl_Position = ubo.proj * ubo.view * model * vec4(p, 1.0);
 | 
|---|
 | 60 |    }
 | 
|---|
 | 61 |    */
 | 
|---|
 | 62 |    opacity = 1.0;
 | 
|---|
 | 63 |    gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
 | 
|---|
 | 64 |    gl_PointSize = 100.0; // size in pixels
 | 
|---|
 | 65 | }
 | 
|---|