Two tones effect

This shader replaces the colors of the image with two selected ones depending on the brightness of the pixel

Shader code
shader_type canvas_item;

uniform float difference_point =1.0;//pixel brightness coefficient
uniform vec4 first_color  : hint_color = vec4(1,1,1,1) ; 
uniform vec4 second_color  : hint_color = vec4(0,0,0,1); 
void fragment() {

    vec4 color = texture(TEXTURE, UV);
    if (dot(color, vec4(0.5, 0.5, 0.5, 0)) < difference_point) {
        COLOR = vec4(second_color.rgb,second_color.a*color.a);
    } else {
        COLOR =vec4(first_color.rgb,first_color.a*color.a);
2d, Color, godot3
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Combine two Shaders

Palette Swap using two textures

Two growing hexagons grids

Notify of

Inline Feedbacks
View all comments