48 lines
1.2 KiB
Plaintext
48 lines
1.2 KiB
Plaintext
shader_type canvas_item;
|
|
|
|
#define pow2(x) (x * x)
|
|
#define iResolution 1.0/SCREEN_PIXEL_SIZE
|
|
|
|
uniform sampler2D gradient : source_color, filter_nearest;
|
|
uniform int dimension;
|
|
|
|
const float alpha = 0.7;
|
|
const float strength = 0.5;
|
|
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 * pow(sigma,2)) * exp(-((pow(i.x,2) + pow(i.y,2)) / (2.0 * pow(sigma,2))));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void fragment() {
|
|
vec2 ps = vec2(1.0) / iResolution.xy * .000001 * strength;
|
|
vec2 uv = UV ;
|
|
|
|
vec3 pixel_color = blur(TEXTURE, uv, ps );
|
|
float value = pixel_color.x;
|
|
if (dimension == 1) value = pixel_color.y;
|
|
if (dimension == 2) value = pixel_color.z;
|
|
|
|
COLOR = texture(gradient, vec2(value, 0));
|
|
COLOR.a = alpha;
|
|
} |