recolor.fp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #version 140
  2. uniform sampler2D texture_sampler;
  3. uniform f_uniform
  4. {
  5. vec4 tint;
  6. };
  7. in vec2 var_texcoord0;
  8. // custom vertex attributes
  9. in vec4 new_color;
  10. in vec4 new_outline;
  11. out vec4 final_color;
  12. void main()
  13. {
  14. lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
  15. lowp vec4 sprite = texture(texture_sampler, var_texcoord0.xy);
  16. // float values used for comparing
  17. lowp float combine = (sprite.r + sprite.g);
  18. lowp float greenmul = sprite.g * 2;
  19. // when 2 channels added together equal the same as a single channel multipled then we have desaturated values
  20. if(combine == greenmul){
  21. sprite = vec4(sprite.rgb*new_color.rgb,sprite.a);
  22. }
  23. // when the green channel has a value of 1.0 and the w value is 1.0(on) then we color the outline
  24. if(new_outline.w >= 1.0 && sprite.g >= 1.0){
  25. sprite = vec4(new_outline.rgb,1.0);
  26. }
  27. else if (sprite.g >= 1.0){ //when the w value is not 1.0 we remove all values. turning the outline off
  28. sprite = vec4(0.0, 0.0, 0.0, 0.0);
  29. }
  30. final_color = vec4(sprite * tint);
  31. }