<pre class="plain" name="code">Shader "Test"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_DissolveTex ("Dissolve Texture", 2D) = "white" {}
_LimitValue ("Percent", Range(0.0, 1.0)) = 0.0
_BrightFactor ("Bright Factor", Range(0.0, 4.0)) = 1.0
_Color ("Color", Color) = (1, 1, 1, 1)
_EdgeColor("EdgeColor", Color) = (1, 1, 1, 1)
_EdgeWidth("EdgeWidth", Range(0.01, 1.0)) = 0.5
}
SubShader
{
Tags {"Queue"="Transparent"}
Pass
{
Blend SrcAlpha One
Cull Off
ZWrite Off
CGPROGRAM
//#pragma vertex vert_img
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_particles
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
fixed4 color : COLOR;
};
sampler2D _MainTex;
fixed4 _MainTex_ST;
sampler2D _DissolveTex;
fixed4 _DissolveTex_ST;
float _LimitValue;
float _BrightFactor;
float4 _Color;
// edge
float4 _EdgeColor;
float _EdgeWidth;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
o.texcoord1 = TRANSFORM_TEX(v.texcoord, _DissolveTex);
o.color = v.color;
return o;
}
float4 frag(v2f i) : COLOR
{
float maskValue = tex2D(_DissolveTex,i.texcoord1).r;
// clip(x) Discards the current pixel, if any component of x is less than zero.
float dist = maskValue - _LimitValue;
clip(dist);
float4 texColor = tex2D(_MainTex,i.texcoord);
texColor *= _Color * i.color;
texColor.rgb *= _BrightFactor;
float blendFactor = saturate(dist / _EdgeWidth);
// lerp(a,b f) = (1-f) * a + b * f
float3 resCol = lerp(_EdgeColor.rgb, texColor.rgb, blendFactor);
return float4(resCol.rgb, texColor.a);
}
ENDCG
}
}
FallBack Off
}
思路: