鸟语天空
NGUI的UISprite增加灰度处理
post by:追风剑情 2015-12-3 14:23

一、修改Unlit - Transparent Colored.shader

Shader "Unlit/Transparent Colored"
{
	Properties
	{
		_MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
	}
	
	SubShader
	{
		LOD 100
 
		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		}
		
		Cull Off
		Lighting Off
		ZWrite Off
		Fog { Mode Off }
		Offset -1, -1
		Blend SrcAlpha OneMinusSrcAlpha
 
		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;
				};
	
				sampler2D _MainTex;
				float4 _MainTex_ST;
				
				v2f vert (appdata_t v)
				{
					v2f o;
					o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
					o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
					o.color = v.color;
					return o;
				}
				//修改此函数
				fixed4 frag (v2f i) : COLOR
				{
					fixed4 col = tex2D(_MainTex, i.texcoord);
					fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
					fixed4 col_grey = fixed4(grey, grey, grey, col.a);
					fixed g = step(i.color.r + i.color.g + i.color.b, 0.001);
					col = col * i.color * g + col_grey * (1 - g);
					return col;
				}
			ENDCG
		}
	}
}

运行效果

run.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容