You'll want to use some uniforms for this.
In your shader, do this:
shader_type canvas_item;
uniform vec4 main_color;
uniform vec4 secondary_color;
uniform vec4 accessory_color;
void fragment() {
...
}
Then, in your script you can set them like so:
// Where my_shader_material is your ShaderMaterial
// and main_color, secondary_color, accessory_color
// are set to their corresponding values
my_shader_material.set_shader_parameter("main_color", main_color)
my_shader_material.set_shader_parameter("secondary_color", secondary_color)
my_shader_material.set_shader_parameter("accessory_color", accessory_color)
You can see more about both here:
https://docs.godotengine.org/en/stable/tutorials/shaders/your_first_shader/your_first_3d_shader.html#uniforms
https://docs.godotengine.org/en/stable/classes/class_shadermaterial.html
Godot Engine documentation
Inherits: Material< Resource< RefCounted< Object A material defined by a custom Shader program and the values of its shader parameters. Description: A material that uses a custom Shader program to ...
Godot Engine documentation
You have decided to start writing your own custom Spatial shader. Maybe you saw a cool trick online that was done with shaders, or you have found that the StandardMaterial3D isn't quite meeting you...