NGUI 可裁剪的灰度Shader

 1 Shader "Custom/Unlit - Transparent Colored Grayed (SoftClip)" 
 2 {
 3     Properties 
 4     {
 5         _MainTex ("Base (RGB)", 2D) = "white" {}
 6     }
 7     
 8     SubShader {
 9         LOD 200
10         
11         Tags
12         {
13             "Queue" = "Transparent"
14             "IgnoreProjector" = "True"
15             "RenderType" = "Transparent"
16         }
17         
18         pass
19         {
20             Cull Off
21             Lighting Off
22             ZWrite Off
23             
24             Offset -1, -1
25             Fog 
26             { 
27                 Mode Off 
28             }
29             ColorMask RGB
30             AlphaTest Greater .01
31             Blend SrcAlpha OneMinusSrcAlpha
32             ColorMaterial AmbientAndDiffuse
33             
34             CGPROGRAM
35             #pragma vertex vert
36             #pragma fragment frag
37             #include "UnityCG.cginc"
38             
39             sampler2D _MainTex;
40             float4 _MainTex_ST;
41             float2 _ClipSharpness = float2(20.0, 20.0);
42             
43             struct v2f
44             {
45                 float4 vertex : POSITION;
46                 float4  pos : SV_POSITION;
47                 float2  uv : TEXCOORD0;
48                 float2 worldPos : TEXCOORD1;
49             };
50             
51             v2f vert (appdata_base v)
52             {
53                 v2f o;
54                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
55                 o.uv = v.texcoord;
56                 o.worldPos = TRANSFORM_TEX(v.vertex.xy, _MainTex);
57                 return o;
58             };
59             
60             half4 frag (v2f i) : COLOR
61             {
62                 float2 factor = (float2(1.0, 1.0) - abs(i.worldPos)) * _ClipSharpness;
63                 half4 texcol = tex2D (_MainTex, i.uv);
64                 texcol.rgb = (texcol.r + texcol.g + texcol.b) / 3;
65                 texcol.a *= clamp( min(factor.x, factor.y), 0.0, 1.0);
66                 return texcol;
67             };
68             ENDCG
69         }
70     } 
71     FallBack "Diffuse"
72 }

 

转载于:https://www.cnblogs.com/dabiaoge/p/4202236.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值