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 }
作者:大表哥的笔记
提示:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
如果觉得还有帮助的话,可以点一下右下角的【推荐】,希望能够持续的为大家带来好的技术文章!想跟我一起进步么?那就【关注】我吧。
如果对文章有任何问题,都可以再评论中留言,我会尽可能的答复您,谢谢你的阅读