source: opengl-game/explosion.vert@ dc19a39

feature/imgui-sdl points-test
Last change on this file since dc19a39 was dc19a39, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Make explosion objects use the global model mat uniform buffer and a varying ubo index attribute to access it

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