my gray shader:
Shader "FragShader/Gray" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
Blend SrcAlpha OneMinusSrcAlpha
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _MainTex_ST;
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
} ;
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP,v.vertex); //顶点3D坐标转换为屏幕2D坐标
o.uv = TRANSFORM_TEX(v.texcoord,_MainTex); //计算tile和offset
return o;
}
float4 frag(v2f i) : COLOR
{
float4 texCol = tex2D(_MainTex,i.uv); //从uv坐标获取贴图对应位置的像素颜色
//to gray
float4 total= texCol[0] * 0.3 + texCol[1] * 0.4 + texCol[2]* 0.3;
texCol[0]=total;
texCol[1]=total;
texCol[2]=total;
float4 outp = texCol;
return outp;
}
ENDCG
}
}
FallBack "Diffuse"
}