UIBlurHQ.shader 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. /**
  3. * Gaussian Blur
  4. *
  5. * Author(s): Flying Banana
  6. * Date Created: 11-Nov-2015
  7. */
  8. /**
  9. * This is a three-pass blur shader. Quality-wise this gives the best result.
  10. */
  11. Shader "UI/Blur/UIBlurHQ" {
  12. Properties {
  13. _TintColor ("Tint Color", Color) = (1, 1, 1, 0.2)
  14. _Size ("Spacing", Range(0, 20)) = 5.0
  15. _Vibrancy ("Vibrancy", Range(0, 2)) = 0.2
  16. [HideInInspector]
  17. _StencilComp ("Stencil Comparison", Float) = 8
  18. [HideInInspector]
  19. _Stencil ("Stencil ID", Float) = 0
  20. [HideInInspector]
  21. _StencilOp ("Stencil Operation", Float) = 0
  22. [HideInInspector]
  23. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  24. [HideInInspector]
  25. _StencilReadMask ("Stencil Read Mask", Float) = 255
  26. _MainTex("Base(RGB)",2D) = "White"{}
  27. }
  28. Category {
  29. // We must be transparent, so other objects are drawn before this one.
  30. Tags {
  31. "Queue"="Transparent"
  32. "IgnoreProjector"="True"
  33. "RenderType"="Opaque"
  34. }
  35. Stencil {
  36. Ref [_Stencil]
  37. Comp [_StencilComp]
  38. Pass [_StencilOp]
  39. ReadMask [_StencilReadMask]
  40. WriteMask [_StencilWriteMask]
  41. }
  42. SubShader {
  43. GrabPass {
  44. Tags { "LightMode" = "Always" }
  45. }
  46. // Vertical blur
  47. Pass {
  48. Name "VERTICAL"
  49. Tags { "LightMode" = "Always" }
  50. CGPROGRAM
  51. #pragma vertex vert
  52. #pragma fragment frag
  53. #pragma fragmentoption ARB_precision_hint_fastest
  54. #include "UnityCG.cginc"
  55. struct appdata_t {
  56. float4 vertex : POSITION;
  57. float2 texcoord: TEXCOORD0;
  58. };
  59. struct v2f {
  60. float4 vertex : POSITION;
  61. float4 uvgrab : TEXCOORD0;
  62. };
  63. v2f vert (appdata_t v) {
  64. v2f o;
  65. o.vertex = UnityObjectToClipPos(v.vertex);
  66. #if UNITY_UV_STARTS_AT_TOP
  67. float scale = -1.0;
  68. #else
  69. float scale = 1.0;
  70. #endif
  71. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  72. o.uvgrab.zw = o.vertex.zw;
  73. return o;
  74. }
  75. sampler2D _GrabTexture;
  76. float4 _GrabTexture_TexelSize;
  77. float _Size;
  78. half4 frag( v2f i ) : COLOR {
  79. half4 sum = half4(0,0,0,0);
  80. #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely * _Size * 1.61, i.uvgrab.z, i.uvgrab.w))) * weight
  81. sum += GRABPIXEL(0.05, -4.0);
  82. sum += GRABPIXEL(0.09, -3.0);
  83. sum += GRABPIXEL(0.12, -2.0);
  84. sum += GRABPIXEL(0.15, -1.0);
  85. sum += GRABPIXEL(0.18, 0.0);
  86. sum += GRABPIXEL(0.15, +1.0);
  87. sum += GRABPIXEL(0.12, +2.0);
  88. sum += GRABPIXEL(0.09, +3.0);
  89. sum += GRABPIXEL(0.05, +4.0);
  90. return sum;
  91. }
  92. ENDCG
  93. }
  94. GrabPass {
  95. Tags { "LightMode" = "Always" }
  96. }
  97. // Horizontal blur
  98. Pass {
  99. Name "HORIZONTAL"
  100. Tags { "LightMode" = "Always" }
  101. CGPROGRAM
  102. #pragma vertex vert
  103. #pragma fragment frag
  104. #pragma fragmentoption ARB_precision_hint_fastest
  105. #include "UnityCG.cginc"
  106. struct appdata_t {
  107. float4 vertex : POSITION;
  108. float2 texcoord: TEXCOORD0;
  109. };
  110. struct v2f {
  111. float4 vertex : POSITION;
  112. float4 uvgrab : TEXCOORD0;
  113. };
  114. v2f vert (appdata_t v) {
  115. v2f o;
  116. o.vertex = UnityObjectToClipPos(v.vertex);
  117. #if UNITY_UV_STARTS_AT_TOP
  118. float scale = -1.0;
  119. #else
  120. float scale = 1.0;
  121. #endif
  122. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  123. o.uvgrab.zw = o.vertex.zw;
  124. return o;
  125. }
  126. sampler2D _GrabTexture;
  127. float4 _GrabTexture_TexelSize;
  128. float _Size;
  129. half4 frag( v2f i ) : COLOR {
  130. half4 sum = half4(0,0,0,0);
  131. #define GRABPIXEL(weight,kernelx) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx * _Size * 1.61, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
  132. sum += GRABPIXEL(0.05, -4.0);
  133. sum += GRABPIXEL(0.09, -3.0);
  134. sum += GRABPIXEL(0.12, -2.0);
  135. sum += GRABPIXEL(0.15, -1.0);
  136. sum += GRABPIXEL(0.18, 0.0);
  137. sum += GRABPIXEL(0.15, +1.0);
  138. sum += GRABPIXEL(0.12, +2.0);
  139. sum += GRABPIXEL(0.09, +3.0);
  140. sum += GRABPIXEL(0.05, +4.0);
  141. return sum;
  142. }
  143. ENDCG
  144. }
  145. GrabPass {
  146. Tags { "LightMode" = "Always" }
  147. }
  148. // Vertical blur
  149. Pass {
  150. Name "VERTICAL"
  151. Tags { "LightMode" = "Always" }
  152. CGPROGRAM
  153. #pragma vertex vert
  154. #pragma fragment frag
  155. #pragma fragmentoption ARB_precision_hint_fastest
  156. #include "UnityCG.cginc"
  157. struct appdata_t {
  158. float4 vertex : POSITION;
  159. float2 texcoord: TEXCOORD0;
  160. };
  161. struct v2f {
  162. float4 vertex : POSITION;
  163. float4 uvgrab : TEXCOORD0;
  164. };
  165. v2f vert (appdata_t v) {
  166. v2f o;
  167. o.vertex = UnityObjectToClipPos(v.vertex);
  168. #if UNITY_UV_STARTS_AT_TOP
  169. float scale = -1.0;
  170. #else
  171. float scale = 1.0;
  172. #endif
  173. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  174. o.uvgrab.zw = o.vertex.zw;
  175. return o;
  176. }
  177. sampler2D _GrabTexture;
  178. float4 _GrabTexture_TexelSize;
  179. float _Size;
  180. half4 frag( v2f i ) : COLOR {
  181. half4 sum = half4(0,0,0,0);
  182. #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely * _Size, i.uvgrab.z, i.uvgrab.w))) * weight
  183. sum += GRABPIXEL(0.05, -4.0);
  184. sum += GRABPIXEL(0.09, -3.0);
  185. sum += GRABPIXEL(0.12, -2.0);
  186. sum += GRABPIXEL(0.15, -1.0);
  187. sum += GRABPIXEL(0.18, 0.0);
  188. sum += GRABPIXEL(0.15, +1.0);
  189. sum += GRABPIXEL(0.12, +2.0);
  190. sum += GRABPIXEL(0.09, +3.0);
  191. sum += GRABPIXEL(0.05, +4.0);
  192. return sum;
  193. }
  194. ENDCG
  195. }
  196. GrabPass {
  197. Tags { "LightMode" = "Always" }
  198. }
  199. // Horizontal blur
  200. Pass {
  201. Name "HORIZONTAL"
  202. Tags { "LightMode" = "Always" }
  203. CGPROGRAM
  204. #pragma vertex vert
  205. #pragma fragment frag
  206. #pragma fragmentoption ARB_precision_hint_fastest
  207. #include "UnityCG.cginc"
  208. struct appdata_t {
  209. float4 vertex : POSITION;
  210. float2 texcoord: TEXCOORD0;
  211. };
  212. struct v2f {
  213. float4 vertex : POSITION;
  214. float4 uvgrab : TEXCOORD0;
  215. };
  216. v2f vert (appdata_t v) {
  217. v2f o;
  218. o.vertex = UnityObjectToClipPos(v.vertex);
  219. #if UNITY_UV_STARTS_AT_TOP
  220. float scale = -1.0;
  221. #else
  222. float scale = 1.0;
  223. #endif
  224. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  225. o.uvgrab.zw = o.vertex.zw;
  226. return o;
  227. }
  228. sampler2D _GrabTexture;
  229. float4 _GrabTexture_TexelSize;
  230. float _Size;
  231. half4 frag( v2f i ) : COLOR {
  232. half4 sum = half4(0,0,0,0);
  233. #define GRABPIXEL(weight,kernelx) tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx * _Size, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
  234. sum += GRABPIXEL(0.05, -4.0);
  235. sum += GRABPIXEL(0.09, -3.0);
  236. sum += GRABPIXEL(0.12, -2.0);
  237. sum += GRABPIXEL(0.15, -1.0);
  238. sum += GRABPIXEL(0.18, 0.0);
  239. sum += GRABPIXEL(0.15, +1.0);
  240. sum += GRABPIXEL(0.12, +2.0);
  241. sum += GRABPIXEL(0.09, +3.0);
  242. sum += GRABPIXEL(0.05, +4.0);
  243. return sum;
  244. }
  245. ENDCG
  246. }
  247. GrabPass {
  248. Tags { "LightMode" = "Always" }
  249. }
  250. // Vertical blur
  251. Pass {
  252. Name "VERTICAL"
  253. Tags { "LightMode" = "Always" }
  254. CGPROGRAM
  255. #pragma vertex vert
  256. #pragma fragment frag
  257. #pragma fragmentoption ARB_precision_hint_fastest
  258. #include "UnityCG.cginc"
  259. struct appdata_t {
  260. float4 vertex : POSITION;
  261. float2 texcoord: TEXCOORD0;
  262. };
  263. struct v2f {
  264. float4 vertex : POSITION;
  265. float4 uvgrab : TEXCOORD0;
  266. };
  267. v2f vert (appdata_t v) {
  268. v2f o;
  269. o.vertex = UnityObjectToClipPos(v.vertex);
  270. #if UNITY_UV_STARTS_AT_TOP
  271. float scale = -1.0;
  272. #else
  273. float scale = 1.0;
  274. #endif
  275. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  276. o.uvgrab.zw = o.vertex.zw;
  277. return o;
  278. }
  279. sampler2D _GrabTexture;
  280. float4 _GrabTexture_TexelSize;
  281. float _Size;
  282. half4 frag( v2f i ) : COLOR {
  283. half4 sum = half4(0,0,0,0);
  284. #define GRABPIXEL(weight,kernely) tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x, i.uvgrab.y + _GrabTexture_TexelSize.y * kernely * _Size * 0.2, i.uvgrab.z, i.uvgrab.w))) * weight
  285. sum += GRABPIXEL(0.05, -4.0);
  286. sum += GRABPIXEL(0.09, -3.0);
  287. sum += GRABPIXEL(0.12, -2.0);
  288. sum += GRABPIXEL(0.15, -1.0);
  289. sum += GRABPIXEL(0.18, 0.0);
  290. sum += GRABPIXEL(0.15, +1.0);
  291. sum += GRABPIXEL(0.12, +2.0);
  292. sum += GRABPIXEL(0.09, +3.0);
  293. sum += GRABPIXEL(0.05, +4.0);
  294. return sum;
  295. }
  296. ENDCG
  297. }
  298. GrabPass {
  299. Tags { "LightMode" = "Always" }
  300. }
  301. // Horizontal blur
  302. Pass {
  303. Name "HORIZONTAL"
  304. Tags { "LightMode" = "Always" }
  305. CGPROGRAM
  306. #pragma vertex vert
  307. #pragma fragment frag
  308. #pragma fragmentoption ARB_precision_hint_fastest
  309. #include "UnityCG.cginc"
  310. struct appdata_t {
  311. float4 vertex : POSITION;
  312. float2 texcoord: TEXCOORD0;
  313. };
  314. struct v2f {
  315. float4 vertex : POSITION;
  316. float4 uvgrab : TEXCOORD0;
  317. };
  318. v2f vert (appdata_t v) {
  319. v2f o;
  320. o.vertex = UnityObjectToClipPos(v.vertex);
  321. #if UNITY_UV_STARTS_AT_TOP
  322. float scale = -1.0;
  323. #else
  324. float scale = 1.0;
  325. #endif
  326. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  327. o.uvgrab.zw = o.vertex.zw;
  328. return o;
  329. }
  330. sampler2D _GrabTexture;
  331. float4 _GrabTexture_TexelSize;
  332. float _Size;
  333. half4 frag( v2f i ) : COLOR {
  334. half4 sum = half4(0,0,0,0);
  335. #define GRABPIXEL(weight,kernelx) tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(float4(i.uvgrab.x + _GrabTexture_TexelSize.x * kernelx * _Size * 0.2, i.uvgrab.y, i.uvgrab.z, i.uvgrab.w))) * weight
  336. sum += GRABPIXEL(0.05, -4.0);
  337. sum += GRABPIXEL(0.09, -3.0);
  338. sum += GRABPIXEL(0.12, -2.0);
  339. sum += GRABPIXEL(0.15, -1.0);
  340. sum += GRABPIXEL(0.18, 0.0);
  341. sum += GRABPIXEL(0.15, +1.0);
  342. sum += GRABPIXEL(0.12, +2.0);
  343. sum += GRABPIXEL(0.09, +3.0);
  344. sum += GRABPIXEL(0.05, +4.0);
  345. return sum;
  346. }
  347. ENDCG
  348. }
  349. // Distortion
  350. GrabPass {
  351. Tags { "LightMode" = "Always" }
  352. }
  353. Pass {
  354. Tags { "LightMode" = "Always" }
  355. CGPROGRAM
  356. #pragma vertex vert
  357. #pragma fragment frag
  358. #pragma fragmentoption ARB_precision_hint_fastest
  359. #include "UnityCG.cginc"
  360. struct appdata_t {
  361. float4 vertex : POSITION;
  362. float2 texcoord: TEXCOORD0;
  363. };
  364. struct v2f {
  365. float4 vertex : POSITION;
  366. float4 uvgrab : TEXCOORD0;
  367. };
  368. v2f vert (appdata_t v) {
  369. v2f o;
  370. o.vertex = UnityObjectToClipPos(v.vertex);
  371. #if UNITY_UV_STARTS_AT_TOP
  372. float scale = -1.0;
  373. #else
  374. float scale = 1.0;
  375. #endif
  376. o.uvgrab.xy = (float2(o.vertex.x, o.vertex.y*scale) + o.vertex.w) * 0.5;
  377. o.uvgrab.zw = o.vertex.zw;
  378. return o;
  379. }
  380. half4 _TintColor;
  381. float _Vibrancy;
  382. sampler2D _GrabTexture;
  383. float4 _GrabTexture_TexelSize;
  384. half4 frag( v2f i ) : COLOR {
  385. half4 col = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uvgrab));
  386. col.xyz *= 1 + _Vibrancy;
  387. col = lerp (col, _TintColor, _TintColor.w);
  388. return col;
  389. }
  390. ENDCG
  391. }
  392. }
  393. }
  394. }