I wanted to be able to recolor some of my UI images using color picker and a channel mask. So I created the new Unlit shader with this recolor by mask functionality. But after I applied said shader to UI Image component, it became occluded by background Sprite renderers (it is 2d game). I had to settle with no shaders and using pre-colored pictures. Anything that needs to be added to shader code to avoid it?
Shader "Unlit/PowerupMeterColored"
{
Properties
{
_MainTex ("cell grayscale", 2D) = "white" {}
_CellColor ("cell color", Color) = (0,0,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _CellColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
return col + (1.0 - col.r)*_CellColor;
}
ENDCG
}
}
}