Is it possible to apply a shader while preserving the self color?
so far this is what I've come up with
shader_type canvas_item;
void fragment(){
vec4 self_color = texture(TEXTURE, UV);
vec4 back_color = texture(SCREEN_TEXTURE, SCREEN_UV);
if(self_color.a==0.0)
COLOR=back_color;
else // invert color
COLOR = mix(self_color,vec4(1.0 - back_color.rgb, back_color.a),0.5);
}
but as you can see (on left) it's faded and merges with the editor's gray background
as compared to the original image (on right)
This is what I'm trying to achieve:
The only thing that comes to mind is to tell the shader what the clear color is and use that for reference. Something like the following (I'm not sure if this is the desired effect, but hopefully you can tweak to what you want):
Here I'm mixing colors based on how far are the background is from the clear color
distance(back_color, clear_color)
※. When they match, you should getself_color
, and as they differ the mix would approachmix(self_color, back_color, 0.5)
(tweak that to your needs).※: You can try other metrics, for example
dot(back_color - clear_color, back_color - clear_color)
ordot(abs(back_color - clear_color), vec4(1.0))
.