Why my simple shader doesn't get vertex Color?

Hi there, sorry for the noob question but I’ve create a simple surface shader and put a texture and a normal map for it but can’t add vertex Color to it! I want to change the main color but just don’t know how.

Here is my code

Shader "My_Shaders/FirstShader" {

Properties {
   _Color ("Main Color", Color) = (1,1,1,0.5)
   _MainTex ("Texture", 2D) = "white" {}
   _BumpMap ("Bumpmap", 2D) = "bump" {}
}


Subshader {
Tags { "RenderType" = "Opaque" }
 
    CGPROGRAM
     #pragma surface surf Lambert

    struct Input {
 
     float4 color : COLOR;
     float2 uv_MainTex;
     float2 uv_BumpMap;

    };
 
 
    sampler2D _MainTex;
    sampler2D _BumpMap;
       
void surf (Input IN, inout SurfaceOutput o) {
      
         o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; 
         o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap)); 
        // What should I add here to get it to work ?
    }
    ENDCG
 
 
    }
 
 
      Fallback "Diffuse"
 
}
1 Like

Thanks but I’ve seen that thread but still can’t get it to work:(

Line 18 is where you declare the vertex color. Now you certainly need to use it!

Line 30 may e.g. be replace with something like this:

o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.color.rgb;
1 Like

Still can’t change the Main Color

Warning: Untested

Shader "My_Shaders/FirstShader" {
   Properties {
     _Color ("Main Color", Color) = (1,1,1,0.5) // Tint
     _MainTex ("Texture", 2D) = "white" {}
     _BumpMap ("Bumpmap", 2D) = "bump" {}
   }

   Subshader {
     Tags { "RenderType" = "Opaque" }

     CGPROGRAM
     #pragma surface surf Lambert

     struct Input {
       float4 color : COLOR; // Vertex Color
       float2 uv_MainTex;
       float2 uv_BumpMap;
     };
 
     float4 _Color; // Tint
     sampler2D _MainTex;
     sampler2D _BumpMap;

     void surf (Input IN, inout SurfaceOutput o) {
       o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * IN.color.rgb * _Color; // Texture * Vertex Color * Tint
       o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
     }
     ENDCG

   }
   Fallback "Diffuse"
}
1 Like

Great, Worked
Thanks a lot
Thanks a lot :slight_smile: