shader_type canvas_item;
render_mode unshaded;

uniform float line_thickness : hint_range(0.0, 100.0);
uniform vec4 line_color : source_color = vec4(1.0);
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;



void fragment() {
	vec2 size = SCREEN_PIXEL_SIZE * float(line_thickness*4.0);
	float line_alpha = 0.0;
	for (float i = -size.x; i <= size.x; i += SCREEN_PIXEL_SIZE.x) {
		for (float j = -size.y; j <= size.y; j += SCREEN_PIXEL_SIZE.y) {
			line_alpha += texture(screen_texture, SCREEN_UV + vec2(i, j)).a;
		}
	}
	float div = size.x*2.0/SCREEN_PIXEL_SIZE.x + size.y*2.0/SCREEN_PIXEL_SIZE.y;
	line_alpha = .1 * (line_alpha / div);
	vec4 colour = texture(screen_texture, SCREEN_UV);
	vec4 outline = vec4(line_color.rgb, min(line_alpha, 1.0));
	COLOR *= mix(outline, colour, colour.a);
}