Shader "MY/ColourCastCutout" { Properties{ _Color("Main Color", Color) = (1,1,1,1) _Bright("Bright", Float) = 1 _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 _MainTex("Base (RGB)", 2D) = "white" { } [Toggle] _CastColor("ColorCast?", Float) = 0 _ColourTex("ColourTex (RGB)", 2D) = "white" { } _CastColorR("CastColorR", Color) = (1,1,1,1) _CastColorG("CastColorG", Color) = (1,1,1,1) _CastColorB("CastColorB", Color) = (1,1,1,1) _CastColorA("CastColorA", Color) = (1,1,1,1) [Enum(UnityEngine.Rendering.CullMode)] _Cull("Cull Mode", Float) = 2 } SubShader{ Tags { "QUEUE" = "Geometry" "RenderType" = "Opaque" } LOD 200 Cull[_Cull] Blend SrcAlpha OneMinusSrcAlpha Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2.0 //#pragma multi_compile_fog #pragma multi_compile __ _CASTCOLOR_ON #include "UnityCG.cginc" struct v2f { float4 vertex : SV_POSITION; float2 texcoord : TEXCOORD0; //UNITY_FOG_COORDS(1) //UNITY_VERTEX_OUTPUT_STEREO }; sampler2D _MainTex; half4 _MainTex_ST; half4 _Color; half _Bright; half _Cutoff; #ifdef _CASTCOLOR_ON sampler2D _ColourTex; //float4 _ColourTex_ST; half4 _CastColorR; half4 _CastColorG; half4 _CastColorB; half4 _CastColorA; #endif v2f vert(appdata_base v) { v2f o; UNITY_SETUP_INSTANCE_ID(v); //UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); o.vertex = UnityObjectToClipPos(v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); //UNITY_TRANSFER_FOG(o, o.vertex); return o; } half3 mix(half3 x, half3 y, half a) { return x * (1 - a) + y * a; } fixed4 frag(v2f i) : SV_Target { half4 main = tex2D(_MainTex, i.texcoord); clip(main.a - _Cutoff); half3 cc = main.rgb; #ifdef _CASTCOLOR_ON half4 mask = tex2D(_ColourTex, i.texcoord); half gray = Luminance(main.rgb); //half3 gray = main.rgb; cc = mix(cc.rgb, (_CastColorR.rgb*(gray*_CastColorR.a)), mask.r); cc = mix(cc.rgb, (_CastColorG.rgb*(gray*_CastColorG.a)), mask.g); cc = mix(cc.rgb, (_CastColorB.rgb*(gray*_CastColorB.a)), mask.b); cc = mix(cc.rgb, (_CastColorA.rgb*(gray*_CastColorA.a)), 1 - mask.a); #endif half4 col; col.rgb = cc * _Color.rgb * (1.0 + 0.25 * _Bright); col.a = main.a * _Color.a; //UNITY_APPLY_FOG(i.fogCoord, col); return col; } ENDCG } } Fallback "Unlit/Transparent Cutout" }