Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active January 20, 2019 12:46
Show Gist options
  • Save unitycoder/444e29be43dce20d991ecf90047ed75e to your computer and use it in GitHub Desktop.
Save unitycoder/444e29be43dce20d991ecf90047ed75e to your computer and use it in GitHub Desktop.
Shader Sprites/Clip
// removed ColorTint, Added clip() based on alpha
Shader "Sprites/Clip"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("AlphaCutoff", Range(0,1)) = 1
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
fixed _Cutoff;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D (_MainTex,IN.texcoord);
clip(c.a-_Cutoff);
c.rgb *= c.a;
return c;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment