feature/imgui-sdl
points-test
Last change
on this file since 8fbd34f was adb104f, checked in by Dmitry Portnoy <dmp1488@…>, 6 years ago |
Make the explosion shader only emit particles for a short time instead of forever and make it look more like an explosion
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | #version 410 core
|
---|
2 |
|
---|
3 | // TODO: Pass the explosion center in as a uniform
|
---|
4 |
|
---|
5 | uniform float explosion_start_time;
|
---|
6 | uniform float cur_time;
|
---|
7 |
|
---|
8 | layout (location = 0) in vec3 v_i; // initial velocity
|
---|
9 | layout (location = 1) in float start_time;
|
---|
10 |
|
---|
11 | out float opacity;
|
---|
12 |
|
---|
13 | void main() {
|
---|
14 | float duration = 0.5;
|
---|
15 | float t = cur_time - explosion_start_time - start_time;
|
---|
16 |
|
---|
17 | if (t < 0.0) {
|
---|
18 | opacity = 0.0;
|
---|
19 | } else {
|
---|
20 | // Need to find out the last time this particle was at the origin
|
---|
21 | // If that is greater than the duration, hide the particle
|
---|
22 | float cur = floor(t / duration);
|
---|
23 | float end = floor((duration - start_time) / duration);
|
---|
24 | if (cur > end) {
|
---|
25 | opacity = 0.0;
|
---|
26 | } else {
|
---|
27 | opacity = 1.0 - (t / duration);
|
---|
28 | }
|
---|
29 | }
|
---|
30 |
|
---|
31 | vec3 p = vec3(0.0, 0.0, 0.0); // this is the center of the explosion
|
---|
32 | vec3 a = vec3(0.0, 0.1, 0.0);
|
---|
33 | p += normalize(v_i) * mod(t, duration) / duration * 0.3; // allow time to loop around so particle emitter keeps going
|
---|
34 |
|
---|
35 | gl_Position = vec4(p, 1.0);
|
---|
36 | gl_PointSize = 15.0; // size in pixels
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.