效果:
代码实现:
Shader "MyShader/Sim"
{
Properties
{
_MainTex("主贴图",2D)="white"{}
_MainColor("主贴图颜色",color)=(1,1,1,1)
_InnerSimPower("内描边强度",Range(-1.0,3.0))=0.0
_InnerSimColor("内描边颜色",color)=(1,1,1,1)
_OutSimPower("外描边强度",Range(0.0,5.0))=1.0
_OutSimColor("外描边颜色",color)=(1,1,1,1)
_RimIntensity("描边颜色插值",Range(0.0,1.0))=0
}
SubShader
{
Pass
{
ColorMask 0
ZWrite On
}
Tags{"RenderType"="Transparent" "Queue"="Transparent"}
Pass
{
Blend SrcAlpha One
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
float _InnerSimPower;
float _OutSimPower;
fixed3 _InnerSimColor;
fixed3 _OutSimColor;
fixed3 _MainColor;
float _RimIntensity;
struct vertexInput
{
float4 vertex:POSITION;
float3 normal:NORMAL;
float4 texcoord:TEXCOORD0;
};
struct vertexOutput
{
float4 pos:SV_POSITION;
float3 worldNormal:TEXCOORD0;
float3 worldPos:TEXCOORD1;
float2 uv:TEXCOORD2;
};
vertexOutput vert(vertexInput v)
{
vertexOutput o = (vertexOutput)0;
o.pos = UnityObjectToClipPos(v.vertex);
o.worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos = mul(unity_ObjectToWorld,v.vertex).xyz;
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
float4 frag(vertexOutput i):SV_TARGET
{
half3 worldNormal = normalize(i.worldNormal);
half3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
half3 viewDir = normalize(UnityWorldSpaceViewDir(i.worldPos));
float finnesl = smoothstep(_InnerSimPower,_OutSimPower,1-saturate(dot(worldNormal,viewDir)));
fixed3 abledo = tex2D(_MainTex,i.uv).rgb*_MainColor.rgb;
fixed3 color = finnesl*lerp(_InnerSimColor.rgb,_OutSimColor.rgb,_RimIntensity)*abledo;
return float4(color,finnesl);
}
ENDCG
}
}
}