Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.2 KiB

3 years ago
  1. Shader "Hidden/EfficientBlur"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. sampler2D _MainTex;
  10. half4 _MainTex_TexelSize;
  11. half4 _MainTex_ST;
  12. uniform half _Radius;
  13. struct v2f
  14. {
  15. half4 vertex : SV_POSITION;
  16. half4 texcoord : TEXCOORD0;
  17. };
  18. /*struct appdata
  19. {
  20. half4 vertex : POSITION;
  21. half2 texcoord: TEXCOORD0;
  22. }*/
  23. v2f vert(appdata_img v)
  24. {
  25. v2f o;
  26. o.vertex = UnityObjectToClipPos(v.vertex);
  27. half4 offset = half2(-0.5h, 0.5h).xxyy; //-x, -y, x, y
  28. offset *= _MainTex_TexelSize.xyxy;
  29. offset *= _Radius;
  30. o.texcoord = v.texcoord.xyxy + offset;
  31. return o;
  32. }
  33. half4 frag(v2f i) : SV_Target
  34. {
  35. // half4 o =
  36. // tex2D(_MainTex, i.texcoord.xw);
  37. // o += tex2D(_MainTex, i.texcoord.zw);
  38. // o += tex2D(_MainTex, i.texcoord.xy);
  39. // o += tex2D(_MainTex, i.texcoord.zy);
  40. // o /= 4.0;
  41. //Pray to the compiler god these will MAD
  42. half4 o =
  43. tex2D(_MainTex, i.texcoord.xw) / 4.0h;
  44. o += tex2D(_MainTex, i.texcoord.zw) / 4.0h;
  45. o += tex2D(_MainTex, i.texcoord.xy) / 4.0h;
  46. o += tex2D(_MainTex, i.texcoord.zy) / 4.0h;
  47. return o;
  48. }
  49. ENDCG
  50. SubShader
  51. {
  52. Cull Off ZWrite Off ZTest Always Blend Off
  53. Pass
  54. {
  55. CGPROGRAM
  56. #pragma vertex vert
  57. #pragma fragment frag
  58. ENDCG
  59. }
  60. Pass
  61. {
  62. CGPROGRAM
  63. //Crop before blur
  64. #pragma vertex vertCrop
  65. #pragma fragment frag
  66. half4 _CropRegion;
  67. half2 getNewUV(half2 oldUV)
  68. {
  69. return lerp(_CropRegion.xy, _CropRegion.zw, oldUV);
  70. }
  71. v2f vertCrop(appdata_img v)
  72. {
  73. v2f o = vert(v);
  74. o.texcoord.xy = getNewUV(o.texcoord.xy);
  75. o.texcoord.zw = getNewUV(o.texcoord.zw);
  76. return o;
  77. }
  78. ENDCG
  79. }
  80. }
  81. FallBack Off
  82. }