Skip to content

Instantly share code, notes, and snippets.

@wotakuro
Created May 22, 2018 02:44
Show Gist options
  • Save wotakuro/4052c3b00c274cc34ad0a6a088123382 to your computer and use it in GitHub Desktop.
Save wotakuro/4052c3b00c274cc34ad0a6a088123382 to your computer and use it in GitHub Desktop.
適当に作った 出現エフェクト用 Shader
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "App/Appear"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Height("_Height",Float) = 1.0
_AppearTime ("_AppearTime", Range(0.0,1.0)) = 1.0 // sliders
_AppearColor ("_AppearColor", Color) = (.34, .85, .92, 1) // color
}
SubShader
{
// No culling or depth
Cull Off ZWrite On ZTest LEqual
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};\
struct v2f
{
float2 uv : TEXCOORD0;
float2 originpos:TECOORD1;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
fixed _AppearTime;
half _Height;
fixed4 _AppearColor;
v2f vert (appdata v)
{
v2f o;
half timeFirst = clamp(_AppearTime * 3.0 , 0.0 , 1.0);
half timeSecond = clamp(_AppearTime * 2.0 , 0.0 , 1.0);
half param = timeFirst - timeSecond;
o.originpos = float2( v.vertex.x , abs( v.vertex.y) );
v.vertex.y = clamp(v.vertex.y ,-_Height * timeFirst , _Height * timeFirst );
o.vertex = UnityObjectToClipPos(v.vertex );
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 blackCol = fixed4(0.0 , 0.0 , 0.0 , 0.0);
fixed4 texColor = tex2D(_MainTex, i.uv);
half time = _AppearTime + (1.0 - i.originpos.y) / _Height * 0.3;
half timeFirst = clamp( time * 4 , 0.0 , 1.0);
half timeSecond = clamp( ( time - 0.25) * 1.4 , 0.0 , 1.0);
fixed4 col = lerp( lerp( blackCol , _AppearColor ,timeFirst) ,texColor , timeSecond);
col.a = 1.0;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment