Pixel-Composer/shaders/sh_blur_directional/sh_blur_directional.fsh

87 lines
2.2 KiB
Plaintext
Raw Normal View History

2024-10-24 12:40:14 +02:00
#pragma use(sampler_simple)
#region -- sampler_simple -- [1729740692.1417658]
uniform int sampleMode;
vec4 sampleTexture( sampler2D texture, vec2 pos) {
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
return texture2D(texture, pos);
if(sampleMode <= 1) return vec4(0.);
else if(sampleMode == 2) return texture2D(texture, clamp(pos, 0., 1.));
else if(sampleMode == 3) return texture2D(texture, fract(pos));
else if(sampleMode == 4) return vec4(vec3(0.), 1.);
return vec4(0.);
}
#endregion -- sampler_simple --
2022-01-13 05:24:03 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2023-03-23 13:38:50 +01:00
uniform float size;
2024-03-15 13:38:08 +01:00
uniform int scale;
2023-12-23 09:39:55 +01:00
uniform vec2 direction;
uniform int directionUseSurf;
uniform sampler2D directionSurf;
2024-03-15 13:38:08 +01:00
uniform vec2 strength;
uniform int strengthUseSurf;
uniform sampler2D strengthSurf;
uniform int gamma;
2023-08-12 12:35:35 +02:00
2023-12-23 09:39:55 +01:00
vec4 dirBlur(vec2 angle) { #region
2024-03-15 13:38:08 +01:00
vec4 acc = vec4(0.);
float delta = 1. / size;
2023-08-12 12:35:35 +02:00
float weight = 0.;
2022-01-13 05:24:03 +01:00
2024-03-15 13:38:08 +01:00
if(scale == 0) {
for(float i = -1.0; i <= 1.0; i += delta) {
2024-10-24 12:40:14 +02:00
vec4 col = sampleTexture( gm_BaseTexture, v_vTexcoord - angle * i);
if(gamma == 1) col.rgb = pow(col.rgb, vec3(2.2));
2024-03-15 13:38:08 +01:00
acc += col;
weight += col.a;
}
acc.rgb /= weight;
acc.a /= size * 2.;
} else {
for(float i = 0.; i <= 1.0; i += delta) {
2024-10-24 12:40:14 +02:00
vec4 col = sampleTexture( gm_BaseTexture, v_vTexcoord - angle * i);
if(gamma == 1) col.rgb = pow(col.rgb, vec3(2.2));
2024-03-15 13:38:08 +01:00
acc += col ;
weight += col.a;
}
acc.rgb /= weight;
acc.a /= size - 1.;
2024-10-24 12:40:14 +02:00
acc += sampleTexture( gm_BaseTexture, v_vTexcoord );
2024-03-15 13:38:08 +01:00
}
2023-08-12 12:35:35 +02:00
if(gamma == 1) acc.rgb = pow(acc.rgb, vec3(1. / 2.2));
2023-08-12 12:35:35 +02:00
return acc;
2023-12-23 09:39:55 +01:00
} #endregion
2022-01-13 05:24:03 +01:00
void main() {
2023-12-23 09:39:55 +01:00
float str = strength.x;
if(strengthUseSurf == 1) {
vec4 _vMap = texture2D( strengthSurf, v_vTexcoord );
str = mix(strength.x, strength.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
float dir = direction.x;
if(directionUseSurf == 1) {
vec4 _vMap = texture2D( directionSurf, v_vTexcoord );
dir = mix(direction.x, direction.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
float r = radians(dir + 90.);
vec2 dirr = vec2(sin(r), cos(r)) * str;
2022-01-13 05:24:03 +01:00
2023-12-23 09:39:55 +01:00
gl_FragColor = dirBlur(dirr);
2022-01-13 05:24:03 +01:00
}