Pixel-Composer/shaders/sh_erode/sh_erode.fsh

69 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2023-12-23 09:39:55 +01:00
uniform int border;
uniform int alpha;
uniform vec2 size;
uniform int sizeUseSurf;
uniform sampler2D sizeSurf;
2022-01-13 05:24:03 +01:00
2023-02-23 07:02:19 +01:00
#define TAU 6.283185307179586
2022-01-13 05:24:03 +01:00
2023-12-23 09:39:55 +01:00
float bright(in vec4 col) { return dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)) * col.a; }
2022-01-13 05:24:03 +01:00
void main() {
vec2 pixelPosition = v_vTexcoord * dimension;
vec4 point = texture2D( gm_BaseTexture, v_vTexcoord );
2023-12-23 09:39:55 +01:00
vec4 fill = vec4(0.);
2023-01-25 06:49:00 +01:00
if(alpha == 0) fill.a = 1.;
2022-01-13 05:24:03 +01:00
gl_FragColor = point;
2023-12-23 09:39:55 +01:00
if(alpha == 0 && length(point.rgb) <= 0.) return;
if(alpha == 1 && point.a <= 0.) return;
float siz = size.x;
2024-04-21 12:06:54 +02:00
float sizMax = siz;
2023-12-23 09:39:55 +01:00
if(sizeUseSurf == 1) {
2024-04-21 12:06:54 +02:00
sizMax = max(size.x, size.y);
2023-12-23 09:39:55 +01:00
vec4 _vMap = texture2D( sizeSurf, v_vTexcoord );
siz = mix(size.x, size.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
2024-04-21 12:06:54 +02:00
for(float i = 1.; i <= sizMax; i++) {
if(i > siz) break;
2023-01-25 06:49:00 +01:00
2023-02-23 07:02:19 +01:00
float base = 1.;
float top = 0.;
for(float j = 0.; j <= 64.; j++) {
float ang = top / base * TAU;
top += 2.;
if(top >= base) {
top = 1.;
base *= 2.;
}
vec2 pxs = (pixelPosition + vec2( cos(ang) * i, sin(ang) * i)) / dimension;
if(border == 1)
pxs = clamp(pxs, vec2(0.), vec2(1.));
2023-01-25 06:49:00 +01:00
2023-02-23 07:02:19 +01:00
if(pxs.x < 0. || pxs.x > 1. || pxs.y < 0. || pxs.y > 1.) {
gl_FragColor = fill;
break;
}
vec4 sam = texture2D( gm_BaseTexture, pxs );
if((alpha == 0 && length(sam.rgb) * sam.a == 0.) || (alpha == 1 && sam.a == 0.)) {
gl_FragColor = fill;
break;
}
2022-01-13 05:24:03 +01:00
}
}
}