How to render a shader to MainTex? (can Shader Graph be used?)

What I want to do is have parameters that can be independently set in code for a single material such as clothing color and skin color parameters. I did that using shader graph:

gameObject.GetComponent<Renderer>().material.SetColor("_ClothingColor", randomClothingColor);
gameObject.GetComponent<Renderer>().material.SetColor("_SkinColor", randomSkinColor);

But what I ultimately want to do is render it to their MainTex. Does that require using RenderTexture or CustomRenderTexture?

Though I found this:

The reason I want to render it to their MainTex is because I’m using Paint in 3D and I want to use P3D to modify the MainTex rather than having an independent painted layer/texture.

This might be relevant:

I was after some help about using code to render it to the model’s MainTex (if CRTs are the method to use)
Thanks!

I am not familiar with custom render texture, and I am not 100% sure I understand your use case, but reading your question gave me this idea, maybe it could inspire you in some ways :

You have a texture which has the clothing and the skin on it as I understand.
You want to apply the color to a render texture so you can combine the clothing color with the skin color to have a lot of permutations without having a separate texture in your project for every permutation possible.
You need to have the result stored in a texture so you can paint over it.

Why not create the textures dynamically with some masks (black/white)?

1 mask for skin : White for skin area, black for the reset
1 mask for clothes : White for clothes area, black for reset
Multiply the mask by their respective color to get your main texture.

Hope this was helpful in some ways !

Thanks for your input. That’s what I was going to do - have masks for the skin and clothing areas. But it would be a Material or Shader type and I need it to be in a Texture type. It seems RenderTexture and CustomRenderTexture are subclasses of Texture. So I think I need to somehow convert a Material/Shader to one of those Texture subclasses. Hopefully I can do that with Shader Graph because it is easier to make those masks using it.
I was looking here:

It says _MainTex can be updated with another Texture or RenderTexture…

“Custom Render Textures are an extension to Render Textures that allow you to render directly to the Texture using a Shader”
“material The Material that Unity uses to initialize the content of a Custom Render Texture.”

I figured it out…

public class CustomTest : MonoBehaviour
{
    public Material mat;
    void Start()
    {
        Color randomColor1 = Color.blue;
        Color randomColor2 = Color.yellow;
        mat.SetColor("_Color1", randomColor1);
        mat.SetColor("_Color2", randomColor2);

        // low res
        CustomRenderTexture crt = new CustomRenderTexture(16, 16);
        // make it pixelated
        crt.filterMode = FilterMode.Point;

        crt.initializationMaterial = mat;
        crt.initializationSource = CustomRenderTextureInitializationSource.Material;
        crt.initializationMode = CustomRenderTextureUpdateMode.OnLoad;

        gameObject.GetComponent<Renderer>().material.SetTexture("_MainTex", crt);
    }
}

I was looking in the Inspector in the CustomRenderTexture - it was initially black until I tweaked some settings…

Fortunately Shader Graph worked with it… initially I just made one color fade to the other as a test.