Shader "Zhanyou/SkillRange" { Properties { _ShadowTex("Cookie", 2D) = "gray" {} _RangeRadiu("Radiu",Range(0,0.5)) = 0.2 _RangeAngle("Angle",Range(0,180)) = 60 _LineW1("LineW",Range(0,0.5)) = 0.1 _LineW2("LineW",Range(0,0.1)) = 0.01 _LineColor("LineColor",Color) = (1,0,0,1) _Forword("Forword",Vector) = (0,0,0,0) [Toggle(CLIP_BY_RANGE)] _Redify("Clip By Range", Int) = 0 } //Properties{ // _ShadowTex("Cookie", 2D) = "gray" {} // _RangeRadiu("Radiu",Range(0,0.5)) = 0.2 // _RangeAngle("Angle",Range(0,180)) = 60 // _LineW1("LineW",Range(0,0.5)) = 0.1 // _LineW2("LineW",Range(0,0.1)) = 0.01 // _LineColor("LineColor",Color) = (1,0,0,1) // _Forword("Forword",Vector) = (0,0,0,0) // _Type("Type",Int) = 1 //} Subshader{ Tags{ "Queue" = "Transparent-1" } ZWrite Off ColorMask RGB Blend SrcAlpha OneMinusSrcAlpha CGINCLUDE #pragma vertex vert #pragma multi_compile __ CLIP_BY_RANGE #pragma fragment frag #include "UnityCG.cginc" struct v2f { float2 uvShadow : TEXCOORD0; float4 pos : SV_POSITION; }; struct a2v { float4 vertex:POSITION; float4 texcoord:TEXCOORD0; }; v2f vert(a2v v) { v2f o; UNITY_INITIALIZE_OUTPUT(v2f, o); o.pos = UnityObjectToClipPos(v.vertex); o.uvShadow = v.texcoord.xy; return o; } sampler2D _ShadowTex; float _RangeRadiu; float _RangeAngle; float _LineW1; float _LineW2; float4 _LineColor; float4 _Forword; fixed4 frag(v2f i) : SV_Target { fixed4 res = tex2D(_ShadowTex, i.uvShadow); #if CLIP_BY_RANGE float2 center = float2(0.5, 0.5); float dis = distance(i.uvShadow, center); float2 dir = float2(i.uvShadow.x - 0.5,i.uvShadow.y - 0.5); float2 centerDir = float2(_Forword .x-0.5, _Forword .y-0.5); float angle = dot(dir, centerDir)/(length(dir)*length(centerDir)); float angleMax = cos(radians(_RangeAngle)); if (dis < _RangeRadiu) { res = fixed4(0, 0, 0, 0); } else { if (dis >= _RangeRadiu && dis < _RangeRadiu + _LineW1) { if (angle > angleMax) { res = _LineColor; } else { res = fixed4(0, 0, 0, 0); } } else { if (dis >= _RangeRadiu + _LineW1 && dis < 0.5- _LineW1) { if (angle > angleMax && angle < angleMax+ _LineW2) { res = _LineColor; } else { if(angle <= angleMax) res = fixed4(0, 0, 0, 0); } } else { if (dis >= 0.5- _LineW1 && dis <0.5) { if (angle > angleMax) { res = _LineColor; } else { res = fixed4(0, 0, 0, 0); } } } } } #endif return res; } ENDCG Pass { Stencil { Ref 1 Comp Equal } CGPROGRAM ENDCG } Pass { Stencil { Ref 1 Comp NotEqual } ZTest Always CGPROGRAM ENDCG } } }