19
21

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.

ブラーシェーダ作ってみた

Posted at

UnityのShaderLabでブラーシェーダ作ってみました。

ブラー(Blur)とは霞んで見える、ぼんやりと見えるなどを意味します。遠くのものやフォーカス(焦点)を当てていないオブジェクトの描画等で役立つと思います。

このブラーはエフェクトの基本であり、かなり応用が効く技術だと思っています。
例えば特殊な演出で、ぼんやりとオブジェクトを光らせたりするエフェクトはブラーシェーダと発光シェーダを組み合わせることで実装できます。

効果

noeffect.png

これが

effect.png

こんな感じになります。ブラーの強度はパラメータで指定が可能です。

実装

シェーダは以下のようになります。

BlurVF.shader
Shader "Custom/BlurVF" {
	Properties{
		_MainTex("Texture", 2D) = "white" {}
		_Diff("Diff", Range(0, 1)) = 0.1
	}

	SubShader{
		Pass{
			CGPROGRAM
			#pragma fragment frag
			#pragma vertex vert_img
			#include "UnityCG.cginc"
			sampler2D _MainTex;
			float _Diff;

			float4 frag(v2f_img i) :COLOR{
				float4 col = tex2D(_MainTex, i.uv - _Diff) + tex2D(_MainTex, i.uv + _Diff);
				return col / 2;
			}
			ENDCG
		}
	}
}

この実装では斜め右下方向分ズレるような効果が期待できます。

19
21
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
19
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?