You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.4 KiB
141 lines
4.4 KiB
Shader "PeachValley/GameObject" |
|
{ |
|
Properties |
|
{ |
|
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} |
|
_Color ("Tint", Color) = (1,1,1,1) |
|
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {} |
|
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0 |
|
|
|
[Space] |
|
[Header(Edge)] |
|
[Toggle] _EFFECT_EDGE ("Enable Edge", Float) = 0 |
|
_OutLineColor ("Outline color", Color) = (0.804, 0.2, 0, 1)//描边颜色 |
|
_PixelSize ("Pixel Size", Range(0, 10)) = 6 |
|
_DetectAlpha ("DetectAlpha", Range(0, 0.2)) = 0.1 //四周的点算alpha平均,若大于则显示描边 |
|
_ImageCullAlpha ("ImageCullAlpha", Range(0, 1)) = 0.2 //当前所在的点若大于改值,则无条件原图 |
|
// _Smooth ("Smooth", Range(1, 10)) = 10 |
|
// _SmoothAlphaBase ("SmoothAlphaBase", Range(0, 1)) = 0.8 |
|
_HaveEdgeEffect ("HaveEdgeEffect", Range(0, 1)) = 1 |
|
|
|
[Space] |
|
[Header(Highlight)] |
|
[Toggle] _EFFECT_HIGHLIGHT("Enable Highlight", Float) = 0 |
|
} |
|
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 _ ETC1_EXTERNAL_ALPHA |
|
#pragma multi_compile _EFFECT_EDGE _EFFECT_EDGE_ON |
|
#pragma multi_compile _EFFECT_HIGHLIGHT _EFFECT_HIGHLIGHT_ON |
|
#include "UnityCG.cginc" |
|
|
|
struct appdata_t |
|
{ |
|
float4 vertex : POSITION; |
|
float4 color : COLOR; |
|
float2 texcoord : TEXCOORD0; |
|
}; |
|
|
|
struct v2f |
|
{ |
|
float4 vertex : SV_POSITION; |
|
fixed4 color : COLOR; |
|
float2 texcoord : TEXCOORD0; |
|
}; |
|
|
|
fixed4 _Color; |
|
|
|
v2f vert(appdata_t IN) |
|
{ |
|
v2f OUT; |
|
OUT.vertex = UnityObjectToClipPos(IN.vertex); |
|
OUT.texcoord = IN.texcoord; |
|
OUT.color = IN.color * _Color; |
|
#ifdef PIXELSNAP_ON |
|
OUT.vertex = UnityPixelSnap (OUT.vertex); |
|
#endif |
|
|
|
return OUT; |
|
} |
|
|
|
sampler2D _MainTex; |
|
sampler2D _AlphaTex; |
|
|
|
// for edge |
|
fixed4 _OutLineColor; |
|
float _PixelSize; |
|
float2 _MainTex_TexelSize; |
|
float _DetectAlpha; |
|
float _ImageCullAlpha; |
|
// float _Smooth; |
|
// float _SmoothAlphaBase; |
|
half _HaveEdgeEffect; |
|
|
|
void Edge(inout fixed4 outColor, half2 changedUV) |
|
{ |
|
_PixelSize = _PixelSize * _MainTex_TexelSize; |
|
// fixed4 color = tex2D(_MainTex, fixed2(changedUV.x, changedUV.y)); |
|
fixed color1 = tex2D(_MainTex, fixed2(changedUV.x + _PixelSize, changedUV.y + _PixelSize)).a; |
|
fixed color2 = tex2D(_MainTex, fixed2(changedUV.x - _PixelSize, changedUV.y - _PixelSize)).a; |
|
fixed color3 = tex2D(_MainTex, fixed2(changedUV.x + _PixelSize, changedUV.y - _PixelSize)).a; |
|
fixed color4 = tex2D(_MainTex, fixed2(changedUV.x - _PixelSize, changedUV.y + _PixelSize)).a; |
|
fixed a = (color1 + color2 + color3 + color4) / 4; |
|
int if1 = step(outColor.a, _ImageCullAlpha); |
|
int if2 = step(a, _DetectAlpha); |
|
// outColor = outColor* (1 - _HaveEdgeEffect) + _HaveEdgeEffect *(if1 * (((1 - if2) * fixed4(_OutLineColor.rgb, pow(a + _SmoothAlphaBase, _Smooth) * _OutLineColor.a))) + color * (1 - if1)); |
|
outColor = outColor* (1 - _HaveEdgeEffect) + _HaveEdgeEffect *(if1 * (((1 - if2) * _OutLineColor)) + outColor * (1 - if1)); |
|
} |
|
|
|
fixed4 SampleSpriteTexture (float2 uv) |
|
{ |
|
fixed4 color = tex2D (_MainTex, uv); |
|
|
|
#if ETC1_EXTERNAL_ALPHA |
|
fixed4 alpha = tex2D (_AlphaTex, uv); |
|
color.a = lerp (color.a, alpha.r, _EnableExternalAlpha); |
|
#endif |
|
|
|
return color; |
|
} |
|
|
|
fixed4 frag(v2f IN) : SV_Target |
|
{ |
|
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color; |
|
|
|
#if _EFFECT_HIGHLIGHT_ON |
|
c.rgb *= fixed3(1.3, 1.3, 1.3); |
|
#endif |
|
|
|
#if _EFFECT_EDGE_ON |
|
Edge(c, IN.texcoord); |
|
#endif |
|
c.rgb *= c.a; |
|
|
|
return c; |
|
} |
|
|
|
ENDCG |
|
} |
|
} |
|
FallBack "Diffuse" |
|
}
|
|
|