Problem with the modification of differents colors in the same texture.

Hi.
I’m trying to make a shader where i can set differents colors at differents parts of my character ( 1 texture) with the use of multiple alpha channel ( one alpha for the torso, one for the legs, ect…) , but here i’m stuck with a little (big) problem. All the Alpha have the same color.

here my code:

Shader "Custom/characterCustom" {
    Properties {

    _Color ("Main Color", Color) = (1,1,1,1)
    _Color2 ("Main Color2", Color) = (1,1,1,1)
    _Color3 ("Main Color3", Color) = (1,1,1,1)
    _MainTex ("Base", 2D) = "white" {}
    _MyTexture ("B", 2D) = "white" {}
    _MyTexture2 ("C", 2D) = "white" {}
}
SubShader {

 
    Pass {
    SetTexture[_MainTex]
 
    SetTexture[_MyTexture] {
    Combine texture Lerp(constant) previous
}
    SetTexture[_MyTexture2] {
    Combine texture Lerp(constant) previous
}

}

CGPROGRAM
#pragma surface surf Lambert alpha


sampler2D _MainTex;
fixed4 _Color;

sampler2D _MyTexture;
fixed4 _Color2;

sampler2D _MyTexture2;
fixed4 _Color3;

    struct Input {
        float2 uv_MainTex;
     
        float2 uv_MyTexture;
        float2 uv_MyTexture2;

    };

    void surf (Input IN, inout SurfaceOutput o) {

    fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    fixed4 d = tex2D(_MyTexture, IN.uv_MyTexture) * _Color2;
    fixed4 e = tex2D(_MyTexture2, IN.uv_MyTexture2) * _Color3;
 
 
    o.Albedo =  c.rgb;
    //o.Albedo =  c.rgb + d.rgb;
    o.Alpha = d.a + e.a;
 
 



}

ENDCG
}

    Fallback "Diffuse"

}

i’m sure i am wrong here o.Albedo = c.rgb; but i’m not very familiar with the shaders and i don’t know how i can add the different color in separate manner?

Any help is apreciated :slight_smile:

Hi.
It’s me again :slight_smile:
After hours of research, i found a solution to my problem thank to this tutorial http://staraban.com/en/2d-game-tutorial-part-1-simple-characters-with-cusomization-using-tint-shader/
This tutorial explain how to create a shader for customize the differents colors of a sprite. And with few modifications i can use it now as base for my 3D characters :p.
And which is great, i dont need any alpha map.

edit: the problem here is we are limited to 3 colors ( the shader work with the RGB colors). I still think if we want more colors we need to use differents alpha maps but i don’t see/know how to do it.

Hi
I found a simple solution for the color limitation :slight_smile: i use 2 alpha map ( one for exemple contain the shirt(blue), the head (red) and the shoes (green) and the other the hands(blue) the belt( red) and the eyes (green)).

and i merge the result of the 2 ( i’m not sure if i’m very understandable ^^")

here my code while this may be useful for somebody ( sorry if it’s a bit messy;)):

Shader "Custom/characterCustom" {

    Properties {
    _MainTex1 ("text1", 2D) = "white" {}
    _TintColor1 ("Tint Color 1", Color) = (0.5,0.5,0.5,0.5)
    _TintColor2 ("Tint Color 2", Color) = (0.5,0.5,0.5,0.5)
    _TintColor3 ("Tint Color 3", Color) = (0.5,0.5,0.5,0.5)  
  
  
    _MainTex2 ("text2", 2D) = "white" {}
    _TintColor4 ("Tint Color 4", Color) = (0.5,0.5,0.5,0.5)
    _TintColor5 ("Tint Color 5", Color) = (0.5,0.5,0.5,0.5)
    _TintColor6 ("Tint Color 6", Color) = (0.5,0.5,0.5,0.5)
  
}

Category {
    Tags { "RenderType"="Opaque" }
        LOD 200
    Blend SrcAlpha OneMinusSrcAlpha
    AlphaTest Greater .01
    ColorMask RGB
    Cull Off Lighting Off// ZWrite Off
    BindChannels {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }

    // ---- Fragment program cards
    SubShader {
        Pass {

            CGPROGRAM

            #pragma exclude_renderers gles
            #pragma vertex vert
            #pragma fragment frag
            #pragma fragmentoption ARB_precision_hint_fastest
          

            #include "UnityCG.cginc"

            sampler2D _MainTex1;
            fixed4 _TintColor1;
            fixed4 _TintColor2;
            fixed4 _TintColor3;
          
            sampler2D _MainTex2;
            fixed4 _TintColor4;
            fixed4 _TintColor5;
            fixed4 _TintColor6;

            struct appdata_t {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
            };

            float4 _MainTex1_ST;

            v2f vert (appdata_t v)
            {
                v2f o;
                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex1);
                return o;
            }

            sampler2D _CameraDepthTexture;
            float _InvFade;

            fixed4 frag (v2f i) : COLOR
            {  
                float4 baseColor1 = tex2D(_MainTex1, i.texcoord);
                float alpha = baseColor1.a;
                baseColor1 = alpha * (baseColor1.r * _TintColor1 + baseColor1.g * _TintColor2 + baseColor1.b * _TintColor3);
                baseColor1.a = 1.0f - step(alpha, 0.1);
              
                float4 baseColor2 = tex2D(_MainTex2, i.texcoord);
                float alpha2 = baseColor2.a;
                baseColor2 = alpha2 * (baseColor2.r * _TintColor4 + baseColor2.g * _TintColor5 + baseColor2.b * _TintColor6);
                baseColor2.a = 1.0f - step(alpha2, 0.1);
                return baseColor1 + baseColor2;
            }
            ENDCG
        }
    }
}
}