SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Hidden/FastMobileBloom"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _BloomTex ("Bloom (RGB)", 2D) = "black" {}
  7.     }
  8. CGINCLUDE
  9. #include "UnityCG.cginc"
  10. uniform sampler2D _MainTex;
  11. uniform half4 _MainTex_TexelSize;
  12. uniform half4 _MainTex_ST;
  13.  
  14. uniform half2 _ThresholdParams;
  15. uniform half  _Spread;
  16.  
  17. uniform sampler2D _BloomTex;
  18. uniform half _BloomIntensity;
  19.  
  20. struct v2fCombineBloom
  21. {
  22.     float4 pos : SV_POSITION;
  23.     half2  uv  : TEXCOORD0;
  24. #if UNITY_UV_STARTS_AT_TOP
  25.     half2  uv2 : TEXCOORD1;
  26. #endif
  27. }; 
  28.  
  29. struct v2fBlurDown
  30. {
  31.     float4 pos  : SV_POSITION;
  32.     half2  uv0  : TEXCOORD0;
  33.     half4  uv12 : TEXCOORD1;
  34.     half4  uv34 : TEXCOORD2;
  35. };
  36.  
  37. struct v2fBlurUp
  38. {
  39.     float4 pos  : SV_POSITION;
  40.     half4  uv12 : TEXCOORD0;
  41.     half4  uv34 : TEXCOORD1;
  42.     half4  uv56 : TEXCOORD2;
  43.     half4  uv78 : TEXCOORD3;
  44. };
  45.  
  46. v2fBlurDown vertBlurDown(appdata_img v)
  47. {
  48.     v2fBlurDown o;
  49.     o.pos = UnityObjectToClipPos(v.vertex);
  50.     o.uv0 = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy, _MainTex_ST);
  51.     o.uv12.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 1.0h,  1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  52.     o.uv12.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2(-1.0h,  1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  53.     o.uv34.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2(-1.0h, -1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  54.     o.uv34.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 1.0h, -1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  55. return o;
  56. }
  57.  
  58. v2fBlurUp vertBlurUp(appdata_img v)
  59. {
  60.     v2fBlurUp o;
  61.     o.pos = UnityObjectToClipPos(v.vertex);
  62.     o.uv12.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 1.0h,  1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  63.     o.uv12.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2(-1.0h,  1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  64.     o.uv34.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2(-1.0h, -1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  65.     o.uv34.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 1.0h, -1.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  66.     o.uv56.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 0.0h,  2.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  67.     o.uv56.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 0.0h, -2.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  68.     o.uv78.xy = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2( 2.0h,  0.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  69.     o.uv78.zw = UnityStereoScreenSpaceUVAdjust(v.texcoord.xy + half2(-2.0h,  0.0h) * _MainTex_TexelSize.xy * _Spread, _MainTex_ST);
  70. return o;
  71. }
  72.  
  73. v2fCombineBloom vertCombineBloom(appdata_img v)
  74. {
  75.     v2fCombineBloom o;
  76.    
  77.     o.pos = UnityObjectToClipPos(v.vertex);
  78.     o.uv = UnityStereoScreenSpaceUVAdjust(v.texcoord, _MainTex_ST);
  79. #if UNITY_UV_STARTS_AT_TOP
  80.     o.uv2 = o.uv;
  81.     if (_MainTex_TexelSize.y < 0.0)
  82.         o.uv.y = 1.0 - o.uv.y;
  83. #endif
  84.  
  85. return o;
  86. }
  87.  
  88. fixed4 fragBlurDownFirstPass(v2fBlurDown i) : SV_Target
  89. {
  90.     fixed4 col0 = tex2D(_MainTex, i.uv0);
  91.     fixed4 col1 = tex2D(_MainTex, i.uv12.xy);
  92.     fixed4 col2 = tex2D(_MainTex, i.uv12.zw);
  93.     fixed4 col3 = tex2D(_MainTex, i.uv34.xy);
  94.     fixed4 col4 = tex2D(_MainTex, i.uv34.zw);
  95.  
  96.     fixed4 col = col0 + col1*0.25 + col2*0.25 + col3*0.25 + col4*0.25;
  97.     col = col * 0.5;
  98.     col = col + _ThresholdParams.y;
  99.  
  100.     col = max(col, 0.0);
  101. return col;
  102. }
  103.  
  104. fixed4 fragBlurDown(v2fBlurDown i) : SV_Target
  105. {
  106.     fixed4 col0 = tex2D(_MainTex, i.uv0);
  107.     fixed4 col1 = tex2D(_MainTex, i.uv12.xy);
  108.     fixed4 col2 = tex2D(_MainTex, i.uv12.zw);
  109.     fixed4 col3 = tex2D(_MainTex, i.uv34.xy);
  110.     fixed4 col4 = tex2D(_MainTex, i.uv34.zw);
  111.  
  112.     fixed4 col = col0 + col1*0.25 + col2*0.25 + col3*0.25 + col4*0.25;
  113.     col = col * 0.5;
  114. return col;
  115. }
  116.  
  117. #define oneSix     0.1666666
  118. #define oneThree   0.3333333
  119. fixed4 fragBlurUp(v2fBlurUp i) : SV_Target
  120. {
  121.     fixed4 col1 = tex2D(_MainTex, i.uv12.xy);
  122.     fixed4 col2 = tex2D(_MainTex, i.uv12.zw);
  123.     fixed4 col3 = tex2D(_MainTex, i.uv34.xy);
  124.     fixed4 col4 = tex2D(_MainTex, i.uv34.zw);
  125.     fixed4 col5 = tex2D(_MainTex, i.uv56.xy);
  126.     fixed4 col6 = tex2D(_MainTex, i.uv56.zw);
  127.     fixed4 col7 = tex2D(_MainTex, i.uv78.xy);
  128.     fixed4 col8 = tex2D(_MainTex, i.uv78.zw);
  129.  
  130.     fixed4 col = col1*oneThree + col2*oneThree + col3*oneThree + col4*oneThree + col5*oneSix + col6*oneSix + col7*oneSix + col8*oneSix;
  131.     //col = col * 0.5;
  132.  
  133. return col;
  134. }
  135.  
  136. fixed4 fragCombineBloom(v2fCombineBloom i) : SV_Target
  137. {
  138. #if UNITY_UV_STARTS_AT_TOP
  139.     fixed4 col = tex2D(_MainTex,  i.uv2);
  140.     return col + tex2D(_BloomTex, i.uv) * _BloomIntensity;
  141. #else
  142.     fixed4 col = tex2D(_MainTex,  i.uv);
  143.     return col + tex2D(_BloomTex, i.uv) * _BloomIntensity;
  144. #endif
  145. }
  146.  
  147. ENDCG
  148.     SubShader
  149.     {
  150.         Cull Off ZWrite Off ZTest Always
  151.  
  152.         //initial downscale and threshold
  153.         Pass
  154.         {
  155. CGPROGRAM
  156. #pragma vertex vertBlurDown
  157. #pragma fragment fragBlurDownFirstPass
  158. ENDCG
  159.         }
  160.  
  161.         //down pass
  162.         Pass
  163.         {
  164. CGPROGRAM
  165. #pragma vertex vertBlurDown
  166. #pragma fragment fragBlurDown
  167. ENDCG
  168.         }
  169.  
  170.         //up pass
  171.         Pass
  172.         {
  173. CGPROGRAM
  174. #pragma vertex vertBlurUp
  175. #pragma fragment fragBlurUp
  176. ENDCG
  177.         }
  178.  
  179.         //final bloom
  180.         Pass
  181.         {
  182. CGPROGRAM
  183. #pragma vertex vertCombineBloom
  184. #pragma fragment fragCombineBloom
  185. ENDCG
  186.         }
  187.     }
  188. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top