Pixel-Composer/shaders/sh_blur_zoom/sh_blur_zoom.fsh

90 lines
2.5 KiB
Text
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 --
2023-01-25 06:49:00 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2023-12-10 14:55:05 +01:00
uniform vec2 center;
uniform int blurMode;
uniform int gamma;
2023-01-25 06:49:00 +01:00
2023-12-23 09:39:55 +01:00
uniform vec2 strength;
uniform int strengthUseSurf;
uniform sampler2D strengthSurf;
2023-01-25 06:49:00 +01:00
uniform int useMask;
uniform sampler2D mask;
2023-12-10 14:55:05 +01:00
#region ==== PARAM DRIVER ====
#define PARAM_COUNT 1
uniform int parameter_active[PARAM_COUNT];
uniform sampler2D parameters;
float sampleParameter(in int index, in float def) {
if(parameter_active[index] == 0) return def;
float row = floor(float(index) / 4.);
vec2 coord = (v_vTexcoord + vec2(float(index) - row * 4., row)) * 0.25;
vec4 col = texture2D( parameters, coord );
float _val = col.r;
float _min = col.g * 256. - 128.;
float _max = col.b * 256. - 128.;
return mix(_min, _max, _val);
}
#endregion
float sampleMask() { #region
2023-01-25 06:49:00 +01:00
if(useMask == 0) return 1.;
vec4 m = texture2D( mask, v_vTexcoord );
return (m.r + m.g + m.b) / 3. * m.a;
2023-12-10 14:55:05 +01:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-12-10 14:55:05 +01:00
void main() { #region
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.);
}
2023-01-25 06:49:00 +01:00
vec2 uv = v_vTexcoord - center;
2023-12-23 09:39:55 +01:00
float _str = sampleParameter(0, str) * sampleMask();
float nsamples = 64.;
float scale_factor = _str * (1. / (nsamples * 2. - 1.));
vec4 color = vec4(0.0);
float blrStart = 0.;
2023-01-25 06:49:00 +01:00
2023-12-10 14:55:05 +01:00
if(blurMode == 0) blrStart = 0.;
else if(blurMode == 1) blrStart = -nsamples;
else if(blurMode == 2) blrStart = -nsamples * 2. - 1.;
2023-01-25 06:49:00 +01:00
for(float i = 0.; i < nsamples * 2. + 1.; i++) {
float scale = 1.0 + ((blrStart + i) * scale_factor);
2023-12-23 09:39:55 +01:00
vec2 pos = uv * scale + center;
2024-10-24 12:40:14 +02:00
vec4 col = sampleTexture( gm_BaseTexture, pos );
if(gamma == 1) col.rgb = pow(col.rgb, vec3(2.2));
color += col;
2023-01-25 06:49:00 +01:00
}
color /= nsamples * 2. + 1.;
if(gamma == 1) color.rgb = pow(color.rgb, vec3(1. / 2.2));
2023-01-25 06:49:00 +01:00
gl_FragColor = color;
2023-12-10 14:55:05 +01:00
} #endregion