Pixel-Composer/shaders/sh_blur_directional/sh_blur_directional.fsh

47 lines
999 B
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2023-03-23 13:38:50 +01:00
uniform float size;
2022-01-13 05:24:03 +01:00
uniform float strength;
uniform float direction;
2023-08-12 12:35:35 +02:00
uniform int sampleMode;
vec4 sampleTexture(vec2 pos) {
if(pos.x >= 0. && pos.y >= 0. && pos.x <= 1. && pos.y <= 1.)
return texture2D(gm_BaseTexture, pos);
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.);
}
2022-01-13 05:24:03 +01:00
vec4 dirBlur(vec2 angle) {
2023-08-12 12:35:35 +02:00
vec4 acc = vec4(0.);
2023-03-23 13:38:50 +01:00
float delta = 1. / size;
2023-08-12 12:35:35 +02:00
float weight = 0.;
2022-01-13 05:24:03 +01:00
for(float i = -1.0; i <= 1.0; i += delta) {
2023-08-12 12:35:35 +02:00
vec4 col = sampleTexture( v_vTexcoord - angle * i);
acc += col;
weight += col.a;
2022-01-13 05:24:03 +01:00
}
2023-08-12 12:35:35 +02:00
acc.rgb /= weight;
acc.a /= size * 2.;
return acc;
2022-01-13 05:24:03 +01:00
}
void main() {
float r = radians(direction);
vec2 dirr = vec2(sin(r), cos(r));
gl_FragColor = dirBlur(strength * dirr);
}