[update] Implemented blur effect.

This commit is contained in:
falsycat 2019-10-16 00:00:00 +00:00
parent 3a9669df38
commit 9f8379fa96

View File

@ -23,6 +23,9 @@ class PostEffect {
/// ///
align(16) vec4 contrast = vec4(1, 1, 1, 1); align(16) vec4 contrast = vec4(1, 1, 1, 1);
///
align(16) vec4 blur = vec4(0.3, 0.3, 0.3, 0);
} }
/// ///
@ -130,6 +133,8 @@ class PostEffectProgram {
vec2 clip_rightbottom; vec2 clip_rightbottom;
vec4 contrast; vec4 contrast;
vec4 blur;
} instance; } instance;
in vec2 uv_; in vec2 uv_;
@ -152,6 +157,35 @@ class PostEffectProgram {
pixel_.b = pow(pixel_.b, instance.contrast.b); pixel_.b = pow(pixel_.b, instance.contrast.b);
pixel_.a = pow(pixel_.a, instance.contrast.a); pixel_.a = pow(pixel_.a, instance.contrast.a);
// blur
vec4 blur_div = instance.blur / 32;
pixel_ = pixel_ * (1-instance.blur) +
texture(fb, fb_size * tex_uv + vec2(-2, 2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-2, 1)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-2, 0)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-2, -1)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-2, -2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-1, -2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 0, -2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 1, -2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 2, -2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 2, -1)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 2, 0)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 2, 1)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 2, 2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 1, 2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2( 0, 2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-1, 2)) * blur_div +
texture(fb, fb_size * tex_uv + vec2(-1, 1)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2(-1, 0)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2(-1, -1)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2( 0, -1)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2( 1, -1)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2( 1, 0)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2( 1, 1)) * blur_div*2 +
texture(fb, fb_size * tex_uv + vec2( 0, 1)) * blur_div*2;
// clipping // clipping
pixel_.a *= pixel_.a *=
step(-1+instance.clip_lefttop.x, uv_.x) * step(-1+instance.clip_lefttop.x, uv_.x) *