Last active
March 18, 2021 11:55
-
-
Save dotsquid/02fc938ed1cdd7baf306c38dc59051fb to your computer and use it in GitHub Desktop.
This file contains 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
[Header(Animation)] | |
_Velocity ("Velocity", Vector) = (0,0,0,0) | |
_Amplitude ("Amplitude", Vector) = (0,0,0,0) | |
_AlphaSpeed ("Alpha Speed", Float) = 0 | |
_AlphaPower ("Alpha Power", Float) = 1 |
This file contains 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
// Noise: | |
// r - horizontal movement phase shift | |
// g - alpha animation phase shift | |
// b - 1.0 - to suppress horizontal movement and alpha animation | |
// a - unused | |
out_t Vert(in_t IN) | |
{ | |
out_t OUT; | |
UNITY_SETUP_INSTANCE_ID (IN); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); | |
#ifdef UNITY_INSTANCING_ENABLED | |
IN.vertex.xy *= _Flip.xy; | |
#endif | |
OUT.vertex = UnityObjectToClipPos(IN.vertex); | |
OUT.texcoord = IN.texcoord; | |
OUT.noise = IN.color; | |
float2 sinval = sin(_Time.y * _Velocity + OUT.noise.r * 42.37); | |
sinval = sinval * sinval * 2.0 - 1.0; | |
float2 offset = _Amplitude * sinval * (1.0 - step(1.0, OUT.noise.b)); | |
OUT.vertex.xy += offset; | |
#ifdef PIXELSNAP_ON | |
OUT.vertex = UnityPixelSnap (OUT.vertex); | |
#endif | |
return OUT; | |
} |
This file contains 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
fixed4 Frag(out_t IN) : SV_Target | |
{ | |
fixed4 c = SampleSpriteTexture (IN.texcoord); | |
float offset = IN.noise.g * 37.42 + ceil(IN.texcoord.x * _MainTex_TexelSize.z) * 0.173 + ceil(IN.texcoord.y * _MainTex_TexelSize.w) * 0.631; | |
float alphaPhase = sin(_Time.y * _AlphaSpeed + offset) * 0.5 + 0.5; | |
float alpha = alphaPhase * (1.0 - step(1.0, IN.noise.b)); | |
alpha = 1.0 - pow(alpha, _AlphaPower); | |
c.a *= alpha; | |
c.rgb *= c.a; | |
return c; | |
} |
This file contains 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 "+SummerCatchers/Vegetation/CrownAnimation" | |
{ | |
Properties | |
{ | |
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} | |
[Header(Animation)] | |
_Velocity ("Velocity", Vector) = (0,0,0,0) | |
_Amplitude ("Amplitude", Vector) = (0,0,0,0) | |
_AlphaSpeed ("Alpha Speed", Float) = 0 | |
_AlphaPower ("Alpha Power", Float) = 1 | |
[Header(Sprite)] | |
_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 Frag | |
#pragma target 2.0 | |
#pragma multi_compile_instancing | |
#pragma multi_compile _ PIXELSNAP_ON | |
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA | |
#include "UnitySprites.cginc" | |
float4 _MainTex_TexelSize; | |
float2 _Velocity; | |
float2 _Amplitude; | |
float _AlphaSpeed; | |
float _AlphaPower; | |
struct in_t | |
{ | |
float4 vertex : POSITION; | |
float4 color : COLOR; | |
float2 texcoord : TEXCOORD0; | |
UNITY_VERTEX_INPUT_INSTANCE_ID | |
}; | |
struct out_t | |
{ | |
float4 vertex : SV_POSITION; | |
float2 texcoord : TEXCOORD0; | |
float4 noise : TEXCOORD1; | |
UNITY_VERTEX_OUTPUT_STEREO | |
}; | |
// Noise: | |
// r - horizontal movement phase shift | |
// g - alpha animation phase shift | |
// b - 1.0 - to suppress horizontal movement and alpha animation | |
// a - unused | |
out_t Vert(in_t IN) | |
{ | |
out_t OUT; | |
UNITY_SETUP_INSTANCE_ID (IN); | |
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); | |
#ifdef UNITY_INSTANCING_ENABLED | |
IN.vertex.xy *= _Flip.xy; | |
#endif | |
OUT.vertex = UnityObjectToClipPos(IN.vertex); | |
OUT.texcoord = IN.texcoord; | |
OUT.noise = IN.color; | |
float2 sinval = sin(_Time.y * _Velocity + OUT.noise.r * 42.37); | |
sinval = sinval * sinval * 2.0 - 1.0; | |
float2 offset = _Amplitude * sinval * (1.0 - step(1.0, OUT.noise.b)); | |
OUT.vertex.xy += offset; | |
#ifdef PIXELSNAP_ON | |
OUT.vertex = UnityPixelSnap (OUT.vertex); | |
#endif | |
return OUT; | |
} | |
fixed4 Frag(out_t IN) : SV_Target | |
{ | |
fixed4 c = SampleSpriteTexture (IN.texcoord); | |
float offset = IN.noise.g * 37.42 + ceil(IN.texcoord.x * _MainTex_TexelSize.z) * 0.173 + ceil(IN.texcoord.y * _MainTex_TexelSize.w) * 0.631; | |
float alphaPhase = sin(_Time.y * _AlphaSpeed + offset) * 0.5 + 0.5; | |
float alpha = alphaPhase * (1.0 - step(1.0, IN.noise.b)); | |
alpha = 1.0 - pow(alpha, _AlphaPower); | |
c.a *= alpha; | |
c.rgb *= c.a; | |
return c; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment