I spent all day searching for a basic sprite 'Colorizer' similar to how art programs can 'Colorize' a sprite for you easily, but I want to do this in-game based on a color the player chooses. (Skin color, hair color, etc.)
The in-built 'modulate' function in Godot does not produce results anything like I had expected. So I wrote a shader that performs pretty much exactly as would be expected from any Art rendering software.
It is incredibly simple so it should be EXTREMELY fast.
Colorizer.shader
shader_type canvas_item;
uniform vec4 new_color: hint_color = vec4(0.878, 0.694, 0.518, 1.0);
uniform float offset = 0.5;
void fragment(){
COLOR = texture(TEXTURE, UV); //read from texture
COLOR.rgb += new_color.rgb - offset;
}
You can send the 'new color' to it through code in an attached script as well:
self.material.set_shader_param("new_color", "#E0B184")
The above color is a default skin tone but you can obviously change it to any color you'd like.
The offset can be changed to your desire as well, but 0.5 performs exactly like I intended. It was a 1:1 likeness with my favorite art software (GIMP).
I hope this might help someone else, let me know if you try it out.
Enjoy! :3