-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpriteOutline.shader
73 lines (63 loc) · 2.45 KB
/
SpriteOutline.shader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Sprites/SpriteOutline"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
[MaterialToggle] _Outline ("Outline", Float) = 0
_OutlineColor ("Outline Color", Color ) = (1,1,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 SpriteVert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_instancing
#pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#include "UnitySprites.cginc"
float _Outline;
float4 _OutlineColor;
float4 _MainTex_TexelSize;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 col = SampleSpriteTexture (IN.texcoord) * IN.color;
col.rgb *= col.a;
if ( _Outline > 0 && col.a == 0 && IN.color.a > 0)
{
fixed4 pixelUp = tex2D( _MainTex, IN.texcoord + fixed2(0,_MainTex_TexelSize.y));
fixed4 pixelDown = tex2D( _MainTex, IN.texcoord - fixed2(0,_MainTex_TexelSize.y));
fixed4 pixelRight = tex2D( _MainTex, IN.texcoord + fixed2(_MainTex_TexelSize.x,0));
fixed4 pixelLeft = tex2D( _MainTex, IN.texcoord - fixed2(_MainTex_TexelSize.x,0));
if ( pixelUp.a != 0 || pixelDown.a != 0 || pixelRight.a != 0 || pixelLeft.a != 0)
{
col = _OutlineColor;
}
}
return col * IN.color;
}
ENDCG
}
}
}