SeparableWeightedBlurDof34.shader 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/SeparableWeightedBlurDof34" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "" {}
  5. _TapMedium ("TapMedium (RGB)", 2D) = "" {}
  6. _TapLow ("TapLow (RGB)", 2D) = "" {}
  7. _TapHigh ("TapHigh (RGB)", 2D) = "" {}
  8. }
  9. CGINCLUDE
  10. #include "UnityCG.cginc"
  11. half4 offsets;
  12. half4 _Threshhold;
  13. sampler2D _MainTex;
  14. sampler2D _TapHigh;
  15. struct v2f {
  16. half4 pos : SV_POSITION;
  17. half2 uv : TEXCOORD0;
  18. half4 uv01 : TEXCOORD1;
  19. half4 uv23 : TEXCOORD2;
  20. half4 uv45 : TEXCOORD3;
  21. };
  22. struct v2fSingle {
  23. half4 pos : SV_POSITION;
  24. half2 uv : TEXCOORD0;
  25. };
  26. //
  27. // VERT PROGRAMS
  28. //
  29. v2f vert (appdata_img v) {
  30. v2f o;
  31. o.pos = UnityObjectToClipPos(v.vertex);
  32. o.uv.xy = v.texcoord.xy;
  33. o.uv01 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1);
  34. o.uv23 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 2.0;
  35. o.uv45 = v.texcoord.xyxy + offsets.xyxy * half4(1,1, -1,-1) * 3.0;
  36. return o;
  37. }
  38. v2fSingle vertSingleTex (appdata_img v) {
  39. v2fSingle o;
  40. o.pos = UnityObjectToClipPos(v.vertex);
  41. o.uv.xy = v.texcoord.xy;
  42. return o;
  43. }
  44. //
  45. // FRAG PROGRAMS
  46. //
  47. // mostly used for foreground, so more gaussian-like
  48. half4 fragBlurUnweighted (v2f i) : SV_Target {
  49. half4 blurredColor = half4 (0,0,0,0);
  50. half4 sampleA = tex2D(_MainTex, i.uv.xy);
  51. half4 sampleB = tex2D(_MainTex, i.uv01.xy);
  52. half4 sampleC = tex2D(_MainTex, i.uv01.zw);
  53. half4 sampleD = tex2D(_MainTex, i.uv23.xy);
  54. half4 sampleE = tex2D(_MainTex, i.uv23.zw);
  55. blurredColor += sampleA;
  56. blurredColor += sampleB;
  57. blurredColor += sampleC;
  58. blurredColor += sampleD;
  59. blurredColor += sampleE;
  60. blurredColor *= 0.2;
  61. blurredColor.a = max(UNITY_SAMPLE_1CHANNEL(_TapHigh, i.uv.xy), blurredColor.a);
  62. return blurredColor;
  63. }
  64. // used for background, so more bone curve-like
  65. half4 fragBlurWeighted (v2f i) : SV_Target {
  66. half4 blurredColor = half4 (0,0,0,0);
  67. half4 sampleA = tex2D(_MainTex, i.uv.xy);
  68. half4 sampleB = tex2D(_MainTex, i.uv01.xy);
  69. half4 sampleC = tex2D(_MainTex, i.uv01.zw);
  70. half4 sampleD = tex2D(_MainTex, i.uv23.xy);
  71. half4 sampleE = tex2D(_MainTex, i.uv23.zw);
  72. half sum = sampleA.a + dot (half4 (1.25, 1.25, 1.5, 1.5), half4 (sampleB.a,sampleC.a,sampleD.a,sampleE.a));
  73. sampleA.rgb = sampleA.rgb * sampleA.a;
  74. sampleB.rgb = sampleB.rgb * sampleB.a * 1.25;
  75. sampleC.rgb = sampleC.rgb * sampleC.a * 1.25;
  76. sampleD.rgb = sampleD.rgb * sampleD.a * 1.5;
  77. sampleE.rgb = sampleE.rgb * sampleE.a * 1.5;
  78. blurredColor += sampleA;
  79. blurredColor += sampleB;
  80. blurredColor += sampleC;
  81. blurredColor += sampleD;
  82. blurredColor += sampleE;
  83. blurredColor /= sum;
  84. half4 color = blurredColor;
  85. color.a = sampleA.a;
  86. return color;
  87. }
  88. half4 fragBlurDark (v2f i) : SV_Target {
  89. half4 blurredColor = half4 (0,0,0,0);
  90. half4 sampleA = tex2D(_MainTex, i.uv.xy);
  91. half4 sampleB = tex2D(_MainTex, i.uv01.xy);
  92. half4 sampleC = tex2D(_MainTex, i.uv01.zw);
  93. half4 sampleD = tex2D(_MainTex, i.uv23.xy);
  94. half4 sampleE = tex2D(_MainTex, i.uv23.zw);
  95. half sum = sampleA.a + dot (half4 (0.75, 0.75, 0.5, 0.5), half4 (sampleB.a,sampleC.a,sampleD.a,sampleE.a));
  96. sampleA.rgb = sampleA.rgb * sampleA.a;
  97. sampleB.rgb = sampleB.rgb * sampleB.a * 0.75;
  98. sampleC.rgb = sampleC.rgb * sampleC.a * 0.75;
  99. sampleD.rgb = sampleD.rgb * sampleD.a * 0.5;
  100. sampleE.rgb = sampleE.rgb * sampleE.a * 0.5;
  101. blurredColor += sampleA;
  102. blurredColor += sampleB;
  103. blurredColor += sampleC;
  104. blurredColor += sampleD;
  105. blurredColor += sampleE;
  106. blurredColor /= sum;
  107. half4 color = blurredColor;
  108. color.a = sampleA.a;
  109. return color;
  110. }
  111. // not used atm
  112. half4 fragBlurUnweightedDark (v2f i) : SV_Target {
  113. half4 blurredColor = half4 (0,0,0,0);
  114. half4 sampleA = tex2D(_MainTex, i.uv.xy);
  115. half4 sampleB = tex2D(_MainTex, i.uv01.xy);
  116. half4 sampleC = tex2D(_MainTex, i.uv01.zw);
  117. half4 sampleD = tex2D(_MainTex, i.uv23.xy);
  118. half4 sampleE = tex2D(_MainTex, i.uv23.zw);
  119. blurredColor += sampleA;
  120. blurredColor += sampleB * 0.75;
  121. blurredColor += sampleC * 0.75;
  122. blurredColor += sampleD * 0.5;
  123. blurredColor += sampleE * 0.5;
  124. blurredColor /= 3.5;
  125. blurredColor.a = max(UNITY_SAMPLE_1CHANNEL(_TapHigh, i.uv.xy), blurredColor.a);
  126. return blurredColor;
  127. }
  128. // fragMixMediumAndLowTap
  129. // happens before applying final coc/blur result to screen,
  130. // mixes defocus buffers of different resolutions / bluriness
  131. sampler2D _TapMedium;
  132. sampler2D _TapLow;
  133. half4 fragMixMediumAndLowTap (v2fSingle i) : SV_Target
  134. {
  135. half4 tapMedium = tex2D (_TapMedium, i.uv.xy);
  136. half4 tapLow = tex2D (_TapLow, i.uv.xy);
  137. tapMedium.a *= tapMedium.a;
  138. tapLow.rgb = lerp (tapMedium.rgb, tapLow.rgb, (tapMedium.a * tapMedium.a));
  139. return tapLow;
  140. }
  141. ENDCG
  142. Subshader {
  143. ZTest Always Cull Off ZWrite Off
  144. Pass {
  145. CGPROGRAM
  146. #pragma vertex vert
  147. #pragma fragment fragBlurWeighted
  148. ENDCG
  149. }
  150. Pass {
  151. CGPROGRAM
  152. #pragma vertex vert
  153. #pragma fragment fragBlurUnweighted
  154. ENDCG
  155. }
  156. // 2
  157. Pass {
  158. CGPROGRAM
  159. #pragma vertex vert
  160. #pragma fragment fragBlurUnweightedDark
  161. ENDCG
  162. }
  163. Pass {
  164. CGPROGRAM
  165. #pragma vertex vertSingleTex
  166. #pragma fragment fragMixMediumAndLowTap
  167. ENDCG
  168. }
  169. // 4
  170. Pass {
  171. CGPROGRAM
  172. #pragma vertex vert
  173. #pragma fragment fragBlurDark
  174. ENDCG
  175. }
  176. }
  177. Fallback off
  178. } // shader