Created
October 29, 2018 14:11
-
-
Save mao-test-h/a6a5d18507d63a58d820b90f82f658e2 to your computer and use it in GitHub Desktop.
ドカベンロゴアニメーションシェーダー(書き直し版)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/Sprites/Dokaben" | |
{ | |
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 | |
// コマ落ちアニメーション(radians) | |
groupshared float Animation[16] = | |
{ | |
1.5707963267948966, | |
1.4660765716752369, | |
1.3613568165555772, | |
1.2566370614359172, | |
1.1519173063162575, | |
1.0471975511965979, | |
0.9424777960769379, | |
0.8377580409572781, | |
0.7330382858376184, | |
0.6283185307179586, | |
0.5235987755982989, | |
0.4188790204786392, | |
0.31415926535897926, | |
0.2094395102393195, | |
0.10471975511965975, | |
0, | |
}; | |
#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 | |
v2f vert (appdata_t IN) | |
{ | |
v2f OUT; | |
UNITY_SETUP_INSTANCE_ID (IN); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); | |
// ================================= | |
// 「_SinTime : -1~1」の値を0~1の範囲に正規化 | |
float normal = (_SinTime.w + 1) / 2; | |
// SinTimeの値を0~15の範囲にスケール。値を量子化することでアニメーションテーブルのIndexとして扱う。 | |
float rot = Animation[round(normal*15)]; | |
// 回転行列 | |
float sinX = sin(rot); | |
float cosX = cos(rot); | |
float2x2 rotationMatrix = float2x2(cosX, -sinX, sinX, cosX); | |
// 回転の適用。TextureSettingsに於けるPivotは「Bottom」を期待 | |
IN.vertex.yz = mul(rotationMatrix, IN.vertex.yz); | |
// ================================= | |
#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