16
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity]Shaderでかっこよさげな(?)シーン遷移 ~その1~

Last updated at Posted at 2017-01-15

できるもの

1月-15-2017 15-25-47.gif
バトルシーンへの遷移の時に使えそう。
少なくとも一瞬でパッと切り替わるよりかはマシかなぁ?
(スクリプトから進行度合いの値を入れる必要があります。詳しくはここ)
(それが嫌なら_Time.yに演算を少し施して使うといいかもです。)

コード

Shader "Original/NewImageEffectShader 1"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		percent ("percent", Range(0, 1)) = 0.5
	}
	SubShader
	{
		// No culling or depth
		Cull Off ZWrite Off ZTest Always
		// 追加
        CGINCLUDE

        #define PI 3.14159

        float mod(float  a, float  b) { return a-b*floor(a/b); } 
        uniform float percent;
        ENDCG

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = v.uv;
				return o;
			}
			
			sampler2D _MainTex;

			fixed4 frag (v2f i) : SV_Target
			{
				fixed4 col = tex2D(_MainTex, i.uv);

				float2 r = 2.0 * (i.uv - 0.5);
                float aspectRatio = _ScreenParams.x / _ScreenParams.y;
                r.x *= aspectRatio;
                fixed4 bgCol = fixed4(0.0, 0.0, 0.0, 0.0);

                float2 rm = float2(mod(r.x, 0.2) - 0.1, mod(r.y, 0.2) - 0.1);
                if(rm.x >= 0 && rm.y >= 0){
                	if(percent / 5 > rm.x){
                		col = bgCol;
                	}
                }
                if(rm.x < 0 && rm.y < 0){
                	if(percent / 5 > rm.x + 0.1){
                		col = bgCol;
                	}
                }
                if(rm.x < 0 && rm.y >= 0){
                	if(percent / 5 >= -rm.x + 0.1){
                		col = bgCol;
                	}
                }
                if(rm.x >= 0 && rm.y < 0){
                	if(percent / 5 >= -rm.x + 0.2){
                		col = bgCol;
                	}
                }

				return col;
			}
			ENDCG
		}
	}
}

仕組み

x座標とy座標を0.2で割った余りを考えそのあと愚直に場合分けをしています。

16
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?