1
1

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 3 years have passed since last update.

シンプルなImageEffect その8。VPOSを使った走査線

Posted at

Twitterにアップした走査線ImageEffectのシェーダコードを貼っておきます

ポイントは

  • VPOSを使っているので #pragma target 3.0が必要
  • _Sizeの値を調整する事で走査線の太さを変更できる(ただ、そんな機能必要かな??普通太さ1pxでは?)
  • 走査線は固定色で潰すのではなく、colorの2乗で明度を落としつつ彩度を上げるような合成にして滲みを表現してみた

って感じですかね。

ScanLine.shader
Shader "ScreenPocket/ImageEffect/ScanLine"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Size ("Size", Float) = 1
    }
    
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.0

            #include "UnityCG.cginc"

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
            };

            v2f vert (appdata v,
            out float4 outpos : SV_POSITION)
            {
                v2f o;
                o.uv.xy = v.uv;
                outpos = UnityObjectToClipPos(v.vertex);
                return o;
            }

            sampler2D _MainTex;
            float _Size;

            fixed4 frag (v2f i,
                UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
            {
                half4 col = tex2D( _MainTex, i.uv );
                float rate = frac(screenPos.y * ( 1.0 / _Size ));
                col = lerp( col, col*col, round( rate ) );
                return col;
            }
            ENDCG
        }
    }
}

線を固定の色(例えば黒)で塗りつぶしたい場合は col*col の部分を、fixed4(0,0,0,1) に置き換えてもらえば対応可能かと。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?