Pixel-Composer/shaders/sh_image_trace/sh_image_trace.fsh

35 lines
816 B
Text
Raw Normal View History

2024-01-22 10:26:25 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
vec2 tx;
bool sample(float x, float y) {
vec2 pos = v_vTexcoord + vec2(tx.x * x, tx.y * y);
if(pos.x < 0. || pos.y < 0. || pos.x > 1. || pos.y > 1.) return true;
2024-01-22 10:26:25 +01:00
vec4 c = texture2D( gm_BaseTexture, pos );
return (c.r + c.g + c.b) * c.a == 0.;
2024-01-22 10:26:25 +01:00
}
void main() {
tx = 1. / dimension;
vec4 cc = texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor = vec4(0.);
if(cc.a == 0.) return;
bool s1 = sample(-1., 0.);
bool s2 = sample( 1., 0.);
bool s3 = sample(0., -1.);
bool s4 = sample(0., 1.);
if(s1 && s2) return;
if(s3 && s4) return;
2024-01-22 10:26:25 +01:00
if(s1) { gl_FragColor = vec4(1.); return; }
if(s2) { gl_FragColor = vec4(1.); return; }
if(s3) { gl_FragColor = vec4(1.); return; }
if(s4) { gl_FragColor = vec4(1.); return; }
2024-01-22 10:26:25 +01:00
}