Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
celyk committed Sep 20, 2023
1 parent 8dce4c6 commit f6fc64c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion shaders/trail.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ shader_type particles;

render_mode keep_data,disable_force,disable_velocity;

uniform vec3 acceleration = vec3(0,1,0);

const float fixed_dt = 1.0/60.0;
void simulate(inout vec3 pos0, inout vec3 vel0, inout vec3 pos1, inout vec3 vel1, float dt) {
vel0 += acceleration * dt;
vel1 += acceleration * dt;

pos0 += vel0 * dt;
pos1 += vel1 * dt;
}

void process() {
// CUSTOM.w tracks the particles place in the trail, in range (0..LIFETIME]
Expand All @@ -21,22 +30,38 @@ void process() {

// needed to initialize in case of CUSTOM.w == 2.0
TRANSFORM = mat4(a,a,b,b);
VELOCITY = vec3(0);
COLOR.xyz = vec3(0);
}

vec3 pos0 = (TRANSFORM[0] + TRANSFORM[3]).xyz/2.0;
vec3 pos1 = (TRANSFORM[1] + TRANSFORM[2]).xyz/2.0;
vec3 d0 = pos0;
vec3 d1 = pos1;
simulate(pos0,VELOCITY,pos1,COLOR.xyz,DELTA);
TRANSFORM[0].xyz += pos0 - d0;
TRANSFORM[3].xyz += pos0 - d0;
TRANSFORM[1].xyz += pos1 - d1;
TRANSFORM[2].xyz += pos1 - d1;

// 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);
VELOCITY = vec3(0);
COLOR.xyz = vec3(0);
}

if(CUSTOM.w == 2.0){
// sets the right edge of the quad
TRANSFORM[1] = a;
TRANSFORM[2] = b;

COLOR.xyz = vec3(0);
}

CUSTOM.w++;
Expand Down

0 comments on commit f6fc64c

Please sign in to comment.