unity:2D图片边缘高亮

http://blog.csdn.net/lyh916/article/details/51487918


Properties

{

_MainTex ("Texture", 2D) ="white"{}

_OffsetUV ("OffsetUV", Range(0, 1)) = 0.1

_EdgeColor ("EdgeColor", Color) = (1, 0, 0, 1)

_AlphaTreshold ("Treshold", Range(0, 1)) = 0.5

}

SubShader

{

Tags {"Queue"="Transparent"}

Blend SrcAlpha OneMinusSrcAlpha

Pass

{

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"

structappdata

{

float4 vertex : POSITION;

fixed2 uv : TEXCOORD0;

};

structv2f

{

float4 vertex : SV_POSITION;

fixed2 uv[5] : TEXCOORD0;

};

sampler2D _MainTex;

float4 _MainTex_ST;

fixed_OffsetUV;

fixed4 _EdgeColor;

fixed_AlphaTreshold;

v2f vert (appdata v)

{

v2f o;

o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);

o.uv[0] = v.uv;

o.uv[1] = v.uv + fixed2(0, _OffsetUV);//up

o.uv[2] = v.uv + fixed2(-_OffsetUV, 0);//left

o.uv[3] = v.uv + fixed2(0, -_OffsetUV);//bottom

o.uv[4] = v.uv + fixed2(_OffsetUV, 0);//right

returno;

}

fixed4 frag (v2f i) : SV_Target

{

fixed4 original = tex2D(_MainTex, i.uv[0]);

fixedalpha = original.a;

fixedp1 = tex2D(_MainTex, i.uv[1]).a;

fixedp2 = tex2D(_MainTex, i.uv[2]).a;

fixedp3 = tex2D(_MainTex, i.uv[3]).a;

fixedp4 = tex2D(_MainTex, i.uv[4]).a;

alpha = p1 + p2 + p3 + p4 + alpha;

alpha /= 5;

if(alpha < _AlphaTreshold) original.rgb = _EdgeColor.rgb;

returnoriginal;

}

ENDCG

}

}

}

你可能感兴趣的:(unity:2D图片边缘高亮)