2022-01-13 05:24:03 +01:00
|
|
|
//
|
|
|
|
// Simple passthrough fragment shader
|
|
|
|
//
|
|
|
|
varying vec2 v_vTexcoord;
|
|
|
|
varying vec4 v_vColour;
|
|
|
|
|
|
|
|
uniform vec2 dimension;
|
|
|
|
uniform float tolerance;
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
bool sameColor(in vec4 c1, in vec4 c2) { return length(c1.rgb * c1.a - c2.rgb * c2.a) <= tolerance; }
|
|
|
|
int sameColorInt(in vec4 c1, in vec4 c2) { return sameColor(c1, c2)? 1 : 0; }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
void main() {
|
2023-07-25 20:12:40 +02:00
|
|
|
vec2 tx = 1. / dimension;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
vec4 a0 = texture2D( gm_BaseTexture, v_vTexcoord + vec2(-tx.x, -tx.y));
|
|
|
|
vec4 a1 = texture2D( gm_BaseTexture, v_vTexcoord + vec2( 0., -tx.y));
|
|
|
|
vec4 a2 = texture2D( gm_BaseTexture, v_vTexcoord + vec2( tx.x, -tx.y));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
vec4 a3 = texture2D( gm_BaseTexture, v_vTexcoord + vec2(-tx.x, 0.));
|
|
|
|
vec4 a4 = texture2D( gm_BaseTexture, v_vTexcoord );
|
|
|
|
vec4 a5 = texture2D( gm_BaseTexture, v_vTexcoord + vec2( tx.x, 0.));
|
|
|
|
|
|
|
|
vec4 a6 = texture2D( gm_BaseTexture, v_vTexcoord + vec2(-tx.x, tx.y));
|
|
|
|
vec4 a7 = texture2D( gm_BaseTexture, v_vTexcoord + vec2( 0., tx.y));
|
|
|
|
vec4 a8 = texture2D( gm_BaseTexture, v_vTexcoord + vec2( tx.x, tx.y));
|
|
|
|
|
|
|
|
gl_FragColor = a4;
|
|
|
|
if(sameColor(a1, a4)) return;
|
|
|
|
|
|
|
|
bool sideEqual = sameColor(a1, a3) && sameColor(a1, a5) && sameColor(a1, a7);
|
|
|
|
if(!sideEqual) return;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
int cornerEqual = sameColorInt(a1, a0)
|
|
|
|
+ sameColorInt(a1, a2)
|
|
|
|
+ sameColorInt(a1, a6)
|
|
|
|
+ sameColorInt(a1, a8);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
if(cornerEqual == 4)
|
|
|
|
gl_FragColor = a0;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|