shader_type canvas_item;

uniform sampler2D gradient;
instance uniform float threshold = -0.1;
uniform float fringe = 0;
void vertex() {
	// Called for every vertex the material is visible on.
}

void fragment() {
	vec4 col = texture(TEXTURE, UV);
	float lum = 0.2126*col.r + 0.7152*col.g + 0.0722*col.b;
	vec4 g_col = texture(gradient, vec2((threshold + fringe) - lum, 0));
	if(lum > threshold){
		float fringe_alpha = max(0, (fringe - (lum - threshold))/fringe);
		COLOR = vec4(g_col.rgb,fringe_alpha * col.a);
		
	}else{
		COLOR = vec4(g_col.rgb, col.a);
	}
	// Called for every pixel the material is visible on.
}

//void light() {
//	// Called for every pixel for every light affecting the CanvasItem.
//	// Uncomment to replace the default light processing function with this one.
//}
