首页 > 其他 > 详细

NGUI 可裁剪的灰度Shader

时间:2015-01-04 21:08:12      阅读:396      评论:0      收藏:0      [点我收藏+]
 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 }

 

NGUI 可裁剪的灰度Shader

原文:http://www.cnblogs.com/dabiaoge/p/4202236.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!