1
+ // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
2
+
3
+ Shader "Custom/RadialFill"
4
+ {
5
+ Properties
6
+ {
7
+ [PerRendererData ] _MainTex ( "Sprite Texture" , 2D ) = "white" {}
8
+ _Color ( "Tint" , Color ) = (1 ,1 ,1 ,1 )
9
+ _Angle( "Angle" , Range (0 , 360 )) = 0
10
+ _Arc1( "Arc Point 1" , Range (0 , 360 )) = 15
11
+ _Arc2( "Arc Point 2" , Range (0 , 360 )) = 15
12
+ [MaterialToggle ] PixelSnap ( "Pixel snap" , Float ) = 0
13
+ }
14
+
15
+ SubShader
16
+ {
17
+ Tags
18
+ {
19
+ "Queue" ="Transparent"
20
+ "IgnoreProjector" ="True"
21
+ "RenderType" ="Transparent"
22
+ "PreviewType" ="Plane"
23
+ "CanUseSpriteAtlas" ="True"
24
+ }
25
+
26
+ Cull Off
27
+ Lighting Off
28
+ ZWrite Off
29
+ Blend One OneMinusSrcAlpha
30
+
31
+ Pass
32
+ {
33
+ CGPROGRAM
34
+ #pragma vertex vert
35
+ #pragma fragment frag
36
+ #pragma multi_compile _ PIXELSNAP_ON
37
+ #include "UnityCG.cginc"
38
+
39
+ struct appdata_t
40
+ {
41
+ float4 vertex : POSITION ;
42
+ float4 color : COLOR ;
43
+ float2 texcoord : TEXCOORD0 ;
44
+ };
45
+
46
+ struct v2f
47
+ {
48
+ float4 vertex : SV_POSITION ;
49
+ fixed4 color : COLOR ;
50
+ float2 texcoord : TEXCOORD0 ;
51
+ };
52
+
53
+ fixed4 _Color;
54
+
55
+ v2f vert (appdata_t IN)
56
+ {
57
+ v2f OUT;
58
+ OUT.vertex = UnityObjectToClipPos (IN.vertex);
59
+ OUT.texcoord = IN.texcoord;
60
+ OUT.color = IN.color * _Color;
61
+ #ifdef PIXELSNAP_ON
62
+ OUT.vertex = UnityPixelSnap (OUT.vertex);
63
+ #endif
64
+
65
+ return OUT;
66
+ }
67
+
68
+ sampler2D _MainTex;
69
+ sampler2D _AlphaTex;
70
+ float _AlphaSplitEnabled;
71
+ float _Angle;
72
+ float _Arc1;
73
+ float _Arc2;
74
+
75
+ fixed4 SampleSpriteTexture (float2 uv)
76
+ {
77
+ fixed4 color = tex2D (_MainTex, uv);
78
+
79
+ #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED
80
+ if (_AlphaSplitEnabled)
81
+ color.a = tex2D (_AlphaTex, uv).r;
82
+ #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED
83
+
84
+ return color;
85
+ }
86
+
87
+ fixed4 frag (v2f IN) : SV_Target
88
+ {
89
+ fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
90
+ c.rgb *= c.a;
91
+
92
+ //-------- Creating arc --------//
93
+ // sector start/end angles
94
+ float startAngle = _Angle - _Arc1;
95
+ float endAngle = _Angle + _Arc2;
96
+
97
+ // check offsets
98
+ float offset0 = clamp (0 , 360 , startAngle + 360 );
99
+ float offset360 = clamp (0 , 360 , endAngle - 360 );
100
+
101
+ // convert uv to atan coordinates
102
+ float2 atan2Coord = float2 (lerp (-1 , 1 , IN.texcoord.x), lerp (-1 , 1 , IN.texcoord.y));
103
+ float atanAngle = atan2 (atan2Coord.y, atan2Coord.x) * 57.3 ; // angle in degrees
104
+
105
+ // convert angle to 360 system
106
+ if (atanAngle < 0 ) atanAngle = 360 + atanAngle;
107
+
108
+ if (atanAngle >= startAngle && atanAngle <= endAngle) discard ;
109
+ if (atanAngle <= offset360) discard ;
110
+ if (atanAngle >= offset0) discard ;
111
+
112
+ return c;
113
+ }
114
+ ENDCG
115
+ }
116
+ }
117
+ }
0 commit comments