2
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 その4。「Vignette(ビネット)」

Last updated at Posted at 2020-05-11

TwitterでアップしたVignette(ビネット)のコードを貼っておきます

Vignette.shader
Shader "ScreenPocket/ImageEffect/Vignette"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Power ( "Power", Float ) = 0
    }
    
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

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

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

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv.xy = v.uv;
                o.uv.zw = o.vertex.xy;
                return o;
            }

            sampler2D _MainTex;
            float _Power;

            fixed4 frag (v2f i) : SV_Target
            {
                half4 col = tex2D( _MainTex, i.uv.xy );
                float2 vp = (i.uv.zw);
                col.rgb -= dot(vp,vp) * _Power;
                return col;
            }
            ENDCG
        }
    }
}

頂点シェーダでImageEffectで使いやすい2つの座標情報で紹介したViewport座標を、o.uv.zwを介してFragmentShaderに渡し、Viewport座標xyの内積を取る(dot(vp,vp))ことで円形に暗くしています。
また、強さを_Powerで指定できるようにしておいたので、値を大きくすることでより暗く、負の値にすることでより明るくすることも可能です
※値を増やして暗くなるのが違和感ある人は -= を += に変更して下さい。

暗い方はよくあるビネットとして使えそうですし、明るい方も回想シーンなどで使えるかもですね。

2
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
2
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?