Shader "Spine/SkeletonColorMatrix" {
Properties {
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
_MainTex ("Texture to blend", 2D) = "black" {}
_ColorMatrixR("color matrix r",Vector) = (1,0,0,0)
_ColorMatrixG("color matrix g",Vector) = (0,1,0,0)
_ColorMatrixB("color matrix b",Vector) = (0,0,1,0)
_ColorMatrixA("color matrix a",Vector) = (0,0,0,1)
_OutLineAlpha("outline alpha",Range(0,1)) = 0
}
// 2 texture stage GPUs
SubShader {
Tags { "Queue"="Transparent+130" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 100
Cull Off
ZWrite Off
Blend One OneMinusSrcAlpha
Lighting Off
/*Pass {
Name "OutLine"
CGPROGRAM
//往上描边一个像素。
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
//fixed4 color1 : COLOR1;
};
sampler2D _MainTex;
float4x4 _ColorMatrix;
float4 _ColorMatrixR;
float4 _ColorMatrixG;
float4 _ColorMatrixB;
float4 _ColorMatrixA;
float _OutLineAlpha;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.vertex.y += 0.003;
o.texcoord = v.texcoord;
o.color = v.color;
//o.color1 = o.vertex;
return o;
}
fixed4 frag (v2f i) : COLOR
{
fixed4 col = tex2D(_MainTex, i.texcoord.xy);
col = fixed4(0,0,0,col.a*_OutLineAlpha);
return col;
}
ENDCG
}*/
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
//fixed4 color1 : COLOR1;
};
sampler2D _MainTex;
float4x4 _ColorMatrix;
float4 _ColorMatrixR;
float4 _ColorMatrixG;
float4 _ColorMatrixB;
float4 _ColorMatrixA;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
o.color = v.color;
//o.color1 = o.vertex;
return o;
}
fixed4 frag (v2f i) : COLOR
{
_ColorMatrix = float4x4(_ColorMatrixR,_ColorMatrixG,_ColorMatrixB,_ColorMatrixA);
fixed4 col = tex2D(_MainTex, i.texcoord.xy) ;
fixed4 color = i.color;
col *= color;
col = mul(_ColorMatrix,col);
//col.a *= step(0,i.color1.g);
return col;
}
ENDCG
}
/*Pass {
Name "Caster"
Tags { "LightMode"="ShadowCaster" }
Offset 1, 1
Fog { Mode Off }
ZWrite On
ZTest LEqual
Cull Off
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
};
uniform float4 _MainTex_ST;
v2f vert (appdata_base v) {
v2f o;
TRANSFER_SHADOW_CASTER(o)
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
uniform sampler2D _MainTex;
uniform fixed _Cutoff;
float4 frag (v2f i) : COLOR {
fixed4 texcol = tex2D(_MainTex, i.uv);
clip(texcol.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}*/
}
// 1 texture stage GPUs
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 100
Cull Off
ZWrite Off
//ZWrite On
Blend One OneMinusSrcAlpha
Lighting Off
Pass {
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
SkeletonRender.cs里的修改
效果图:
原图:
变色后:
最后附上一个颜色矩阵列表:
![](/qrcode.jpg)
using UnityEngine;
using System.Collections;
/// <summary>
/// <para>Author: zhaojun [email protected]</para>
/// <para>Date: $time$</para>
/// <para>$Id: ColorMatrixConfigs.cs 6294 2014-09-19 07:33:18Z zhaojun $</para>
/// </summary>
public class ColorMatrixConfigs{
/// <summary>
/// 灰色
/// </summary>
public static Vector4[] gray = new Vector4[4]{
new Vector4(0.2f, 0.7f, 0.1f, 0),
new Vector4(0.2f, 0.7f, 0.1f, 0),
new Vector4(0.2f, 0.7f, 0.1f, 0),
new Vector4(0,0, 0, 1),
};
/// <summary>
/// 石化
/// </summary>
public static Vector4[] stone = new Vector4[4]{
new Vector4(0.2f, 0.2f, 0.2f, 0),
new Vector4(0.2f, 0.2f, 0.2f, 0),
new Vector4(0.2f, 0.2f, 0.2f, 0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 放逐
/// </summary>
public static Vector4[] banish = new Vector4[4]{
new Vector4(0.27f, 0.27f, 0.27f, 0),
new Vector4(0.36f, 0.36f, 0.36f, 0),
new Vector4(0.3f, 0.3f, 0.3f, 0.1f),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 中毒
/// </summary>
public static Vector4[] poison = new Vector4[4]{
new Vector4(0.8f, 0f, 0f,0.08f),
new Vector4(0, 0.8f, 0, 0.2f),
new Vector4(0, 0, 0.8f, 0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 冰封
/// </summary>
public static Vector4[] frozen = new Vector4[4]{
new Vector4(0.8f, 0f, 0f,0f),
new Vector4(0, 0.8f, 0, 0f),
new Vector4(0, 0, 0.8f, 0.2f),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 冰霜
/// </summary>
public static Vector4[] ice = new Vector4[4]{
new Vector4(0.4f, 0.4f, 0.4f,0),
new Vector4(0.6f, 0.6f, 0.6f, 0),
new Vector4(0.75f, 0.75f, 0.75f, 0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// normal
/// </summary>
public static Vector4[] normal = new Vector4[4]{
new Vector4(1,0,0,0),
new Vector4(0,1,0,0),
new Vector4(0,0,1,0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 纯白色
/// </summary>
public static Vector4[] white = new Vector4[4]{
new Vector4(1,0,0,0.7f),
new Vector4(0,1,0,0.7f),
new Vector4(0,0,1,0.7f),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 金黄色
/// </summary>
public static Vector4[] gold = new Vector4[4]{
new Vector4(1,0,0,0.9f),
new Vector4(0,1,0,0.5f),
new Vector4(0,0,1,0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 纯黑色
/// </summary>
public static Vector4[] black = new Vector4[4]{
new Vector4(0,0,0,0),
new Vector4(0,0,0,0),
new Vector4(0,0,0,0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 高偏红
/// </summary>
public static Vector4[] red = new Vector4[4]{
new Vector4(2,2,2,0),
new Vector4(0,1,0,0),
new Vector4(0,0,1,0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 高亮蓝
/// </summary>
public static Vector4[] highBlue = new Vector4[4]{
new Vector4(0.5f,0,0,0),
new Vector4(0,1,0,0),
new Vector4(0,0,10,0),
new Vector4(0, 0, 0, 1),
};
/// <summary>
/// 根据特点返回颜色
///
/// 1灰色 2石头 3矾色 4中毒 5冰冻 6冰霜 7纯白 8金色 9黑色
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static Vector4[] getColorMatrix(int type)
{
Vector4[] color = normal;
switch(type)
{
case 1:
color = gray;
break;
case 2:
color = stone;
break;
case 3:
color = banish;
break;
case 4:
color = poison;
break;
case 5:
color = frozen;
break;
case 6:
color = ice;
break;
case 7:
color = white;
break;
case 8:
color = gold;
break;
case 9:
color = black;
break;
case 10:
color = red;
break;
default:
break;
}
return color;
}
}