shader_type canvas_item; uniform float greyscale_ratio : hint_range(0.0, 1.0) = 1.0; void fragment() { vec4 c = texture(TEXTURE,UV); vec4 modulate = COLOR / c; //Get Modulate COLOR = c; float avg = (COLOR.r + COLOR.g + COLOR.b)/ 3.0; COLOR.rgb = mix(COLOR.rgb, vec3(avg), greyscale_ratio); COLOR *= modulate; //Reintroduce Modulate }
or share this direct link: