原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:【Unity3D(AR/VR) 334163814】【Unity3D(游戏) 119706192】 本文链接地址: 灰度shader(改编自NGUI)
废话不多说,直接图解流程:
1.原图
2.修改shader
打开NGUI自带的shader:(Unlit - Transparent Colored)
修改代码:
- struct v2f
- {
- float4 vertex : SV_POSITION;
- half2 texcoord : TEXCOORD0;
- fixed4 color : COLOR;
- fixed gray : TEXCOORD1;
- };
- 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;
- o.gray = dot(v.color, fixed4(1,1,1,0));
- return o;
- }
- fixed4 frag (v2f i) : COLOR
- {
- fixed4 col;
- if (i.gray == 0)
- {
- col = tex2D(_MainTex, i.texcoord);
- col.rgb = dot(col.rgb, fixed3(.222,.707,.071));
- col.a = i.color.a;
- }
- else
- {
- col = tex2D(_MainTex, i.texcoord) * i.color;
- }
- return col;
- }
参考自: http://chengduyi.com/blog/?post=43
3.使用方法和效果。
版权声明:本文为博主原创文章,未经博主允许不得转载。