8
8

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でかっこよさげな(?)シーン遷移 ~その4~

Last updated at Posted at 2017-01-29

#できるもの
1月-29-2017 12-13-24.gif
エリア・ステージ間の遷移に使えそう。
少なくとも一瞬でパッと変わるよりはマシかなぁ?
少しいじれば回想シーンなんかにも使えます
(スクリプトから進行度合いの値を入れる必要があります。詳しくはここ)
(それが嫌なら_Time.yに演算を少し施して使うといいかもです。)
#コード

Shader "Original/NewImageEffectShader 3"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		percent ("percent", Range(0.0, 1.0)) = 0 
	}
	SubShader
	{
		// No culling or depth
		Cull Off ZWrite Off ZTest Always
		CGINCLUDE
		int xor128(int b, int c){ 
		    int x=1234567 * b * c,y=362436036,z=521288629,w=886751 * (_Time.y % 128); 
	    	int t; 
    		t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); 
		} 
		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);
				i.uv.x++;
				i.uv.y++;
				i.uv *= 3;
				float rand = (float)xor128(i.uv.x * 100 + 1, i.uv.y * 100 + 1) % 10000 / 10000;
				col *= step(percent, rand);
				return col;
			}
			ENDCG
		}
	}
}

#仕組み
xor128という関数がランダムの関数なので%などを使い0~1の範囲にした後step関数で真っ黒の場所を作っています。
i.uvにかける値を変えればノイズの解像度を変えることができます。
#参考
すごい乱数生成アルゴリズム「xorshift」

8
8
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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?