2023-01-04 02:30:04 +01:00
|
|
|
//
|
|
|
|
// Simple passthrough fragment shader
|
|
|
|
//
|
|
|
|
varying vec2 v_vTexcoord;
|
|
|
|
varying vec4 v_vColour;
|
|
|
|
|
2024-10-05 10:30:21 +02:00
|
|
|
uniform int size;
|
|
|
|
uniform vec2 dimension;
|
|
|
|
uniform float kernel[256];
|
|
|
|
uniform int sampleMode;
|
|
|
|
uniform int normalized;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
vec4 sampleTexture(vec2 pos) {
|
|
|
|
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
|
|
|
|
return texture2D(gm_BaseTexture, pos);
|
2024-02-15 14:23:26 +01:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
if(sampleMode == 0) return vec4(0.);
|
|
|
|
else if(sampleMode == 1) return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
|
|
|
|
else if(sampleMode == 2) return texture2D(gm_BaseTexture, fract(pos));
|
|
|
|
else if(sampleMode == 3) return vec4(vec3(0.), 1.);
|
2024-02-15 14:23:26 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
return vec4(0.);
|
|
|
|
}
|
2023-01-04 02:30:04 +01:00
|
|
|
|
|
|
|
void main() {
|
2024-10-09 04:09:24 +02:00
|
|
|
vec2 tx = 1. / dimension;
|
2024-10-05 10:30:21 +02:00
|
|
|
float sum = 1.;
|
2023-01-04 02:30:04 +01:00
|
|
|
|
2024-10-05 10:30:21 +02:00
|
|
|
if(normalized == 1) {
|
|
|
|
sum = 0.;
|
|
|
|
int amo = size * size;
|
|
|
|
for(int i = 0; i < amo; i++) sum += kernel[i];
|
2024-10-09 03:56:39 +02:00
|
|
|
|
|
|
|
if(sum == 0.) sum = 1.;
|
2024-10-05 10:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float st = -(float(size) - 1.) / 2.;
|
|
|
|
vec4 c = vec4(0.);
|
|
|
|
|
|
|
|
for(int i = 0; i < size; i++)
|
|
|
|
for(int j = 0; j < size; j++) {
|
|
|
|
int index = i * size + j;
|
2024-10-09 04:09:24 +02:00
|
|
|
vec2 px = v_vTexcoord + vec2((float(j) + st) * tx.x, (float(i) + st) * tx.y);
|
|
|
|
|
|
|
|
float w = kernel[index];
|
|
|
|
if(w == 0.) continue;
|
2024-10-05 10:30:21 +02:00
|
|
|
|
2024-10-09 04:09:24 +02:00
|
|
|
c += w * sampleTexture(px) / sum;
|
2024-10-05 10:30:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gl_FragColor = c;
|
2023-01-04 02:30:04 +01:00
|
|
|
}
|