[Unity3D] [NGUI] to select an icon (highlighted or ashing)
NGUIDiscussion group: 333417608
Demand
Click on the monster portrait, portrait. (restrictions: highlight value only)
Method
Copy the Unlit - Transparent Colored.shader, modify(Finally, a complete shader)
Shader "Unlit/Transparent Colored"
Instead of
Shader "Unlit/Transparent Colored (Bright)"
2,
Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {} }
Instead of
Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {} _Bright("Brightness", Float) = 2 }
3,
sampler2D _MainTex; float4 _MainTex_ST;
Instead of
sampler2D _MainTex; float4 _MainTex_ST; float _Bright;
4,
fixed4 frag (v2f i) : COLOR { fixed4 col = tex2D(_MainTex, i.texcoord) * i.color; return col; }
Instead of
fixed4 frag (v2f i) : COLOR { fixed4 col = tex2D(_MainTex, i.texcoord) * i.color; col.rgb = _Bright * col.rgb; return col; }
5, Save the name for the Unlit - Transparent Colored (Bright).shader
Create a new Atlas
ReplicationAtlas and Material, pictured above is Wooden Atlas 1 (two is respectively Atlas and Material)
Material Atlas Wooden Atlas 1Designated asWooden Atlas 1
Revise the new Material
Increasing the brightness
Can be modified Brightness (Note: the modified window may not immediately display effect, need to refresh force corresponding to the Panel)
Application
The code which, when using the corresponding sprite atlas specified for the new atlas.
Effect
On the left is the highlighted icon. On the right is the ashing.
With complete Shader
Highlight
Shader "Unlit/Transparent Colored (Bright)" { Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {} _Bright("Brightness", Float) = 2 } 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; float _Bright; 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) * i.color; col.rgb = _Bright * col.rgb; 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 AlphaTest Greater .01 Blend SrcAlpha OneMinusSrcAlpha ColorMaterial AmbientAndDiffuse SetTexture [_MainTex] { Combine Texture * Primary } } } }
Ashing
Shader "Unlit/Transparent Colored (Gray)" { Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {} } 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) * i.color; col.rgb = dot(col.rgb, fixed3(.222,.707,.071)); 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 AlphaTest Greater .01 Blend SrcAlpha OneMinusSrcAlpha ColorMaterial AmbientAndDiffuse SetTexture [_MainTex] { Combine Texture * Primary } } } }
Posted by Louis at February 26, 2014 - 10:17 PM
'Unity3D > NGUI' 카테고리의 다른 글
[펌] NGUI와 BMFont를 이용한 데미지(숫자) 폰트 만들기 (0) | 2015.10.21 |
---|---|
NGUI UISprite 회색처리하기 / 강조처리하기 (0) | 2015.07.15 |
[NGUI] 스크롤뷰 재사용 (0) | 2015.06.24 |
[Unity3D] [NGUI] how to set up Atlas Texture (0) | 2015.06.17 |
유니티 이미지 최적화 (0) | 2015.06.17 |