Controlled color inversion
Don’t you hate it when on 50% mix of the picture with its inverted self there is only gray? Well, I sure do!
With this shader not only you can smoothly transition into inverted color image, but also control the middle value look.
PARAMETERS
- factor: inverted color factor. 0 = original colors; 1 = fully inverted colors
- color_middle: saturation and intensity of the transition color. The higher the more colored the transition will be.
- hue_shift: change offset of colors in the in-between state.
Controls R (red) G (green) and B (blue) color shift ratio when factor is value between 0 and 1.
Shader code
shader_type canvas_item;
uniform float factor: hint_range(0.0, 1.0);
// intensity of the color on 0.5 value of factor
uniform float color_middle: hint_range(0.0, 1.0, 0.1) = 0.5;
uniform vec3 hue_shift = vec3(1.5,0.815,2.895);
void fragment() {
vec3 inverted_color = 1. - COLOR.rgb;
vec3 orig_color = COLOR.rgb;
// distance from factor to center value (0.5)
float dist = (distance(factor,0.5) - 0.5) * color_middle;
// shift hue by values in hue shift
vec3 factor_v = vec3(factor + dist / hue_shift.r, factor + dist /
hue_shift.g, factor + dist / hue_shift.b);
COLOR.rgb = mix(orig_color, inverted_color, factor_v);
}
