LoginSignup
4
4

More than 5 years have passed since last update.

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

Posted at

できるもの

1月-21-2017 16-02-11.gif
バトルシーンへの遷移に使えそう。
少なくとも一瞬でパッと変わるよりはマシかなぁ?
この三角形っぽく見えるものが個人的には好きです。
(スクリプトから進行度合いの値を入れる必要があります。詳しくはここ)
(それが嫌なら_Time.yに演算を少し施して使うといいかもです。)

コード

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

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"
            uniform float percent;

            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);

                float hight = floor(r.y * 10) / 10 + 2;
                if(hight % 0.2 < 0.1){
                    if(r.x < hight + percent * 6 - 5){
                        col = bgCol;
                    }
                }else{
                    if(r.x > -hight - percent * 6 + 5){
                        col = bgCol;
                    }
                }

                return col;
            }
            ENDCG
        }
    }
}

仕組み

高さをfloor()で0.1単位に切り下げしてその値とpercentを使って黒をぬっています。

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