Unity3D 灰度shader(改编自NGUI)

原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 QQ群:【Unity3D(AR/VR) 334163814】【Unity3D(游戏) 119706192】 本文链接地址: 灰度shader(改编自NGUI)

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

1.原图


2.修改shader

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

修改代码:

  1. struct v2f   
  2. {   
  3.     float4 vertex : SV_POSITION;   
  4.     half2 texcoord : TEXCOORD0;   
  5.     fixed4 color : COLOR;   
  6.     fixed gray : TEXCOORD1;   
  7. };   
  8. sampler2D _MainTex;   
  9. float4 _MainTex_ST;   
  10. v2f vert (appdata_t v)   
  11. {   
  12.     v2f o;   
  13.     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);   
  14.     o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);   
  15.     o.color = v.color;   
  16.     o.gray = dot(v.color, fixed4(1,1,1,0));   
  17.     return o;   
  18. }   
  19. fixed4 frag (v2f i) : COLOR   
  20. {   
  21.     fixed4 col;   
  22.     if (i.gray == 0)   
  23.     {   
  24.         col = tex2D(_MainTex, i.texcoord);   
  25.         col.rgb = dot(col.rgb, fixed3(.222,.707,.071));   
  26.         col.a = i.color.a;  
  27.     }   
  28.     else   
  29.     {   
  30.         col = tex2D(_MainTex, i.texcoord) * i.color;   
  31.     }   
  32.     return col;   
  33. }  

参考自: http://chengduyi.com/blog/?post=43

3.使用方法和效果。




版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值