Pixel-Composer/shaders/sh_trail_filler/sh_trail_filler.fsh

47 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2023-02-20 10:16:31 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2023-02-21 04:48:50 +01:00
#define TAU 6.283185307179586
2023-02-20 10:16:31 +01:00
uniform sampler2D prevFrame;
uniform vec2 dimension;
uniform float range;
void main() {
vec4 colCur = texture2D( gm_BaseTexture, v_vTexcoord );
2023-02-21 04:48:50 +01:00
if(colCur.a > 0.5) {
2023-02-20 10:16:31 +01:00
gl_FragColor = colCur;
return;
}
gl_FragColor = vec4(0.);
2023-02-21 04:48:50 +01:00
float aStep = TAU / 64.;
vec2 texel = 1. / dimension;
2023-02-20 10:16:31 +01:00
2023-02-21 04:48:50 +01:00
for(float i = 1.; i <= range; i++)
for(float j = 0.; j <= TAU; j += aStep) {
vec2 shift = vec2(cos(j), sin(j)) * i * texel;
2023-02-20 10:16:31 +01:00
vec2 pos0 = v_vTexcoord + shift;
if(pos0.x < 0. || pos0.y < 0. || pos0.x > 1. || pos0.y > 1.) continue;
vec4 col0 = texture2D( prevFrame, pos0 );
2023-02-21 04:48:50 +01:00
if(col0.a <= 0.5) continue;
2023-02-20 10:16:31 +01:00
2023-02-21 04:48:50 +01:00
vec2 norm = normalize(shift) * texel;
for(float k = 1.; k <= range; k++) {
vec2 posS = v_vTexcoord - norm * k;
2023-02-20 10:16:31 +01:00
if(posS.x < 0. || posS.y < 0. || posS.x > 1. || posS.y > 1.) continue;
vec4 colS = texture2D( gm_BaseTexture, posS );
2023-02-21 04:48:50 +01:00
if(colS.a <= 0.5) continue;
2023-02-20 10:16:31 +01:00
gl_FragColor = colS;
return;
}
}
}