source: opengl-game/explosion.vert@ 39ac76d

feature/imgui-sdl points-test
Last change on this file since 39ac76d was 646f3f2, checked in by Dmitry Portnoy <dmp1488@…>, 6 years ago

Make explosions render correctly whenever a ship is destroyed.

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[db06984]1#version 410 core
2
[fe5e3ca]3#define MAX_NUM_OBJECTS 1024
4
5uniform mat4 view, proj;
6uniform mat4 model_mat;
7layout (std140) uniform models {
8 mat4 model_mats[MAX_NUM_OBJECTS];
9};
[adb104f]10
11uniform float explosion_start_time;
12uniform float cur_time;
[db06984]13
14layout (location = 0) in vec3 v_i; // initial velocity
15layout (location = 1) in float start_time;
[fe5e3ca]16//layout(location = 2) in uint ubo_index;
[db06984]17
18out float opacity;
19
20void main() {
[adb104f]21 float duration = 0.5;
22 float t = cur_time - explosion_start_time - start_time;
[db06984]23
[adb104f]24 if (t < 0.0) {
25 opacity = 0.0;
26 } else {
27 // Need to find out the last time this particle was at the origin
28 // If that is greater than the duration, hide the particle
29 float cur = floor(t / duration);
30 float end = floor((duration - start_time) / duration);
31 if (cur > end) {
32 opacity = 0.0;
33 } else {
34 opacity = 1.0 - (t / duration);
35 }
36 }
[db06984]37
[adb104f]38 vec3 p = vec3(0.0, 0.0, 0.0); // this is the center of the explosion
39 vec3 a = vec3(0.0, 0.1, 0.0);
40 p += normalize(v_i) * mod(t, duration) / duration * 0.3; // allow time to loop around so particle emitter keeps going
[db06984]41
[646f3f2]42 //gl_Position = proj * view * model_mats[ubo_index] * vec4(p, 1.0);
43 gl_Position = proj * view * model_mats[0] * vec4(p, 1.0);
[db06984]44 gl_PointSize = 15.0; // size in pixels
45}
Note: See TracBrowser for help on using the repository browser.