Pixel-Composer/shaders/sh_blur_gaussian/sh_blur_gaussian.fsh

81 lines
1.7 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2023-08-12 12:35:35 +02:00
uniform int horizontal;
2022-01-13 05:24:03 +01:00
2023-11-24 10:41:53 +01:00
uniform float weight[128];
2023-08-12 12:35:35 +02:00
uniform int size;
2024-06-22 12:09:44 +02:00
uniform float angle;
2023-08-12 12:35:35 +02:00
uniform int sampleMode;
2022-01-13 05:24:03 +01:00
2023-08-12 12:35:35 +02:00
uniform int overrideColor;
2023-01-17 08:11:55 +01:00
uniform vec4 overColor;
2022-01-13 05:24:03 +01:00
uniform int gamma;
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);
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
if(sampleMode == 0)
return vec4(0.);
2024-02-15 14:23:26 +01:00
else if(sampleMode == 1)
2023-01-17 08:11:55 +01:00
return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
2024-02-15 14:23:26 +01:00
else if(sampleMode == 2)
2023-01-17 08:11:55 +01:00
return texture2D(gm_BaseTexture, fract(pos));
2024-02-15 14:23:26 +01:00
else if(sampleMode == 3)
return vec4(vec3(0.), 1.);
2023-01-17 08:11:55 +01:00
return vec4(0.);
}
2023-08-12 12:35:35 +02:00
float wgh = 0.;
2023-01-17 08:11:55 +01:00
vec4 sample(in vec2 pos, in int index) {
vec4 col = sampleTexture( pos );
if(gamma == 1) col.rgb = pow(col.rgb, vec3(2.2));
2023-08-12 12:35:35 +02:00
col.rgb *= weight[index] * col.a;
wgh += weight[index] * col.a;
2023-08-12 12:35:35 +02:00
return col;
2022-01-13 05:24:03 +01:00
}
void main() {
2024-06-22 12:09:44 +02:00
vec2 tex_offset = 1.0 / dimension, pos;
vec4 result = sample( v_vTexcoord, 0 );
mat2 rot = mat2(cos(angle), -sin(angle), sin(angle), cos(angle));
2022-01-13 05:24:03 +01:00
if(horizontal == 1) {
2022-12-27 04:00:50 +01:00
for(int i = 1; i < size; i++) {
2024-06-22 12:09:44 +02:00
pos = rot * vec2(tex_offset.x * float(i), 0.0);
2022-01-13 05:24:03 +01:00
2023-08-12 12:35:35 +02:00
result += sample( v_vTexcoord + pos, i );
result += sample( v_vTexcoord - pos, i );
2022-01-13 05:24:03 +01:00
}
} else {
2022-12-27 04:00:50 +01:00
for(int i = 1; i < size; i++) {
2024-06-22 12:09:44 +02:00
pos = rot * vec2(0.0, tex_offset.y * float(i));
2022-01-13 05:24:03 +01:00
2023-08-12 12:35:35 +02:00
result += sample( v_vTexcoord + pos, i );
result += sample( v_vTexcoord - pos, i );
2022-01-13 05:24:03 +01:00
}
}
2023-08-12 12:35:35 +02:00
result.rgb /= wgh;
result.a = wgh;
if(gamma == 1) result.rgb = pow(result.rgb, vec3(1. / 2.2));
2023-01-17 08:11:55 +01:00
gl_FragColor = result;
2024-01-08 08:10:50 +01:00
if(overrideColor == 1) {
2023-01-17 08:11:55 +01:00
gl_FragColor.rgb = overColor.rgb;
2024-01-08 08:10:50 +01:00
gl_FragColor.a *= overColor.a;
}
2022-01-13 05:24:03 +01:00
}