Properties {
_MainTex("Main Texture", 2D) = "white" {}
_CrackTex("Crack Texture", 2D) = "white" {}
_AlphaTex("Alpha Mask Texture", 2D) = "white" {}
[HideInInspector]_AlphaThresh("Alpha Threshold", Range(0, 1)) = 0
}
SubShader {
Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _CrackTex;
float4 _CrackTex_ST;
sampler2D _AlphaTex;
float4 _AlphaTex_ST;
float _AlphaThresh;
v2f vert(appdata_t v) {
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 mainTex = tex2D(_MainTex, i.texcoord);
fixed4 crackTex = tex2D(_CrackTex, i.texcoord);
fixed4 alphaTex = tex2D(_AlphaTex, i.texcoord);
fixed4 maskedCrackTex = (alphaTex.r < 0.5) ? 0 : crackTex;
mainTex = saturate(mainTex + maskedCrackTex);
return mainTex;
}
ENDCG
}
}