3
2

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(NotPostEffect)を作る

Posted at

615339e6e019b45e18884a5158b02ebf.gif

こんなん。
上のgifは、動画のデータにブラーshader貼り付けた感じです。

参考にしたサイト
http://gameprogramming.me.land.to/PDF/ESL516.pdf

qiita.hlsl

Shader "Unlit/Blur"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}

        Uoffset ("Uoffset", float) = 0.1

        Voffset ("Voffset", float) = 0.1

    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog
            
            #include "UnityCG.cginc"

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float Uoffset;
            float Voffset;
        
            
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

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

                float4 txl0=tex2D(_MainTex,i.uv+float2(0.0f,0.0f))*0.2f;
float4 txl1=tex2D(_MainTex,i.uv+float2(-Uoffset,-Voffset))*0.1f; float4 txl2=tex2D(_MainTex,i.uv+float2(0.0f,-Voffset))*0.1f; float4 txl3=tex2D(_MainTex,i.uv+float2(+Uoffset,-Voffset))*0.1f;
float4 txl4=tex2D(_MainTex,i.uv+float2(-Uoffset,0.0f))*0.1f; float4 txl5=tex2D(_MainTex,i.uv+float2(+Uoffset,0.0f))*0.1f;
float4 txl6=tex2D(_MainTex,i.uv+float2(-Uoffset,+Voffset))*0.1f; float4 txl7=tex2D(_MainTex,i.uv+float2(0.0f,+Voffset))*0.1f; float4 txl8=tex2D(_MainTex,i.uv+float2(+Uoffset,+Voffset))*0.1f;
float4 color1=txl0+txl1+txl2+txl3+txl4+txl5+txl6+txl7+txl8;

                // apply fog
               
                float s = _Time*30;
                return color1;

                }

                 
            
            ENDCG
        }
    }
}

こんな感じ。

やったことは、uv座標をぼかす感じ。
少しずらしたピクセル部分を全部足し合わせると上手くいきます。

ソーベルフィルターみたいな感じですね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?