2
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.0 KiB
Plaintext

2 years ago
Shader "Custom/Character"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
[PerRendererData]_MainTex ("Sprite Texture", 2D) = "white" {}
_Flash ("Flash", Range(0,1)) = 0.5
_FlashColor ("FlashColor", Color) = (1,1,1,1)
_Alpha ("_Alpha", Range(0,1)) = 1
_PaletteTex ("PaletteTex", 2D) = "white" {}
_ReplaceTex ("ReplaceTex", 2D) = "white" {}
[IntRange]_ReplaceType ("ReplaceType", Range(0,15)) = 0
_Direction ("Direction", Vector) = (0, 1, 0, 0)
_Intensity ("Intensity", Range(0.0, 1.0)) = 0
_UV ("UV", Vector) = (0, 0, 0, 0)//uv中心xyuv边界
}
SubShader
{
Tags
{
"Queue" = "Geometry"
}
Cull Off
ZWrite On
CGPROGRAM
#pragma surface surf Lambert addshadow fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
sampler2D _PaletteTex;
sampler2D _ReplaceTex;
fixed4 _Color;
fixed _Flash;
fixed4 _FlashColor;
fixed _Alpha;
fixed _ReplaceType;
fixed4 _Direction;
fixed _Intensity;
fixed4 _UV;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
fixed2 uv = IN.uv_MainTex;
//形变
if (length(_Direction) > 0 && _Intensity > 0)
{
fixed2 dir_center = IN.uv_MainTex - _UV.xy;
fixed2 dir = normalize(_Direction.xy);
fixed2 dir1 = dir.xy * _Intensity;
fixed2 dir2 = cross(fixed3(0, 0, 1), fixed3(dir, 0)).xy * _Intensity;
fixed2 offset1 = -dot(dir1, dir_center) * dir1;
fixed2 offset2 = dot(dir2, dir_center) * dir2;
uv = IN.uv_MainTex + offset1 + offset2;
}
//如果采样超出sprite范围 丢弃
fixed4 bound = fixed4(_UV.x - _UV.z, _UV.x + _UV.z, _UV.y - _UV.w, _UV.y + _UV.w);
if (uv.x < bound.x || uv.x > bound.y || uv.y < bound.z || uv.y > bound.w)
{
discard;
}
//采样
fixed4 c = tex2D(_MainTex, uv);
//颜色替换
fixed4 paletteColor = tex2D(_PaletteTex, c.br);
fixed4 replaceColor = tex2D(_ReplaceTex, fixed2(paletteColor.r, 1 - 0.01 - _ReplaceType * 0.0625));
if (any(replaceColor.rgb == fixed3(0, 0, 0)))
{
replaceColor = tex2D(_ReplaceTex, fixed2(paletteColor.r, 1 - 0.01));
}
fixed3 rgb = replaceColor.rgb;
//闪光
if (_Flash > 0)
{
rgb = rgb * (_Flash + 1) * _FlashColor;
}
o.Albedo = rgb * _Color;
o.Alpha = _Alpha * c.a;
clip(o.Alpha - 0.5);
}
ENDCG
}
FallBack "Diffuse"
}