Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
Last active October 24, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mao-test-h/e17b04b36832112b401f7ddd8deeb48e to your computer and use it in GitHub Desktop.
Save mao-test-h/e17b04b36832112b401f7ddd8deeb48e to your computer and use it in GitHub Desktop.
ドカベンロゴアニメーションシェーダー ※Unity2017.2.0f3の"Sprites/Default"をベースに作成
// "Sprites/Default"のドカベンロゴアニメーション版
Shader "Dokaben/Sprites/Title-Animation"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment SpriteFrag
#pragma multi_compile_instancing
#pragma multi_compile _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#include "UnityCG.cginc"
#include "UnitySprites.cginc"
// ---------------------------------------------------
// vert
float4 _MainTex_TexelSize;
v2f vert (appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID (IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
// =================================
// コマ落ちアニメーション(※動き自体はほぼ目コピ)
float Animation[16] =
{
1,
0.9333333333333333,
0.8666666666666667,
0.8,
0.7333333333333333,
0.6666666666666666,
0.6,
0.5333333333333333,
0.4666666666666667,
0.4,
0.3333333333333333,
0.26666666666666666,
0.2,
0.13333333333333333,
0.06666666666666667,
0
};
// _SinTime0~1に正規化 →0~15(コマ数分)の範囲にスケールして要素数として扱う
float normal = (_SinTime.w+1)/2;
// X軸に90度回転
float rot = Animation[round(normal*15)]*radians(90);
// 回転行列
float sinX = sin(rot);
float cosX = cos(rot);
float2x2 rotationMatrix = float2x2(cosX, -sinX, sinX, cosX);
// 回転軸を下端にする為に先ずは原点の位置に下端が来るように移動→回転行列を掛けた後に元の位置に戻す。
IN.vertex.y += ((_MainTex_TexelSize.w/100)/2);
IN.vertex.yz = mul(rotationMatrix, IN.vertex.yz);
IN.vertex.y -= ((_MainTex_TexelSize.w/100)/2);
// =================================
#ifdef UNITY_INSTANCING_ENABLED
IN.vertex.xy *= _Flip.xy;
#endif
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color * _RendererColor;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap(OUT.vertex);
#endif
return OUT;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment