把物体变灰代码分享
Shader "Shader_tex2D" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
//声明表面着色函数并设置光照模式为Lambert(漫反射)
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D(_MainTex, IN.uv_MainTex);//从纹理中采样
c = float4(Luminance(c));//设置灰度值
o.Albedo = c.rgb;//设置反射光颜色
o.Alpha = c.a;
}
ENDCG
}
Fallback "Diffuse"
} // shader