最近搞了多张卡牌合成新卡牌后,新卡牌在放回背包后闪亮一下,没搞过Shader,但前人已经造好轮子,研究后,记录下,方便以后使用
效果预览
Shader如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| Shader "Unlit/Walk light" { Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {} _LightTex ("Light", 2D) = "black" {} } SubShader { LOD 200 Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } Pass { Cull Off Lighting Off ZWrite Off Fog { Mode Off } Offset -1, -1 Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc"
sampler2D _MainTex; sampler2D _LightTex; struct appdata_t { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; fixed4 color : COLOR; }; struct v2f { float4 vertex : SV_POSITION; half2 texcoord : TEXCOORD0; fixed4 color : COLOR; }; v2f o;
v2f vert (appdata_t v) { o.vertex = UnityObjectToClipPos(v.vertex); o.texcoord = v.texcoord; o.color = v.color; return o; } fixed4 frag (v2f IN) : COLOR { fixed4 main = tex2D(_MainTex, IN.texcoord); half lightU = IN.texcoord.x - frac(_Time.y); half2 lightUV = half2(lightU, IN.texcoord.y); fixed4 light = tex2D(_LightTex, lightUV); fixed4 col = main + main * light.a; return col * IN.color; } ENDCG } }
SubShader { LOD 100
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } Pass { Cull Off Lighting Off ZWrite Off Fog { Mode Off } Offset -1, -1 ColorMask RGB Blend SrcAlpha OneMinusSrcAlpha ColorMaterial AmbientAndDiffuse SetTexture [_MainTex] { Combine Texture * Primary } } } }
|
使用
- 新建一个Material,将Material的Shader选择为上面添加的Shader,如下图,看看就明白怎么设置:
- 新建UITexture,把上面创建的Material拖拽赋值给UITexture;
- 运行预览
代码控制就不写了,网上一大把。自己想想也能明白。
原因是在NGUI的UIScrollView中被剪裁掉了,只需要选择Clipping为:Constrain But Dont Clip即可。