source: opengl-game/shaders/explosion.vert

feature/imgui-sdl
Last change on this file was 67527a5, checked in by Dmitry Portnoy <dportnoy@…>, 3 years ago

Switch all per-object buffers to be dynamic uniform buffers instead of shader storage buffers

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#version 450
2#extension GL_ARB_separate_shader_objects : enable
3
4struct Object {
5 mat4 model;
6 float explosion_start_time;
7 float explosion_duration;
8 bool deleted;
9};
10
11layout (binding = 0) uniform camera_block {
12 mat4 view;
13 mat4 proj;
14 float cur_time;
15} camera;
16
17layout(binding = 1) uniform ubo_block {
18 Object objects[1024];
19} ubo;
20
21layout(location = 0) in vec3 particle_start_velocity;
22layout(location = 1) in float particle_start_time;
23layout(location = 2) in uint obj_index;
24
25layout(location = 0) out float opacity;
26
27void main() {
28 mat4 model = ubo.objects[obj_index].model;
29 float explosion_start_time = ubo.objects[obj_index].explosion_start_time;
30 float explosion_duration = ubo.objects[obj_index].explosion_duration;
31 bool deleted = ubo.objects[obj_index].deleted;
32
33 float t = camera.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 = camera.proj * camera.view * model * vec4(p, 1.0);
59 }
60 gl_PointSize = 10.0; // size in pixels
61}
Note: See TracBrowser for help on using the repository browser.