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;
}
Tags
postpo
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from spamrakuen

ORM material blending using vertex colors and noise with hard/soft transitions

Dilate screen effect

Related shaders

Doom Screen Melt Effect

Screen Noise Effect Shader

Pixelate Screen Effect

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
zadzaza
zadzaza
4 months ago

Thanks for contributing to the Godot community!

tentabrobpy
3 months ago

Personally, I prefer Yellowdot