SeparableWeightedBlur.shader 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/SeparableWeightedBlur" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. }
  6. CGINCLUDE
  7. #include "UnityCG.cginc"
  8. struct v2f {
  9. float4 pos : POSITION;
  10. float2 uv : TEXCOORD0;
  11. float4 uv01 : TEXCOORD1;
  12. float4 uv23 : TEXCOORD2;
  13. float4 uv45 : TEXCOORD3;
  14. };
  15. float4 offsets;
  16. sampler2D _MainTex;
  17. v2f vert (appdata_img v) {
  18. v2f o;
  19. o.pos = UnityObjectToClipPos(v.vertex);
  20. o.uv.xy = v.texcoord.xy;
  21. o.uv01 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1);
  22. o.uv23 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1) * 2.0;
  23. o.uv45 = v.texcoord.xyxy + offsets.xyxy * float4(1,1, -1,-1) * 3.0;
  24. return o;
  25. }
  26. // WEIGHTS are in the alpha channel ...
  27. float4 frag (v2f i) : COLOR {
  28. half4 color = float4 (0,0,0,0);
  29. half4 cocWeightSetA4;
  30. half3 cocWeightSetB3;
  31. cocWeightSetA4.x =(tex2D(_MainTex, i.uv.xy).a) * 0.40;
  32. cocWeightSetA4.y =(tex2D(_MainTex, i.uv01.xy).a) * 0.15;
  33. cocWeightSetA4.z =(tex2D(_MainTex, i.uv01.zw).a) * 0.15;
  34. cocWeightSetA4.w =(tex2D(_MainTex, i.uv23.xy).a) * 0.10;
  35. cocWeightSetB3.x =(tex2D(_MainTex, i.uv23.zw).a) * 0.10;
  36. cocWeightSetB3.y =(tex2D(_MainTex, i.uv45.xy).a) * 0.05;
  37. cocWeightSetB3.z =(tex2D(_MainTex, i.uv45.zw).a) * 0.05;
  38. half sum = dot(half4(1,1,1,1), cocWeightSetA4);
  39. sum += dot(half3(1,1,1), cocWeightSetB3);
  40. color += tex2D(_MainTex, i.uv.xy) * cocWeightSetA4.x;
  41. color += tex2D(_MainTex, i.uv01.xy) * cocWeightSetA4.y;
  42. color += tex2D(_MainTex, i.uv01.zw) * cocWeightSetA4.z;
  43. color += tex2D(_MainTex, i.uv23.xy) * cocWeightSetA4.w;
  44. color += tex2D(_MainTex, i.uv23.zw) * cocWeightSetB3.x;
  45. color += tex2D(_MainTex, i.uv45.xy) * cocWeightSetB3.y;
  46. color += tex2D(_MainTex, i.uv45.zw) * cocWeightSetB3.z;
  47. return color/sum;
  48. }
  49. ENDCG
  50. Subshader {
  51. Pass {
  52. ZTest Always Cull Off ZWrite Off
  53. Fog { Mode off }
  54. CGPROGRAM
  55. #pragma fragmentoption ARB_precision_hint_fastest
  56. #pragma vertex vert
  57. #pragma fragment frag
  58. ENDCG
  59. }
  60. }
  61. Fallback off
  62. } // shader