Files
JJBB/Assets/Project/Shader/CharacterNpcLerp.shader
2024-08-23 15:49:34 +08:00

82 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Shader "Zhanyou/Character/NPCColorLerp" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
[NoScaleOffset]_OtherTex ("Other Texture", 2D) = "white" {}
_Emission ("Emission", Range(0, 1)) = 0.2
// 角色材质颜色,乘法运算
_Color("Blend Color", Color) = (1, 1, 1, 1)
// Emission叠加颜色加法运算
_AddColor("Additive Color", Color) = (0, 0, 0, 1)
_Outline ("Outline Power", float) = 22
_OutlineColor ("Outline Color", Color) = (0.02, 0.02, 0.02, 1)
// 溶解贴图RGB为颜色A为溶解开始数值
_DissolveTex ("Dissolve Tex", 2D) = "white" {}
// 部分溶解的渐变区域值
_DissolveFade ("Dissolve Fade", Range(0, 1)) = 0.1
// 完全溶解的Alpha数值
_DissolveEnd ("Dissolve End", Range(0, 1)) = 0.5
}
SubShader {
Tags { "Queue"="AlphaTest+10" "RenderType"="Character" }
Pass {
Stencil {
Ref 1
Comp always
Pass replace
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "NpcBase.cginc"
uniform sampler2D _OtherTex;
uniform sampler2D _DissolveTex;
uniform half4 _DissolveTex_ST;
uniform half _DissolveFade;
uniform half _DissolveEnd;
struct v2f {
float4 pos : SV_POSITION;
float2 texcoord : TEXCOORD0;
float2 dissolveCoord : TEXCOORD1;
half rim : TEXCOORD2;
UNITY_FOG_COORDS(3)
};
v2f vert (appdata_tan v)
{
v2f o;
UNITY_INITIALIZE_OUTPUT(v2f, o);
NPC_VERT_COMMON(o);
o.dissolveCoord = TRANSFORM_TEX(v.texcoord, _DissolveTex);
UNITY_TRANSFER_FOG(o, o.pos);
return o;
}
fixed4 frag(v2f i) : SV_TARGET
{
fixed4 col = tex2D(_OtherTex, i.texcoord);
fixed4 mainCol = tex2D(_MainTex, i.texcoord);
fixed4 dissolve = tex2D(_DissolveTex, i.dissolveCoord);
if (dissolve.a <= _DissolveEnd + _DissolveFade)
{
float rate = max(0.0, (dissolve.a - _DissolveEnd) / _DissolveFade);
col.rgb = lerp(mainCol.rgb, col.rgb, rate * rate);
}
col.rgb *= _Color.rgb;
col.rgb += col.rgb * _Emission + _AddColor;
col.rgb += _OutlineColor.rgb * _OutlineColor.a * i.rim;
UNITY_OPAQUE_ALPHA(col.a);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
Fallback "Zhanyou/Character/NPC"
}