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 | mat4 model = sbo.objects[obj_index].model;
|
---|
29 | float explosion_start_time = sbo.objects[obj_index].explosion_start_time;
|
---|
30 | float explosion_duration = sbo.objects[obj_index].explosion_duration;
|
---|
31 | bool deleted = sbo.objects[obj_index].deleted;
|
---|
32 |
|
---|
33 | float t = ubo.cur_time - explosion_start_time - particle_start_time;
|
---|
34 |
|
---|
35 | if (t < 0.0) {
|
---|
36 | opacity = 0.0;
|
---|
37 | } else {
|
---|
38 | // Need to find out the last time this particle was at the origin
|
---|
39 | // If that is greater than the duration, hide the particle
|
---|
40 | float cur = floor(t / explosion_duration);
|
---|
41 | float end = floor((explosion_duration - particle_start_time) / explosion_duration);
|
---|
42 | if (cur > end) {
|
---|
43 | opacity = 0.0;
|
---|
44 | } else {
|
---|
45 | opacity = 1.0 - (t / explosion_duration);
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (deleted) {
|
---|
50 | gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
|
---|
51 | } else {
|
---|
52 | // this is the center of the explosion
|
---|
53 | vec3 p = vec3(0.0, 0.0, 0.0);
|
---|
54 |
|
---|
55 | // allow time to loop around so particle emitter keeps going
|
---|
56 | p += normalize(particle_start_velocity) * mod(t, explosion_duration) / explosion_duration * 0.3;
|
---|
57 |
|
---|
58 | gl_Position = ubo.proj * ubo.view * model * vec4(p, 1.0);
|
---|
59 | }
|
---|
60 | gl_PointSize = 10.0; // size in pixels
|
---|
61 | } |
---|