Pixel-Composer/shaders/sh_sdf_dist/sh_sdf_dist.fsh

30 lines
657 B
Text
Raw Normal View History

2023-02-14 02:48:33 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D original;
2023-02-14 02:48:33 +01:00
uniform int side;
uniform int alpha;
uniform int invert;
2023-02-14 02:48:33 +01:00
uniform float max_distance;
void main() {
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord );
2024-08-30 11:08:30 +02:00
float aa = alpha == 1? texture2D( original, v_vTexcoord ).a : 1.;
2023-11-15 02:35:30 +01:00
if(col.xy == vec2(0.)) {
2024-08-30 11:08:30 +02:00
gl_FragColor = vec4(vec3(0.), aa);
2023-11-15 02:35:30 +01:00
return;
}
2023-02-14 02:48:33 +01:00
float dist = (max_distance - distance(col.xy, v_vTexcoord)) / max_distance;
2024-08-30 11:08:30 +02:00
if(invert == 1) dist = 1. - dist;
2023-02-14 02:48:33 +01:00
if((side == 0 && col.z == 0.) || (side == 1 && col.z == 1.)) {
2024-08-30 11:08:30 +02:00
gl_FragColor = vec4(vec3(col.z), aa);
2023-02-14 02:48:33 +01:00
return;
}
gl_FragColor = vec4(vec3(dist), aa);
2023-02-14 02:48:33 +01:00
}