A custom shader I wrote for a 2D face rig of mine has recently stopped working in Unity. Before the shader used to render correctly both in the scene view and in the game view but something happened along the line I guess.
Here is all of that I can provide, but it seems that Unity has stopped rendering fragments in the UV4 channel (if that makes sense). Also I’m on the standard/built-in rendering pipeline.
Here is the vertex and fragment shader:
v2f vert (appdata v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv0 = v.uv0; // Base texture uvs
o.uv1 = (((v.uv1 - float2(0, 1)) * _UVEyeScale) + float2(0, 1)) + _UVEyeOffset; // Eye texture uvs
o.uv2 = (((v.uv2 - float2(0.5, 0.5)) * (1 / _UVPupilScale)) + float2(0.5, 0.5)) + _UVPupilOffsetL; // L Pupil
o.uv3 = (((v.uv3 - float2(0.5, 0.5)) * (1 / _UVPupilScale)) + float2(0.5, 0.5)) + _UVPupilOffsetR; // R Pupil
o.uv4 = (((v.uv4 - float2(0, 1)) * _UVMouthScale) + float2(0, 1)) + _UVMouthOffset; // Mouth texture uvs
float4 lighting = float4(ShadeVertexLightsFull(v.vertex, v.normal, 4, true), 1);
o.diff = lighting * _Color;
UNITY_TRANSFER_FOG(o,o.vertex); // Pass fog
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 faceColor = tex2D(_FaceTexture, i.uv0);
fixed4 eyeColor = tex2D(_EyeTexture, i.uv1);
fixed4 mouthColor = tex2D(_MouthTexture, i.uv4);
fixed4 pupilColorL = tex2D(_PupilTextureL, i.uv2);
fixed4 pupilColorR = tex2D(_PupilTextureR, i.uv3);
fixed4 pupilsColor = (eyeColor * pupilColorL) * (eyeColor * pupilColorR);
fixed4 finalColorE = lerp(faceColor, pupilsColor, eyeColor.a);
fixed4 finalColorM = lerp(finalColorE, mouthColor, mouthColor.a);
finalColorM.a = mouthColor.a + eyeColor.a + faceColor.a;
// Lighting
fixed4 diffColor = finalColorM;
diffColor.xyz = diffColor.xyz * i.diff.xyz;
diffColor.w = diffColor.w * i.diff.w;
finalColorM = lerp(diffColor, finalColorM, _Emission);
// Apply fog
UNITY_APPLY_FOG(i.fogCoord, finalColorM);
return finalColorM;
}
ENDCG
}
And the data structs:
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
};
struct v2f
{
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float2 uv3 : TEXCOORD3;
float2 uv4 : TEXCOORD4;
UNITY_FOG_COORDS(6)
float4 vertex : SV_POSITION;
fixed4 diff : COLOR0;
UNITY_VERTEX_OUTPUT_STEREO
};
Thanks again!


