- Home /
              This question was 
             closed May 01, 2018 at 12:16 PM by 
             Wokarol for the following reason: 
             
 
            Other
Alpha cutoff of sprite based on another texture
I want to combine this two textures:  into sprite like this:
 into sprite like this:  based on one value named angle.
 based on one value named angle.
For example, if this value is set to 0.5 i should get half of this blue circle, if the value is 0.25 I should have quarter of the blue circle. I think that shader would be the bestchoice.
 
                 
                shieldgradient.png 
                (287.0 kB) 
               
 
                
                 
                zrzut-ekranu-87.png 
                (19.1 kB) 
               
 
              
               Comment
              
 
               
              Answer by poisoned_banana · Apr 22, 2018 at 06:06 PM

 Shader "Unlit/AngleShader"
 {
     Properties
     {
         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         _OverlayTex("Overlay Texture",2D) = "white"{}
         _Angle("Angle",Range(0,360)) = 90
     }
     SubShader
     {
         Tags
         { 
             "Queue"="Transparent" 
         }
         LOD 100
 
         Cull Off
         Lighting Off
         ZWrite Off
         Blend One OneMinusSrcAlpha
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             
             #include "UnityCG.cginc"
 
             struct appdata
             {
                 float4 vertex : POSITION;
                 float2 uv : TEXCOORD0;
             };
 
             struct v2f
             {
                 float2 uv : TEXCOORD0;
                 float4 vertex : SV_POSITION;
             };
 
             sampler2D _MainTex;
             sampler2D _OverlayTex;
 
             float4 _MainTex_ST;
             float _Angle;
             
             v2f vert (appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                 return o;
             }
             
             fixed4 frag (v2f i) : SV_Target
             {
                 float x = i.uv.x * 2 - 1;
                 float y = i.uv.y * 2 - 1;
 
                 float ang = degrees(atan2(y,x)) + 180;
                 
                 if(ang - _Angle < 0){
 
                     fixed4 col = tex2D(_MainTex, i.uv);
                     fixed4 overlay = tex2D(_OverlayTex,i.uv);
                     fixed4 final = col * overlay;
                     return final;
 
                 }
                 else
                     return 0;
             }
             ENDCG
         }
     }
 }
 
                 
                angleshader.png 
                (86.9 kB) 
               
 
              That's not quite what I'm looking for. 1. I don't want to cut sprite based on direct angle value, but based on greyscale image and value, so I would be able to add some inequality to cutoff. 2. This shader don't work very well with sprites that have transparency (I mean alpha values other than 1 or 0)
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                