Pixel-Composer/shaders/sh_blur_gaussian/sh_blur_gaussian.fsh

68 lines
1.4 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform int horizontal;
uniform float weight[32];
uniform int size;
2023-01-17 08:11:55 +01:00
uniform int sampleMode;
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
uniform int overrideColor;
uniform vec4 overColor;
2022-01-13 05:24:03 +01:00
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.);
if(sampleMode == 1)
return texture2D(gm_BaseTexture, clamp(pos, 0., 1.));
if(sampleMode == 2)
return texture2D(gm_BaseTexture, fract(pos));
return vec4(0.);
}
vec4 sample(in vec2 pos, in int index) {
vec4 col = sampleTexture( pos );
return vec4(col.rgb, col.a) * weight[index];
2022-01-13 05:24:03 +01:00
}
void main() {
2023-01-17 08:11:55 +01:00
vec2 tex_offset = 1.0 / dimension, pos;
2022-01-13 05:24:03 +01:00
vec4 result = sample( v_vTexcoord, 0 );
vec4 samp;
if(horizontal == 1) {
2022-12-27 04:00:50 +01:00
for(int i = 1; i < size; i++) {
2023-01-17 08:11:55 +01:00
pos = vec2(tex_offset.x * float(i), 0.0);
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
samp = sample( v_vTexcoord + pos, i );
result += samp;
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
samp = sample( v_vTexcoord - pos, i );
result += samp;
2022-01-13 05:24:03 +01:00
}
} else {
2022-12-27 04:00:50 +01:00
for(int i = 1; i < size; i++) {
2023-01-17 08:11:55 +01:00
pos = vec2(0.0, tex_offset.y * float(i));
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
samp = sample( v_vTexcoord + pos, i );
result += samp;
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
samp = sample( v_vTexcoord - pos, i );
result += samp;
2022-01-13 05:24:03 +01:00
}
}
2023-01-17 08:11:55 +01:00
gl_FragColor = result;
if(overrideColor == 1)
gl_FragColor.rgb = overColor.rgb;
2022-01-13 05:24:03 +01:00
}