Unity3D 灰度shader(改编自NGUI)

原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:119706192 本文链接地址: 灰度shader

废话不多说,直接图解流程:

1.原图


2.改动shader

打开NGUI自带的shader:(Unlit - Transparent Colored)

将代码A:

fixed4 frag (v2f i) : COLOR
{
	fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
	return col;
}
改为代码B:

fixed4 frag (v2f i) : COLOR
{
	fixed4 col;  
	if (i.color.r < 0.001)  
	{
		col = tex2D(_MainTex, i.texcoord);  
		float grey = dot(col.rgb, float3(0.299, 0.587, 0.114));  
		col.rgb = float3(grey, grey, grey); 
		col.a = i.color.a;
	}
	else  
	{  
		col = tex2D(_MainTex, i.texcoord) * i.color;  
	}  
	return col; 
}


參考自:http://blog.csdn.net/onerain88/article/details/12197277

3.用法和效果。




原文地址:https://www.cnblogs.com/mengfanrong/p/3816927.html