[Beginner] Help me modify my vertex/fragment shader to include a texture

Hi,

I have a shader (full code below) that renders dots. Currently, all the dots are white, and I’m having a hard time applying a texture (or really any way to make all the dots form a color gradient). I tried just making a surf function to do it but couldn’t get it to work. Any thoughts?

Shader "Custom/Dots" {
    Properties {
        _Scale ("Grid Scale", Float) = 7.0
        _DotSize ("Dot Size", Float) = .05
        _MainTex("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader {
        Tags
        {
            "Queue"="Transparent" 
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
        }
        LOD 200
       
        Pass {
            ZWrite Off Cull Off Blend SrcAlpha OneMinusSrcAlpha
            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"
               
                sampler2D _MainTex;
               
                struct v2f {
                    float4 pos : SV_POSITION;
                    //float2 uv_MainTex : TEXCOORD0;
                    float3  worldPos : TEXCOORD0;
                    float3  worldNormal : TEXCOORD1;
                    float2 uv_MainTex : TEXCOORD2;
                };

                struct Input {
                    float2 uv_MainTex;
                };
           
                //float4 _MainTex_ST;
           
             v2f vert (appdata_base v)
            {
                v2f o;
               
                o.pos = UnityObjectToClipPos(v.vertex);
                o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                o.worldNormal = mul(unity_ObjectToWorld, float4(v.normal, 0.0)).xyz;
                return o;
            }
                   
            sampler2D _MainTex;
            uniform float _Scale;
            uniform float _DotSize;
           
                float4 frag(v2f In) : COLOR
                {
                    //float scale = .1f;
                    float3 grid = float3(0,0,0);
                    float3 pos = In.worldPos.xyz ;
                   
                    grid.x = fmod(pos.x, _Scale);
                    grid.y = fmod(pos.y, _Scale);
                    grid.z = fmod(pos.z, _Scale);
                   
                    
                    float zgrid = length(abs(grid.xy) - (0.5 * _Scale));
                    float xgrid = length(abs(grid.yz) - (0.5 * _Scale));
                    float ygrid = length(abs(grid.xz) - (0.5 * _Scale));
                   
                    float3 norm = In.worldNormal;
                    float nyblend = abs(norm.y);
                    float nzblend = abs(norm.z);
                   
                    float3 result = step(lerp(lerp(xgrid,ygrid,nyblend),zgrid, nzblend), _DotSize);
                   
                    float4 ret = float4(1, result);
                    //fixed4 col = tex2D(_MainTex, In.uv_MainTex);
                    return ret;
                }
            ENDCG
        }
    }
}

It’s pretty much already there. Just end with return ret * col and uncomment the line before that. Then in the vertex shader add o.uv_MainTex = v.texcoord