BlendForBloom.shader 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/BlendForBloom" {
  3. Properties {
  4. _MainTex ("Screen Blended", 2D) = "" {}
  5. _ColorBuffer ("Color", 2D) = "" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : SV_POSITION;
  11. float2 uv[2] : TEXCOORD0;
  12. };
  13. struct v2f_mt {
  14. float4 pos : SV_POSITION;
  15. float2 uv[5] : TEXCOORD0;
  16. };
  17. sampler2D _ColorBuffer;
  18. sampler2D _MainTex;
  19. half _Intensity;
  20. half4 _ColorBuffer_TexelSize;
  21. half4 _MainTex_TexelSize;
  22. v2f vert( appdata_img v ) {
  23. v2f o;
  24. o.pos = UnityObjectToClipPos(v.vertex);
  25. o.uv[0] = v.texcoord.xy;
  26. o.uv[1] = v.texcoord.xy;
  27. #if UNITY_UV_STARTS_AT_TOP
  28. if (_ColorBuffer_TexelSize.y < 0)
  29. o.uv[1].y = 1-o.uv[1].y;
  30. #endif
  31. return o;
  32. }
  33. v2f_mt vertMultiTap( appdata_img v ) {
  34. v2f_mt o;
  35. o.pos = UnityObjectToClipPos(v.vertex);
  36. o.uv[4] = v.texcoord.xy;
  37. o.uv[0] = v.texcoord.xy + _MainTex_TexelSize.xy * 0.5;
  38. o.uv[1] = v.texcoord.xy - _MainTex_TexelSize.xy * 0.5;
  39. o.uv[2] = v.texcoord.xy - _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
  40. o.uv[3] = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1) * 0.5;
  41. return o;
  42. }
  43. half4 fragScreen (v2f i) : SV_Target {
  44. half4 addedbloom = tex2D(_MainTex, i.uv[0].xy) * _Intensity;
  45. half4 screencolor = tex2D(_ColorBuffer, i.uv[1]);
  46. return 1-(1-addedbloom)*(1-screencolor);
  47. }
  48. half4 fragScreenCheap(v2f i) : SV_Target {
  49. half4 addedbloom = tex2D(_MainTex, i.uv[0].xy) * _Intensity;
  50. half4 screencolor = tex2D(_ColorBuffer, i.uv[1]);
  51. return 1-(1-addedbloom)*(1-screencolor);
  52. }
  53. half4 fragAdd (v2f i) : SV_Target {
  54. half4 addedbloom = tex2D(_MainTex, i.uv[0].xy);
  55. half4 screencolor = tex2D(_ColorBuffer, i.uv[1]);
  56. return _Intensity * addedbloom + screencolor;
  57. }
  58. half4 fragAddCheap (v2f i) : SV_Target {
  59. half4 addedbloom = tex2D(_MainTex, i.uv[0].xy);
  60. half4 screencolor = tex2D(_ColorBuffer, i.uv[1]);
  61. return _Intensity * addedbloom + screencolor;
  62. }
  63. half4 fragVignetteMul (v2f i) : SV_Target {
  64. return tex2D(_MainTex, i.uv[0].xy) * tex2D(_ColorBuffer, i.uv[0]);
  65. }
  66. half4 fragVignetteBlend (v2f i) : SV_Target {
  67. return half4(1,1,1, tex2D(_ColorBuffer, i.uv[0]).r);
  68. }
  69. half4 fragClear (v2f i) : SV_Target {
  70. return 0;
  71. }
  72. half4 fragAddOneOne (v2f i) : SV_Target {
  73. half4 addedColors = tex2D(_MainTex, i.uv[0].xy);
  74. return addedColors * _Intensity;
  75. }
  76. half4 frag1Tap (v2f i) : SV_Target {
  77. return tex2D(_MainTex, i.uv[0].xy);
  78. }
  79. half4 fragMultiTapMax (v2f_mt i) : SV_Target {
  80. half4 outColor = tex2D(_MainTex, i.uv[4].xy);
  81. outColor = max(outColor, tex2D(_MainTex, i.uv[0].xy));
  82. outColor = max(outColor, tex2D(_MainTex, i.uv[1].xy));
  83. outColor = max(outColor, tex2D(_MainTex, i.uv[2].xy));
  84. outColor = max(outColor, tex2D(_MainTex, i.uv[3].xy));
  85. return outColor;
  86. }
  87. half4 fragMultiTapBlur (v2f_mt i) : SV_Target {
  88. half4 outColor = 0;
  89. outColor += tex2D(_MainTex, i.uv[0].xy);
  90. outColor += tex2D(_MainTex, i.uv[1].xy);
  91. outColor += tex2D(_MainTex, i.uv[2].xy);
  92. outColor += tex2D(_MainTex, i.uv[3].xy);
  93. return outColor/4;
  94. }
  95. ENDCG
  96. Subshader {
  97. ZTest Always Cull Off ZWrite Off
  98. // 0: nicer & softer "screen" blend mode
  99. Pass {
  100. CGPROGRAM
  101. #pragma vertex vert
  102. #pragma fragment fragScreen
  103. ENDCG
  104. }
  105. // 1: "add" blend mode
  106. Pass {
  107. CGPROGRAM
  108. #pragma vertex vert
  109. #pragma fragment fragAdd
  110. ENDCG
  111. }
  112. // 2: several taps, maxxed
  113. Pass {
  114. CGPROGRAM
  115. #pragma vertex vertMultiTap
  116. #pragma fragment fragMultiTapMax
  117. ENDCG
  118. }
  119. // 3: vignette blending
  120. Pass {
  121. CGPROGRAM
  122. #pragma vertex vert
  123. #pragma fragment fragVignetteMul
  124. ENDCG
  125. }
  126. // 4: nicer & softer "screen" blend mode(cheapest)
  127. Pass {
  128. CGPROGRAM
  129. #pragma vertex vert
  130. #pragma fragment fragScreenCheap
  131. ENDCG
  132. }
  133. // 5: "add" blend mode (cheapest)
  134. Pass {
  135. CGPROGRAM
  136. #pragma vertex vert
  137. #pragma fragment fragAddCheap
  138. ENDCG
  139. }
  140. // 6: used for "stable" downsampling (blur)
  141. Pass {
  142. CGPROGRAM
  143. #pragma vertex vertMultiTap
  144. #pragma fragment fragMultiTapBlur
  145. ENDCG
  146. }
  147. // 7: vignette blending (blend to dest)
  148. Pass {
  149. Blend Zero SrcAlpha
  150. CGPROGRAM
  151. #pragma vertex vert
  152. #pragma fragment fragVignetteBlend
  153. ENDCG
  154. }
  155. // 8: clear
  156. Pass {
  157. CGPROGRAM
  158. #pragma vertex vert
  159. #pragma fragment fragClear
  160. ENDCG
  161. }
  162. // 9: fragAddOneOne
  163. Pass {
  164. Blend One One
  165. CGPROGRAM
  166. #pragma vertex vert
  167. #pragma fragment fragAddOneOne
  168. ENDCG
  169. }
  170. // 10: max blend
  171. Pass {
  172. BlendOp Max
  173. Blend One One
  174. CGPROGRAM
  175. #pragma vertex vert
  176. #pragma fragment frag1Tap
  177. ENDCG
  178. }
  179. }
  180. Fallback off
  181. } // shader