20
12

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のImage Effectでモザイクをかける

Posted at

UnityのImage Effectでモザイクをかけるためのshaderです。
_BlockNumプロパティでモザイクのブロックの数を変更できます。

Mosaic.shader
Shader "MyEffect/Mosaic"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_BlockNum ("Number Of Blocks", Float) = 10
	}
	SubShader
	{
		Pass
		{
			CGPROGRAM
			#pragma vertex vert_img
			#pragma fragment frag
			
			#include "UnityCG.cginc"
			
			sampler2D _MainTex;
			uint _BlockNum;

			fixed4 frag (v2f_img i) : COLOR
			{
				fixed2 f = floor(i.uv * _BlockNum);
				fixed size = 1.0 / _BlockNum;
				fixed2 lb = f / _BlockNum; // left bottom
				fixed2 lt = lb + fixed2(0.0, size); // left top
				fixed2 rb = lb + fixed2(size, 0.0); //right bottom
				fixed2 rt = lb + fixed2(size, size); // right top
				fixed4 c = (tex2D(_MainTex, lb) + tex2D(_MainTex, lt) + tex2D(_MainTex, rb) + tex2D(_MainTex, rt)) / 4.0;
				return c;
			}
			ENDCG
		}
	}
}

FrameBuffer.gif

20
12
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
20
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?