应用了纹理动画与跟随镜头旋转
Shader "Unlit/ImageSequenceAnimation"
{
Properties
{
_Color ("Color", Color) = (1, 1, 1, 1)
_MainTex ("Main Tex", 2D) = "white" {}
_HorizontalAmount ("Horizontal Amount", Float) = 4
_VerticalAmount ("Verticl Amount", Float) = 4
_Speed ("Speed", Float) = 30
}
SubShader
{
Tags { "Renderer" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "True" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
BlendOp Add
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include <UnityCG.cginc>
struct a2v
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
fixed4 _Color;
sampler2D _MainTex;
fixed4 _MainTex_ST;
float _HorizontalAmount;
float _VerticalAmount;
float _Speed;
v2f vert(a2v v)
{
v2f o;
float3 nor = normalize(mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1.0)));
float3 up = float3(0, 1, 0);
float3 right = normalize(cross(nor, up));
up = normalize(cross(right, nor));
float3 pos = v.vertex.x * right + v.vertex.y * up + v.vertex.z * nor;
o.pos = UnityObjectToClipPos(pos);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float time = floor(_Time.y * _Speed);
float row = floor(time / _HorizontalAmount);
float col = time - row * _HorizontalAmount;
half2 uv = i.uv + half2(col, -row);
uv.x /= _HorizontalAmount;
uv.y /= _VerticalAmount;
fixed4 color = tex2D(_MainTex, uv);
color.rgb *= _Color.rgb;
return color;
}
ENDCG
}
}
}