# 【边缘带光的溶解效果】
下面是Shader代码:
Shader "VP/Tests/Shader02"
{
Properties {
_BaseTexture("纹理",2d) = "" {}
_DissolveNoiseTexture("溶解噪波图",2d) = "" {}
_DissolveWidth("溶解边缘大小", float) = 2
_DissolveFade("消散进度0~1",Range(0,1)) = 0.5
[HDR]_FullGlowDissolveEdgeColor("溶解颜色",Color) = (11,0.6,0.6,0)
}
SubShader {
Tags {
"Queue" = "Transparent"
"Rendertype" = "Transparent"
"ForceNoShadowCasting" = "True" // 不捕获阴影
"IgnoreProjector"= "True" // 不响应投射器
}
Pass {
Name "FORWARD"
Tags {
"LightMode" = "ForwardBase"
}
Blend One OneMinusSrcAlpha
CGPROGRAM
#include "UnityCG.cginc"
#pragma target 3.0
#pragma multi_compile_fwdbase_fullshadows
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _BaseTexture;
uniform sampler2D _DissolveNoiseTexture; uniform float4 _DissolveNoiseTexture_ST;
uniform float _DissolveWidth;
uniform float _DissolveFade;
uniform float3 _FullGlowDissolveEdgeColor;
struct VertexInput
{
float4 vertex:POSITION;
float2 uv0:TEXCOORD0;
float2 noiseuv:TEXCOORD1;
};
struct VertexOutput
{
float4 pos:SV_POSITION;
float2 uv0:TEXCOORD0;
float2 noiseuv:TEXCOORD1;
};
VertexOutput vert(VertexInput i)
{
VertexOutput o = (VertexOutput)0;
o.uv0 = i.uv0;
o.pos = UnityObjectToClipPos(i.vertex);
o.noiseuv = TRANSFORM_TEX(i.noiseuv,_DissolveNoiseTexture);
return o;
}
float4 frag(VertexOutput i):COLOR
{
float4 baseColor = tex2D(_BaseTexture,i.uv0);
float4 noisecolor = tex2D(_DissolveNoiseTexture,i.noiseuv);
float isShow = step( noisecolor.r , _DissolveFade );
float dissolveVal = max( ( _DissolveFade * _DissolveWidth ) , 0.001 );
float4 resultColor = float4(( ( (_FullGlowDissolveEdgeColor).rgb * ( isShow - step( noisecolor , ( ( _DissolveFade * ( 1.01 + dissolveVal ) ) - dissolveVal ) ) ) ) + baseColor.rgb ) , baseColor.a * isShow);
//return resultColor;
float4 c = resultColor * baseColor;
c.rgb *= c.a;
return c;
}
ENDCG
}
}
Fallback "Diffuse"
}
下面是测试用素材图:
← 【采用指定区域坐标的贴图】 【法线贴图】 →