Dilate screen effect
Dilate screen effect.
How to use:
– Create a CanvasLayer and put a ColorRect inside
– Create a ShaderMaterial and use this shader
– Assign that material to the ColorRect
Attached screenshots show the effect on/off
Shader code
shader_type canvas_item;
#define USE_CIRCLE_SHAPE 1
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, repeat_disable, filter_nearest;
uniform float radius : hint_range(1, 10, 1) = 5;
void fragment() {
// sample radius*radius values and find max light value
float max_light = 0.0;
vec4 max_color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 center = vec2(0, 0);
for (float i = -radius; i <= radius; i++) {
for (float j = -radius; j <= radius; j++) {
vec2 sample_uv = vec2(i, j);
#if USE_CIRCLE_SHAPE
// be sure its a circle
if (distance(sample_uv, center) > radius) {
continue;
}
#endif
// sample
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV + sample_uv * SCREEN_PIXEL_SIZE);
// convert to grayscale
float gray = (color.r * 0.299) + (color.g * 0.587) + (color.b * 0.114);
// max value?
if (gray > max_light) {
max_light = gray;
max_color = color;
}
}
}
// set max light color as current one
COLOR = max_color;
}