122 lines
3.0 KiB
Plaintext
122 lines
3.0 KiB
Plaintext
|
Shader "Zhanyou/Character/NPCAlpha" {
|
|||
|
Properties {
|
|||
|
_MainTex ("Base (RGB)", 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.03, 0.03, 0.03, 1)
|
|||
|
_Cutoff("Alpha Cutoff", Range(0, 1)) = 0.5
|
|||
|
// 流光贴图
|
|||
|
_FlowTex ("Flow (RGB)", 2D) = "black" {}
|
|||
|
// 流光颜色
|
|||
|
_FlowColor ("Flow Color", Color) = (1, 1, 1, 1)
|
|||
|
// 流光速度
|
|||
|
_FlowSpeed ("Flow Speed", float) = 1
|
|||
|
}
|
|||
|
|
|||
|
SubShader {
|
|||
|
Tags { "Queue"="AlphaTest+10" "RenderType"="CharacterCutout" }
|
|||
|
|
|||
|
Pass {
|
|||
|
Stencil {
|
|||
|
Ref 1
|
|||
|
Comp always
|
|||
|
Pass replace
|
|||
|
}
|
|||
|
CGPROGRAM
|
|||
|
#pragma vertex vert
|
|||
|
#pragma fragment frag
|
|||
|
#pragma shader_feature UseFlowColor
|
|||
|
#pragma multi_compile_fog
|
|||
|
#include "NpcBase.cginc"
|
|||
|
|
|||
|
struct v2f {
|
|||
|
float4 pos : SV_POSITION;
|
|||
|
float2 texcoord : TEXCOORD0;
|
|||
|
half rim : TEXCOORD1;
|
|||
|
UNITY_FOG_COORDS(2)
|
|||
|
#if UseFlowColor
|
|||
|
FLOW_UV(3)
|
|||
|
#endif
|
|||
|
};
|
|||
|
|
|||
|
v2f vert (appdata_tan v)
|
|||
|
{
|
|||
|
v2f o;
|
|||
|
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
|||
|
NPC_VERT_COMMON(o);
|
|||
|
#if UseFlowColor
|
|||
|
FLOW_VERT(o);
|
|||
|
#endif
|
|||
|
UNITY_TRANSFER_FOG(o, o.pos);
|
|||
|
return o;
|
|||
|
}
|
|||
|
|
|||
|
uniform half _Cutoff;
|
|||
|
|
|||
|
fixed4 frag(v2f i) : SV_TARGET
|
|||
|
{
|
|||
|
fixed4 col;
|
|||
|
// 可以略优化到展开贴图后立刻执行clip
|
|||
|
NPC_FRAG_COMMON(col);
|
|||
|
clip(col.a - _Cutoff);
|
|||
|
#if UseFlowColor
|
|||
|
FLOW_FRAG(col);
|
|||
|
#endif
|
|||
|
UNITY_OPAQUE_ALPHA(col.a);
|
|||
|
UNITY_APPLY_FOG(i.fogCoord, col);
|
|||
|
return col;
|
|||
|
}
|
|||
|
ENDCG
|
|||
|
}
|
|||
|
|
|||
|
// 其实没有用的投影通道,但是Unity貌似会用这个通道做屏幕深度运算,所以保留一个
|
|||
|
// Shadow Caster
|
|||
|
// ---- shadow caster pass:
|
|||
|
Pass {
|
|||
|
Name "ShadowCaster"
|
|||
|
Tags { "LightMode" = "ShadowCaster" }
|
|||
|
|
|||
|
CGPROGRAM
|
|||
|
#pragma vertex vert
|
|||
|
#pragma fragment frag
|
|||
|
#pragma multi_compile_shadowcaster
|
|||
|
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
|
|||
|
#include "HLSLSupport.cginc"
|
|||
|
#include "UnityShaderVariables.cginc"
|
|||
|
#define UNITY_PASS_SHADOWCASTER
|
|||
|
#include "UnityCG.cginc"
|
|||
|
#include "Lighting.cginc"
|
|||
|
half _Cutoff;
|
|||
|
|
|||
|
sampler2D _MainTex;
|
|||
|
float4 _MainTex_ST;
|
|||
|
struct v2f {
|
|||
|
V2F_SHADOW_CASTER;
|
|||
|
float2 uv : TEXCOORD1; // _MainTex
|
|||
|
float3 worldPos : TEXCOORD2;
|
|||
|
};
|
|||
|
v2f vert (appdata_full v) {
|
|||
|
v2f o;
|
|||
|
UNITY_TRANSFER_INSTANCE_ID(v,o);
|
|||
|
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
|||
|
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
|||
|
fixed3 worldNormal = UnityObjectToWorldNormal(v.normal);
|
|||
|
o.worldPos = worldPos;
|
|||
|
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
|
|||
|
return o;
|
|||
|
}
|
|||
|
fixed4 frag (v2f i) : SV_Target {
|
|||
|
fixed4 c = tex2D(_MainTex, i.uv);
|
|||
|
clip (c.a - _Cutoff);
|
|||
|
SHADOW_CASTER_FRAGMENT(i)
|
|||
|
}
|
|||
|
ENDCG
|
|||
|
}
|
|||
|
}
|
|||
|
CustomEditor "FlowToggleShaderGui"
|
|||
|
Fallback "Zhanyou/Character/NPC"
|
|||
|
}
|