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