[UnityShader]去色效果

参考链接:http://www.xiaobao1993.com/373.html


去色shader:

Shader "Custom/Gray" {
	Properties 
	{
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}    
    SubShader     
    {    
        Pass{  
        CGPROGRAM    
        #pragma vertex vert    
        #pragma fragment frag    
        #include "UnityCG.cginc" 
		
		sampler2D _MainTex;

        struct vertexOutput {    
        float4 pos : SV_POSITION;    
        float4 tex : TEXCOORD0;    
        };    
        vertexOutput vert(appdata_full input)    
        {    
            vertexOutput output;    
            output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
			output.tex = input.texcoord;        
            return output;    
        }    
        float4 frag(vertexOutput input) : COLOR    
        {
			float4 col = tex2D(_MainTex, input.tex);
			//参考UnityCG.cginc中的Luminance
			float grey = dot(col.rgb, fixed3(0.22, 0.707, 0.071));
			col.rgb = float3(grey, grey, grey);     
            return col;    
        }    
        ENDCG}     
    }    
    //如果以上SubShader渲染失败则回滚采用Diffuse    
    FallBack "Diffuse"    
} 

前后对比图:

[UnityShader]去色效果_第1张图片

[UnityShader]去色效果_第2张图片

你可能感兴趣的:(shader,去色)