Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. Shader "Custom/Blur3"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex("Texture", 2D) = "white" {}
  6.         radius("radius", Range(0,30)) = 0
  7.         resolution("resolution", float) = 800
  8.     }
  9.         SubShader
  10.     {
  11.         Tags{ "RenderType" = "Opaque" }
  12.         LOD 100
  13.  
  14.         Pass
  15.     {
  16.         CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag      
  19. #include "UnityCG.cginc"
  20.  
  21.     struct appdata
  22.     {
  23.         float4 vertex : POSITION;
  24.         float2 uv : TEXCOORD0;
  25.     };
  26.  
  27.     struct v2f
  28.     {
  29.         float2 uv : TEXCOORD0;
  30.         float4 vertex : SV_POSITION;
  31.     };
  32.  
  33.     sampler2D _MainTex;
  34.     float4 _MainTex_ST;
  35.  
  36.     uniform  float resolution = 800;
  37.     uniform  float radius = 400;
  38.     uniform  float2 dir = float2(0,1);
  39.  
  40.     v2f vert(appdata v)
  41.     {
  42.         v2f o;
  43.         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  44.         o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  45.         return o;
  46.     }
  47.  
  48.     fixed4 frag(v2f i) : SV_Target
  49.     {
  50.         float4 sum = float4(0.0, 0.0, 0.0, 0.0);
  51.         float2 tc = i.uv;
  52.  
  53.         //blur radius in pixels
  54.         float blur = radius / resolution / 4;
  55.  
  56.         //the direction of our blur
  57.         //(1.0, 0.0) -> x-axis blur
  58.         //(0.0, 1.0) -> y-axis blur
  59.  
  60.         float hstep = 1;
  61.         float vstep = 1;
  62.  
  63.         sum += tex2D(_MainTex, float2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
  64.         sum += tex2D(_MainTex, float2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
  65.         sum += tex2D(_MainTex, float2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
  66.         sum += tex2D(_MainTex, float2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
  67.  
  68.         sum += tex2D(_MainTex, float2(tc.x, tc.y)) * 0.2270270270;
  69.  
  70.         sum += tex2D(_MainTex, float2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
  71.         sum += tex2D(_MainTex, float2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
  72.         sum += tex2D(_MainTex, float2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
  73.         sum += tex2D(_MainTex, float2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
  74.  
  75.         return float4(sum.rgb, 1);
  76.     }
  77.  
  78.         ENDCG
  79.     }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement