Pixel-Composer/shaders/sh_atlas/sh_atlas.fsh

46 lines
981 B
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2022-12-27 04:00:50 +01:00
#define TAU 6.283185307179586
2024-04-27 14:10:39 +02:00
#define distance_sample 32.
2022-01-13 05:24:03 +01:00
void main() {
2024-04-11 05:51:13 +02:00
vec2 tx = 1. / dimension;
2024-04-27 14:10:39 +02:00
vec2 px = v_vTexcoord * dimension;
2022-01-13 05:24:03 +01:00
vec4 col = texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor = col;
2024-04-11 05:51:13 +02:00
if(col.a == 1.)
2022-12-27 04:00:50 +01:00
return;
2024-04-27 14:10:39 +02:00
bool samp = false;
float angular_sample = distance_sample * TAU * 2.;
2023-02-23 07:02:19 +01:00
for(float i = 1.; i <= distance_sample; i++) {
float base = 1.;
float top = 0.;
2024-04-27 14:10:39 +02:00
float minDist = 9999.;
2024-04-11 05:51:13 +02:00
2024-04-27 14:10:39 +02:00
for(float j = 0.; j <= angular_sample; j++) {
float ang = j / angular_sample * TAU;
vec2 pxs = floor(px + vec2( cos(ang), sin(ang)) * i) + 0.5;
vec2 txs = pxs * tx;
vec4 sam = texture2D( gm_BaseTexture, txs );
float dst = distance(px, pxs);
2023-02-23 07:02:19 +01:00
2024-04-27 14:10:39 +02:00
if(sam.a < 1. || dst > minDist) continue;
2022-12-27 04:00:50 +01:00
2023-02-23 07:02:19 +01:00
gl_FragColor = sam;
2024-04-27 14:10:39 +02:00
// gl_FragColor = vec4(vec3(i / distance_sample), 1.);
minDist = dst;
samp = true;
2023-02-23 07:02:19 +01:00
}
2024-04-27 14:10:39 +02:00
if(samp) return;
2022-01-13 05:24:03 +01:00
}
}