Advertisement
MetaMarkTea

Untitled

Dec 31st, 2021
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/MaskShader"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _Radius ("Radius", Range(0, 0.5)) = 0.5
  7.     }
  8.     SubShader
  9.     {
  10.         Tags { "RenderType"="Opaque" }
  11.         LOD 100
  12.  
  13.         Pass
  14.         {
  15.             CGPROGRAM
  16.             #pragma vertex vert
  17.             #pragma fragment frag
  18.             // make fog work
  19.             #pragma multi_compile_fog
  20.  
  21.             #include "UnityCG.cginc"
  22.  
  23.             struct appdata
  24.             {
  25.                 float4 vertex : POSITION;
  26.                 float2 uv : TEXCOORD0;
  27.             };
  28.  
  29.             struct v2f
  30.             {
  31.                 float2 uv : TEXCOORD0;
  32.                 UNITY_FOG_COORDS(1)
  33.                 float4 vertex : SV_POSITION;
  34.             };
  35.  
  36.             sampler2D _MainTex;
  37.             float4 _MainTex_ST;
  38.             float _Radius;
  39.  
  40.             v2f vert (appdata v)
  41.             {
  42.                 v2f o;
  43.                 o.vertex = UnityObjectToClipPos(v.vertex);
  44.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  45.                 UNITY_TRANSFER_FOG(o,o.vertex);                
  46.                 return o;
  47.             }
  48.  
  49.             fixed4 frag (v2f i) : SV_Target
  50.             {
  51.                 // sample the texture
  52.                 fixed4 col = tex2D(_MainTex, i.uv);
  53.                 // apply fog
  54.                 UNITY_APPLY_FOG(i.fogCoord, col);
  55.                
  56.                 if (length(float2(0.5, 0.5) - i.uv) > _Radius)
  57.                 {
  58.                     discard;
  59.                 }
  60.  
  61.                  #ifdef UNITY_UI_ALPHACLIP
  62.                  clip (color.a - 0.001);
  63.                  #endif
  64.                
  65.                 return col;
  66.             }
  67.             ENDCG
  68.         }
  69.     }
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement