Home>

Normal picture:

shader code:

shader "custom/gaosimohu"
{
 properties
 {
 _maintex ("texture", 2d)="white" {}
 _blursize ("blur size", float)=1.0
 }
 subshader
 {
 ztest always
 cull off
 zwrite off
 cginclude //This can make other pass blocks available,Instead of writing in both passes, reducing the number of writes
 sampler2d _maintex;
 half4 _maintex_texelsize;
 float _blursize;
 struct v2f {
  float4 pos:sv_position;
  half2 uv [5]:texcoord0;
 };
 fixed4 fragblur (v2f i):sv_target {
  float weight [3]={
  0.4026,  0.2442,  0.0545
  };
  fixed3 sum=tex2d (_maintex, i.uv [0]). rgb * weight [0];
  for (int it=1;it<3;it ++) {
  sum +=tex2d (_maintex, i.uv [it]). rgb * weight [it];
  sum +=tex2d (_maintex, i.uv [2 * it]). rgb * weight [it];
  }
  return fixed4 (sum, 1.0);
 }
 endcg
 pass {
  name "gaussian_blur_vertical" //The unique name of this pass,Can be called elsewhere,usepass + name
  cgprogram
  #pragma vertex vertlurvertical
  #pragma fragment fragblur
  #include "unitycg.cginc"
  v2f vertlurvertical (appdata_img v) {
  v2f o;
  o.pos=unityobjecttoclippos (v.vertex);
  half2 uv=v.texcoord;
  o.uv [0]=uv;
  o.uv [1]=uv + float2 (0.0, _maintex_texelsize.y * 1.0) * _blursize;
  o.uv [2]=uv-float2 (0.0, _maintex_texelsize.y * 1.0) * _blursize;
  o.uv [3]=uv + float2 (0.0, _maintex_texelsize.y * 2.0) * _blursize;
  o.uv [4]=uv-float2 (0.0, _maintex_texelsize.y * 2.0) * _blursize;
  return o;
  }
  endcg
 }
 pass {
  name "gaussian_blur_horizontal"
  cgprogram
  #pragma vertex vertlurhorizontal
  #pragma fragment fragblur
  #include "unitycg.cginc"
  v2f vertlurhorizontal (appdata_img v) {
  v2f o;
  o.pos=unityobjecttoclippos (v.vertex);
  half2 uv=v.texcoord;
  o.uv [0]=uv;
  o.uv [1]=uv + float2 (0.0, _maintex_texelsize.x * 1.0) * _blursize;
  o.uv [2]=uv-float2 (0.0, _maintex_texelsize.x * 1.0) * _blursize;
  o.uv [3]=uv + float2 (0.0, _maintex_texelsize.x * 2.0) * _blursize;
  o.uv [4]=uv-float2 (0.0, _maintex_texelsize.x * 2.0) * _blursize;
  return o;
  }
  endcg
 }
 }
}

Adjust the _blursize to see the effect

c
  • Previous Image Gaussian Blur effect of Unity3D UGUI special effects
  • Next UnityShader3 achieves 2D stroke effect