Shader "Hidden/SimpleGaussianBlur" { Properties { _MainTex ("Texture", 2D) = "white" {} _BlurSize ("Blur Size", Float) = 1 } SubShader { Tags { "RenderType"="Opaque" } Pass { ZTest Always Cull Off ZWrite Off HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _MainTex; float4 _MainTex_TexelSize; float _BlurSize; float2 _Direction; // (1,0)=horizontal, (0,1)=vertical struct appdata { float4 vertex:POSITION; float2 uv:TEXCOORD0; }; struct v2f { float4 pos:SV_POSITION; float2 uv:TEXCOORD0; }; v2f vert(appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = v.uv; return o; } fixed4 frag(v2f i):SV_Target { float2 texel = _MainTex_TexelSize.xy * _BlurSize * _Direction; // 9-tap weights(近似高斯) fixed4 c = tex2D(_MainTex, i.uv) * 0.227027f; c += tex2D(_MainTex, i.uv + texel * 1.384615f) * 0.316216f; c += tex2D(_MainTex, i.uv - texel * 1.384615f) * 0.316216f; c += tex2D(_MainTex, i.uv + texel * 3.230769f) * 0.070270f; c += tex2D(_MainTex, i.uv - texel * 3.230769f) * 0.070270f; return c; } ENDHLSL } } }