float blur_percent = color_distance-threshold ;
shader_type canvas_item;
uniform sampler2D screen_texture : hint_screen_texture;
uniform vec2 for_size = vec2(1.0,1.0);
uniform vec2 standard_pixel;
uniform float threshold = 0.5;
uniform float intensity = 2.0;
uniform bool is_block_minus_multiple=true;
uniform vec3 color_mask = vec3(1.0,1.0,1.0);
varying vec2 varying_uv_standard_pixel;
void vertex(){
varying_uv_standard_pixel = vec2((CANVAS_MATRIX * MODEL_MATRIX * vec4(standard_pixel,0.0,0.0)).xy);
varying_uv_standard_pixel = vec2((SCREEN_MATRIX * vec4(varying_uv_standard_pixel,0.0,1.0)).xy);
}
void fragment() {
vec2 standard_pixel_1 = (varying_uv_standard_pixel + 1.0)/2.0;
vec4 color = vec4(0.0);
float total = 0.0;
for (int x = -int(for_size.x); x <= int(for_size.x);x++) {
for (int y = -int(for_size.y); y <= int(for_size.y); y++) {
vec2 uv = SCREEN_UV;
uv+= standard_pixel_1 * vec2(float(x),float(y));
color += texture(screen_texture,uv);
total+=1.0;
}
}
color /= total;
vec4 original_color = texture(screen_texture,SCREEN_UV);
vec4 combine_color=vec4(0.0,0.0,0.0,0.0);
float color_distance = length(vec3(color.xyz));
float blur_percent = color_distance-threshold ;
// 0에 가까울수록 임계 도달, +넘어갈 수록 임계초과, -일수록 임계 아직 도달 안한 거리
blur_percent = min(1.0,blur_percent +1.0);
if(is_block_minus_multiple)
blur_percent = max(0.0, blur_percent);
//blur 계산 결과가 마이너스가 되는 것을 방지 (색상 거리)
// 0 ~ 1 임계 아직 도달 안 함 , 1 임계 도달 , 1 넘어가면 초과
combine_color = color * blur_percent * intensity * vec4(color_mask,1.0);
COLOR = original_color + combine_color;
}
위 코드 역시 MIT 라이선스로 배포한다. 자유로이 사용해도 되나, 라이선스 전문 및 본 사이트를 출처로 남기고 사용하면 된다.