//感谢Dr.Dog提供序列算法//
Shader "ZX/UIFlow"
{
Properties
{
_Color ("Tint", Color) = (1,1,1,1)
_MainTex ("Sprite Texture", 2D) = "white" {}
_SpriteRowCount("RowCounts",float) = 0
_SpriteColumnCount("ColumnCounts",float) = 0
_Speed("AnimationSpeed",Range(0.01,10)) = 4
}
SubShader
{
Tags
{
"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
}
Cull Off
Lighting Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "UnityUI.cginc"
fixed4 _Color;
uniform sampler2D _MainTex;
uniform half _SpriteRowCount;
uniform half _SpriteColumnCount;
uniform half _Speed;
struct appdata_t
{
half4 vertex : POSITION;
half4 color : COLOR;
fixed2 texcoord : TEXCOORD0;
};
struct v2f
{
half4 vertex : SV_POSITION;
fixed4 color : COLOR;
fixed2 texcoord : TEXCOORD0;
float4 worldPosition : TEXCOORD2;
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.worldPosition = IN.vertex;
OUT.vertex = mul(UNITY_MATRIX_MVP, OUT.worldPosition);
OUT.texcoord = IN.texcoord;
return OUT;
}
fixed4 frag(v2f IN) : SV_Target
{
fixed totalSpriteCount = _SpriteRowCount * _SpriteColumnCount;
fixed rowAvgPercent = 1 / _SpriteColumnCount;
fixed columnAvgPercent = 1 / _SpriteRowCount;
fixed SpriteIndex = fmod(_Time.y * _Speed,totalSpriteCount);
SpriteIndex = floor(SpriteIndex);
fixed columnIndex = fmod(SpriteIndex,_SpriteColumnCount);
fixed rowIndex = SpriteIndex / _SpriteColumnCount;
rowIndex = _SpriteRowCount - 1 - floor(rowIndex);
fixed2 spriteUV = IN.texcoord;
spriteUV.x = (spriteUV.x + columnIndex) * rowAvgPercent;
spriteUV.y = (spriteUV.y + rowIndex) * columnAvgPercent;
fixed4 col = tex2D(_MainTex,spriteUV) * _Color;
return col;
}
ENDCG
}
}
}
Unity3d_Shader UGUI 播放序列帧
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一直没有写博客,最近项目要求添加序列帧动画,之前一直用NGUI,只做起来非常方便。刚接触UGU几天的时间,所以写的...
- 大纲 * VideoView播放网络视频、播放本地视频 * 实现边播边缓存 * 获取视频的第一帧图片作为封面 * ...
- 版本记录 前言 app中好的炫的动画可以让用户耳目一新,为产品增色不少,关于动画的实现我们可以用基本动画、关键帧动...