60 lines
No EOL
1.4 KiB
Text
60 lines
No EOL
1.4 KiB
Text
shader_type canvas_item;
|
|
|
|
#define pow2(x) (x * x)
|
|
#define iResolution vec2(0.001,0.001)
|
|
|
|
uniform sampler2D iChannel0;
|
|
uniform vec2 rotationpivot=vec2(0.5,0.5);
|
|
uniform float speed=0.1;
|
|
uniform float strength : hint_range(0.0, 20.0, 0.1) = 1.0;
|
|
const float pi = atan(1.0) * 4.0;
|
|
const int samples = 35;
|
|
const float sigma = float(samples) * 0.25;
|
|
|
|
float gaussian(vec2 i) {
|
|
return 1.0 / (2.0 * pi * pow2(sigma)) * exp(-((pow2(i.x) + pow2(i.y)) / (2.0 * pow2(sigma))));
|
|
}
|
|
|
|
vec3 blur(sampler2D sp, vec2 uv, vec2 scale) {
|
|
vec3 col = vec3(0.0);
|
|
float accum = 0.0;
|
|
float weight;
|
|
vec2 offset;
|
|
|
|
for (int x = -samples / 2; x < samples / 2; ++x) {
|
|
for (int y = -samples / 2; y < samples / 2; ++y) {
|
|
offset = vec2(float(x), float(y));
|
|
weight = gaussian(offset);
|
|
col += texture(sp, uv + scale * offset).rgb * weight;
|
|
accum += weight;
|
|
}
|
|
}
|
|
|
|
return col / accum;
|
|
}
|
|
|
|
vec2 rotateUV(vec2 uv, vec2 pivot, float rotation) {
|
|
float cosa = cos(rotation);
|
|
float sina = sin(rotation);
|
|
uv -= pivot;
|
|
return vec2(
|
|
cosa * uv.x - sina * uv.y,
|
|
cosa * uv.y + sina * uv.x
|
|
) + pivot;
|
|
}
|
|
|
|
|
|
void fragment() {
|
|
|
|
vec2 uv = UV ;
|
|
vec2 rotuv=rotateUV(uv,rotationpivot,TIME*speed);
|
|
|
|
float _strength=abs(0.47-uv.y)*strength;
|
|
vec2 ps = vec2(1.0) / iResolution.xy * .000001 * _strength;
|
|
|
|
|
|
//COLOR.rgb=texture(iChannel0, uv).rgb;
|
|
|
|
COLOR.rgb = blur(iChannel0, rotuv, ps );
|
|
COLOR.a = 1.0;
|
|
} |