Erode screen effect
Erode 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 min light value
float min_light = 100.0;
vec4 min_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);
// min value?
if (gray < min_light) {
min_light = gray;
min_color = color;
}
}
}
// set min light color as current one
COLOR = min_color;
}
Thanks for contributing to the Godot community!
Sure. Its always a pleasure to contribute to the Godot and Redot communities! 😀
Personally, I prefer Yellowdot