problem with using color in fragment shader

HI all! Could you help me with my question about shaders? I trying write vertex fragment shader. If use i.color in fragment shader, my shader looks just white, but if i use _Color. Shader works correctly.

Shader "custom/green"
{
    Properties
    {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Color Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }

        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag


            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float4 color : COLOR0;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
                float4 color : COLOR0;
            };
           
            float4 _Color;
            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);               
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                o.color = v.color;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col_tex = tex2D(_MainTex, i.uv);
                // fixed4 col = i.color; // not work
                fixed4 col = _Color; // work!
                return col;
            }
            ENDCG
        }
    }
}

_Color is the name of the color property that you see on the material.

i.color is the value passed to the fragment shader from the vertex shader, which the vertex shader got from the mesh’s vertex color data. If you don’t have any color data set on your mesh (either colored in an external program, via a custom script, or some kind of vertex painting tool you’re using in the editor) then it’ll default to white.

1 Like

thank you! I understood