So i have this dotted pattern shader that i’ve been working on for a little bit now. Added a color input for the dot color but i can’t figure out how to set a color input for the background color (in this case black) behind the dots. Probably a newbie question but i really don’t know how.
This is the dotted pattern and i want a color input for the black. I already added a property and identifier for it but i don’t know where i would have to add it inside the fragment shader.


Shader "Unlit/Dotted Pattern"
{
Properties
{
[HideInInspector]_MainTex ("Texture", 2D) = "white" {}
[HDR]_DotColor ("Dot Color", Color) = (1,1,1,1)
[HDR]_BgColor ("Background Color", Color) = (1,1,1,1)
_DotsAngle ("Dots Angle", float) = 45
_DotSize ("Dot Size", range(10,100)) = 30
_DotShape ("Dot Shape", range(0.01,0.99)) = 0.1
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _DotColor;
float4 _BgColor;
float _DotsAngle;
float _DotSize;
float _DotShape;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
static float PI = 3.1415926535897932384626433832795;
static float PI180 = float(PI / 180.0);
float sind(float a)
{
return sin(a * PI180);
}
float cosd(float a)
{
return cos(a * PI180);
}
float added(float2 sh, float sa, float ca, float2 c, float d)
{
return 0.5 + 0.25 * cos((sh.x * sa + sh.y * ca + c.x) * d) + 0.25 * cos((sh.x * ca - sh.y * sa + c.y) * d);
}
fixed4 frag (v2f i) : SV_Target
{
float threshold = clamp(float(_ScreenParams.x / _ScreenParams.x) * 0.99, 0, 1);
float ratio = _ScreenParams;
float coordX = i.uv.x;
float coordY = i.uv.y;
float2 dstCoord = float2(coordX, coordY);
float2 srcCoord = float2(coordX, coordY / ratio);
float2 rotationCenter = float2(0, 0);
float2 shift = dstCoord - rotationCenter;
float dotSize = _DotSize;
float angle = _DotsAngle;
float rasterPattern = added(shift, sind(angle), cosd(angle), rotationCenter, PI / dotSize * 680.0);
float4 srcPixel = tex2D(_MainTex, srcCoord);
float avg = _DotShape;
float4 col = (1, 1, 1, 1) * _DotColor;
float gray = (rasterPattern * threshold + avg - threshold) / (1.0 - threshold);
return float4 (gray, gray, gray, 1.0) * col;
}
ENDCG
}
}
}

