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