I've been writing a custom surface shader which allows for vertex colors (with alphas) to be set programmatically. From test runs of the shader itself, it works perfectly fine, and I am able to set the color of vertices programmatically. Unfortunately, I ran into some other issues. Currently, the shader is rendering mesh faces quite strangely, and I cannot figure out why:
The shader code itself currently looks like this:
Shader "Custom/VertexColorSurface" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" { }
}
SubShader {
Tags { "RenderType"="Cutout" }
CGPROGRAM
#pragma surface surf Lambert alpha
#pragma target 3.0
struct Input {
float2 uv_MainTex;
float4 color : COLOR;
};
sampler2D _MainTex;
fixed4 _Color;
void surf(Input IN, inout SurfaceOutput OUT) {
OUT.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * _Color.rgb * IN.color.rgb;
OUT.Alpha = tex2D(_MainTex, IN.uv_MainTex).a * _Color.a * IN.color.a;
OUT.Specular = 0.2;
OUT.Gloss = 1.0;
}
ENDCG
}
FallBack "Diffuse"
}
Currently the two solutions I've tried have been using ZWrite On
and ColorMask 0
in a Pass
block, and while both of these methods fix the face rendering issues, they totally screw up alpha blending, which is something I need.
What might be causing this issue, and how do I fix it?