shader_type canvas_item; // Parameters uniform float alpha_threshold : hint_range(0.0, 1.0) = 0.1; // below this = fully transparent uniform float alpha_modifier : hint_range(0.0, 1.0) = 1.0; // global alpha multiplier void fragment() { // Sample the current frame automatically vec4 tex_color = texture(TEXTURE, UV); // Convert color to luminance (grayscale) float lum = dot(tex_color.rgb, vec3(0.299, 0.587, 0.114)); // Apply threshold: if below threshold, alpha = 0 float alpha = lum < alpha_threshold ? 0.0 : lum; // Apply global modifier alpha *= alpha_modifier; COLOR = vec4(tex_color.rgb, alpha); }