Super simple Shader to achieve blur effect

Today I will share an ultra-simple way to achieve the blur effect, the picture above:
Insert picture description here
Insert picture description here

The core code is just this sentence:
Note that the version above 3.0 can be used.
Insert picture description here
Insert picture description here
After sampling, offset sampling and then superimpose, the effect is similar to the following code:

float4 frag(v2f o):SV_TARGET{
	fixed4 color = tex2D(_MainTex,o.uv);//,float2(_Scale,_Scale),float2(_Scale,_Scale)
	
	float2 uv1= o.uv +float2(_Scale,_Scale);
	fixed4 color2 = tex2D(_MainTex,uv1);

	float2 uv2= o.uv -float2(_Scale,_Scale);
	fixed4 color3 = tex2D(_MainTex,uv2);

	return (color+color2+color3)/3;
}

The complete code below:

Shader "Custom/TestShader40" {
	Properties{
		_MainTex("MainTex",2D)="White"{}
		_Scale("Scale",Range(0,0.1))=0
	}
	SubShader{
		Tags { "RenderType"="Opaque" }
		Pass{
			CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#pragma target 3.0
				#include "Lighting.cginc"

				sampler2D  _MainTex;
				float4 _MainTex_ST;
				float _Scale;

				struct a2v{
					float4 pos:POSITION;
					float4 uv:TEXCOORD0;
				};

				struct v2f{
					float4 wPos:SV_POSITION;
					float2 uv:TEXCOORD0;
				};

				v2f vert(a2v v){
					v2f o;
					o.wPos = UnityObjectToClipPos(v.pos);
					o.uv=TRANSFORM_TEX(v.uv,_MainTex);

					return o;
				}

				float4 frag(v2f o):SV_TARGET{
					fixed4 color = tex2D(_MainTex,o.uv,float2(_Scale,_Scale),float2(_Scale,_Scale));

					return color;
				}
			ENDCG
		}
	}
}

Guess you like

Origin blog.csdn.net/ww1351646544/article/details/90732512
Recommended