-
Notifications
You must be signed in to change notification settings - Fork 10
/
trail.gdshader
43 lines (31 loc) · 869 Bytes
/
trail.gdshader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
shader_type particles;
render_mode keep_data,disable_force,disable_velocity;
void process() {
// CUSTOM.w tracks the particles place in the trail, in range (0..LIFETIME]
// requires that LIFETIME = number of particles
float amount = LIFETIME;
vec4 a = EMISSION_TRANSFORM * vec4(0,1,0,1);
vec4 b = EMISSION_TRANSFORM * vec4(0,-1,0,1);
// start
if(CUSTOM.w == 0.0){
CUSTOM.w = float(INDEX)+1.0;
// needed to pass to draw pass
CUSTOM.z = amount;
// needed to initialize in case of CUSTOM.w == 2.0
TRANSFORM = mat4(a,a,b,b);
}
// restart
if(CUSTOM.w == amount+1.0){
CUSTOM.w = 1.0;
}
if(CUSTOM.w == 1.0){
// sets the quad to the line to cache this frame, it is not yet visible
TRANSFORM = mat4(a,a,b,b);
}
if(CUSTOM.w == 2.0){
// sets the right edge of the quad
TRANSFORM[1] = a;
TRANSFORM[2] = b;
}
CUSTOM.w++;
}