uitexture实现新手引导遮罩等

今天看了雨松momo的,http://www.xuanyusong.com/archives/4408。在ugui下实现新手引导的遮罩效果。将点击位置,及ui的宽高最大值传递给shader显示遮罩。

顺手在ngui里实现了。shader如下:

Shader "Unlit/Transparent Colored Cycle"
{
	Properties
	{
		_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
		_Grey("Luminance Factor",Range(0,1))=0
      _Center("Center", vector) = (0, 0, 0, 0)
      _Silder ("_Silder", Range (0,1000)) = 1000 // sliders
	}
	
	SubShader
	{
		LOD 100

		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		    "RenderTarget" = "oriented"
		}
		
		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;
				fixed grey:TEXCOORD1;
float4 worldPosition : TEXCOORD2;
			};
	
			sampler2D _MainTex;
			float4 _MainTex_ST;
		    fixed _Grey;

			//-------------------add----------------------
            float _Silder;
            float2 _Center;
            //-------------------add----------------------
				
			v2f vert (appdata_t v)
			{
				v2f o;
				o.worldPosition=v.vertex;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.texcoord = v.texcoord;
				o.color = v.color;
			    o.grey=dot(v.color,fixed4(1,1,1,0));
				return o;
			}
				
			fixed4 frag (v2f i) : COLOR
			{
				fixed4 col;
				col = tex2D(_MainTex, i.texcoord);
				
			
				if(i.grey==0){
				 fixed3 grey= Luminance(col.rgb);
				 col.rgb=lerp(grey,col.rgb,_Grey);
				col.a=col.a*i.color.a;
				 }
				else col=col*i.color;
					//-------------------add----------------------
               	col.a*=(distance(i.worldPosition.xy,_Center.xy) > _Silder);
               	col.rgb*= col.a;
               	//-------------------add----------------------
				
				return col;
			}
			ENDCG
		}
	}

	SubShader
	{
		LOD 100

		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		}
		
		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Offset -1, -1
			ColorMask RGB
			Blend SrcAlpha OneMinusSrcAlpha
			ColorMaterial AmbientAndDiffuse
			
			SetTexture [_MainTex]
			{
				Combine Texture * Primary
			}
		}
	}
}

ps:友情附送,灰度效果,及灰度与原图的插值控制,从而实现灰度效果下的低彩效果(参见王者荣耀英雄卡片)。

新建一个材质,选择该shader后,给uitexture.uitexture获得material后,设置参数,如果无效果很正常,记得MarkAsChanged();试试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值