- 
      
- 
        Save JustusPan/325c7cc2b91e09dab1f470b3c4fb1eb2 to your computer and use it in GitHub Desktop. 
Revisions
- 
        harrisyu created this gist Aug 15, 2020 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ shader_type canvas_item; uniform bool use_pallete; uniform sampler2D pallete_texture; uniform vec4 tint_color : hint_color = vec4(1.0); uniform float tint_factor : hint_range(0, 1); const float from_u = 0.25; const float to_u = 0.75; const float pal_size = 16f; const float threshold = 0.001; void fragment() { vec4 source_color = texture(TEXTURE , UV.xy); vec3 final_color = source_color.rgb; if (use_pallete){ for (float i = 0f; i < pal_size; i++) { vec4 from_color = texture(pallete_texture , vec2(from_u, i/pal_size)); vec4 to_color = texture(pallete_texture , vec2(to_u, i/pal_size)); if(abs(length(source_color.rgb - from_color.rgb)) < threshold) final_color = to_color.rgb; } } COLOR.rgb = mix(final_color, tint_color.rgb, tint_factor); COLOR.a = source_color.a; }