1  Shader "Hidden/Dof/DepthOfFieldHdr" {
2     Properties {
3         _MainTex (
"-", 2D) = "black" {}
4         _FgOverlap (
"-", 2D) = "black" {}
5         _LowRez (
"-", 2D) = "black" {}
6     }
7
8     CGINCLUDE
9
10     #include
"UnityCG.cginc"
11     
12     
struct v2f {
13         float4 pos : SV_POSITION;
14         float2 uv : TEXCOORD0;
15         float2 uv1 : TEXCOORD1;
16     };
17
18     
struct v2fRadius {
19         float4 pos : SV_POSITION;
20         float2 uv : TEXCOORD0;
21         float4 uv1[
4] : TEXCOORD1;
22     };
23     
24     
struct v2fBlur {
25         float4 pos : SV_POSITION;
26         float2 uv : TEXCOORD0;
27         float4 uv01 : TEXCOORD1;
28         float4 uv23 : TEXCOORD2;
29         float4 uv45 : TEXCOORD3;
30         float4 uv67 : TEXCOORD4;
31         float4 uv89 : TEXCOORD5;
32     };
33     
34     uniform sampler2D _MainTex;
35     uniform sampler2D_float _CameraDepthTexture;
36     uniform sampler2D _FgOverlap;
37     uniform sampler2D _LowRez;
38     uniform float4 _CurveParams;
39     uniform float4 _MainTex_TexelSize;
40     uniform float4 _Offsets;
41
42     v2f vert( appdata_img v )
43     {
44         v2f o;
45         o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
46         o.uv1.xy = v.texcoord.xy;
47         o.uv.xy = v.texcoord.xy;
48         
49         #
if UNITY_UV_STARTS_AT_TOP
50         
if (_MainTex_TexelSize.y < 0)
51             o.uv.y =
1-o.uv.y;
52         #endif
53         
54         
return o;
55     }
56
57     v2f vertFlip( appdata_img v )
58     {
59         v2f o;
60         o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
61         o.uv1.xy = v.texcoord.xy;
62         o.uv.xy = v.texcoord.xy;
63         
64         #
if UNITY_UV_STARTS_AT_TOP
65         
if (_MainTex_TexelSize.y < 0)
66             o.uv.y =
1-o.uv.y;
67         
if (_MainTex_TexelSize.y < 0)
68             o.uv1.y =
1-o.uv1.y;
69         #endif
70         
71         
return o;
72     }
73
74     v2fBlur vertBlurPlusMinus (appdata_img v)
75     {
76         v2fBlur o;
77         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
78         o.uv.xy = v.texcoord.xy;
79         o.uv01 = v.texcoord.xyxy + _Offsets.xyxy * float4(
1,1, -1,-1) * _MainTex_TexelSize.xyxy / 6.0;
80         o.uv23 = v.texcoord.xyxy + _Offsets.xyxy * float4(
2,2, -2,-2) * _MainTex_TexelSize.xyxy / 6.0;
81         o.uv45 = v.texcoord.xyxy + _Offsets.xyxy * float4(
3,3, -3,-3) * _MainTex_TexelSize.xyxy / 6.0;
82         o.uv67 = v.texcoord.xyxy + _Offsets.xyxy * float4(
4,4, -4,-4) * _MainTex_TexelSize.xyxy / 6.0;
83         o.uv89 = v.texcoord.xyxy + _Offsets.xyxy * float4(
5,5, -5,-5) * _MainTex_TexelSize.xyxy / 6.0;
84         
return o;
85     }
86
87     #define SCATTER_OVERLAP_SMOOTH (-
0.265)
88
89     inline
float BokehWeightDisc(float4 theSample, float sampleDistance, float4 centerSample)
90     {
91         
return smoothstep(SCATTER_OVERLAP_SMOOTH, 0.0, theSample.a - centerSample.a*sampleDistance);
92     }
93
94     inline float2 BokehWeightDisc2(float4 sampleA, float4 sampleB, float2 sampleDistance2, float4 centerSample)
95     {
96         
return smoothstep(float2(SCATTER_OVERLAP_SMOOTH, SCATTER_OVERLAP_SMOOTH), float2(0.0,0.0), float2(sampleA.a, sampleB.a) - centerSample.aa*sampleDistance2); }
97             
98     
static const int SmallDiscKernelSamples = 12;
99     
static const float2 SmallDiscKernel[SmallDiscKernelSamples] =
100     {
101         float2(-
0.326212,-0.40581),
102         float2(-
0.840144,-0.07358),
103         float2(-
0.695914,0.457137),
104         float2(-
0.203345,0.620716),
105         float2(
0.96234,-0.194983),
106         float2(
0.473434,-0.480026),
107         float2(
0.519456,0.767022),
108         float2(
0.185461,-0.893124),
109         float2(
0.507431,0.064425),
110         float2(
0.89642,0.412458),
111         float2(-
0.32194,-0.932615),
112         float2(-
0.791559,-0.59771)
113     };
114
115     
static const int NumDiscSamples = 28;
116     
static const float3 DiscKernel[NumDiscSamples] =
117     {
118         float3(
0.62463,0.54337,0.82790),
119         float3(-
0.13414,-0.94488,0.95435),
120         float3(
0.38772,-0.43475,0.58253),
121         float3(
0.12126,-0.19282,0.22778),
122         float3(-
0.20388,0.11133,0.23230),
123         float3(
0.83114,-0.29218,0.88100),
124         float3(
0.10759,-0.57839,0.58831),
125         float3(
0.28285,0.79036,0.83945),
126         float3(-
0.36622,0.39516,0.53876),
127         float3(
0.75591,0.21916,0.78704),
128         float3(-
0.52610,0.02386,0.52664),
129         float3(-
0.88216,-0.24471,0.91547),
130         float3(-
0.48888,-0.29330,0.57011),
131         float3(
0.44014,-0.08558,0.44838),
132         float3(
0.21179,0.51373,0.55567),
133         float3(
0.05483,0.95701,0.95858),
134         float3(-
0.59001,-0.70509,0.91938),
135         float3(-
0.80065,0.24631,0.83768),
136         float3(-
0.19424,-0.18402,0.26757),
137         float3(-
0.43667,0.76751,0.88304),
138         float3(
0.21666,0.11602,0.24577),
139         float3(
0.15696,-0.85600,0.87027),
140         float3(-
0.75821,0.58363,0.95682),
141         float3(
0.99284,-0.02904,0.99327),
142         float3(-
0.22234,-0.57907,0.62029),
143         float3(
0.55052,-0.66984,0.86704),
144         float3(
0.46431,0.28115,0.54280),
145         float3(-
0.07214,0.60554,0.60982),
146     };
147
148     float4 fragBlurInsaneMQ (v2f i) : SV_Target
149     {
150         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
151         float4 sum = centerTap;
152         float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w;
153
154         
float sampleCount = max(centerTap.a * 0.25, _Offsets.z); // <- weighing with 0.25 looks nicer for small high freq spec
155         sum *= sampleCount;
156
157         
float weights = 0;
158         
159         
for(int l=0; l < NumDiscSamples; l++)
160         {
161             float2 sampleUV = i.uv1.xy + DiscKernel[l].xy * poissonScale.xy;
162             float4 sample0 = tex2D(_MainTex, sampleUV.xy);
163
164             
if( sample0.a > 0.0 )
165             {
166                 weights = BokehWeightDisc(sample0, DiscKernel[l].z, centerTap);
167                 sum += sample0 * weights;
168                 sampleCount += weights;
169             }
170         }
171         
172         float4 returnValue = sum / sampleCount;
173         returnValue.a = centerTap.a;
174
175         
return returnValue;
176     }
177
178     float4 fragBlurInsaneHQ (v2f i) : SV_Target
179     {
180         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
181         float4 sum = centerTap;
182         float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w;
183
184         
float sampleCount = max(centerTap.a * 0.25, _Offsets.z); // <- weighing with 0.25 looks nicer for small high freq spec
185         sum *= sampleCount;
186
187         float2 weights =
0;
188         
189         
for(int l=0; l < NumDiscSamples; l++)
190         {
191             float4 sampleUV = i.uv1.xyxy + DiscKernel[l].xyxy * poissonScale.xyxy / float4(
1.2,1.2,DiscKernel[l].zz);
192
193             float4 sample0 = tex2D(_MainTex, sampleUV.xy);
194             float4 sample1 = tex2D(_MainTex, sampleUV.zw);
195
196             
if( (sample0.a + sample1.a) > 0.0 )
197             {
198                 weights = BokehWeightDisc2(sample0, sample1, float2(DiscKernel[l].z/
1.2, 1.0), centerTap);
199                 sum += sample0 * weights.x + sample1 * weights.y;
200                 sampleCount += dot(weights,
1);
201             }
202         }
203         
204         float4 returnValue = sum / sampleCount;
205         returnValue.a = centerTap.a;
206
207         
return returnValue;
208     }
209
210     inline float4 BlendLowWithHighHQ(
float coc, float4 low, float4 high)
211     {
212         
float blend = smoothstep(0.65,0.85, coc);
213         
return lerp(low, high, blend);
214     }
215
216     inline float4 BlendLowWithHighMQ(
float coc, float4 low, float4 high)
217     {
218         
float blend = smoothstep(0.4,0.6, coc);
219         
return lerp(low, high, blend);
220     }
221
222     float4 fragBlurUpsampleCombineHQ (v2f i) : SV_Target
223     {
224         float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
225         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
226
227         float4 smallBlur = centerTap;
228         float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w ;
229                     
230         
float sampleCount = max(centerTap.a * 0.25, 0.1f); // <- weighing with 0.25 looks nicer for small high freq spec
231         smallBlur *= sampleCount;
232         
233         
for(int l=0; l < NumDiscSamples; l++)
234         {
235             float2 sampleUV = i.uv1.xy + DiscKernel[l].xy * poissonScale.xy;
236
237             float4 sample0 = tex2D(_MainTex, sampleUV);
238             
float weight0 = BokehWeightDisc(sample0, DiscKernel[l].z, centerTap);
239             smallBlur += sample0 * weight0; sampleCount += weight0;
240         }
241
242         smallBlur /= (sampleCount+
1e-5f);
243         smallBlur = BlendLowWithHighHQ(centerTap.a, smallBlur, bigBlur);
244
245         
return centerTap.a < 1e-2f ? centerTap : float4(smallBlur.rgb,centerTap.a);
246     }
247
248     float4 fragBlurUpsampleCombineMQ (v2f i) : SV_Target
249     {
250         float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
251         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
252
253         float4 smallBlur = centerTap;
254         float4 poissonScale = _MainTex_TexelSize.xyxy * centerTap.a * _Offsets.w ;
255                     
256         
float sampleCount = max(centerTap.a * 0.25, 0.1f); // <- weighing with 0.25 looks nicer for small high freq spec
257         smallBlur *= sampleCount;
258         
259         
for(int l=0; l < SmallDiscKernelSamples; l++)
260         {
261             float2 sampleUV = i.uv1.xy + SmallDiscKernel[l].xy * poissonScale.xy*
1.1;
262
263             float4 sample0 = tex2D(_MainTex, sampleUV);
264             
float weight0 = BokehWeightDisc(sample0, length(SmallDiscKernel[l].xy*1.1), centerTap);
265             smallBlur += sample0 * weight0; sampleCount += weight0;
266         }
267
268         smallBlur /= (sampleCount+
1e-5f);
269         
270         smallBlur = BlendLowWithHighMQ(centerTap.a, smallBlur, bigBlur);
271
272         
return centerTap.a < 1e-2f ? centerTap : float4(smallBlur.rgb,centerTap.a);
273     }
274
275     float4 fragBlurUpsampleCheap (v2f i) : SV_Target
276     {
277         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
278         float4 bigBlur = tex2D(_LowRez, i.uv1.xy);
279
280         
float fgCoc = tex2D(_FgOverlap, i.uv1.xy).a;
281         float4 smallBlur = lerp(centerTap, bigBlur, saturate( max(centerTap.a,fgCoc)*
8.0 ));
282
283         
return float4(smallBlur.rgb, centerTap.a);
284     }
285                                     
286     float4 fragBlurBox (v2f i) : SV_Target
287     {
288         
const int TAPS = 12;
289
290         float4 centerTap = tex2D(_MainTex, i.uv1.xy);
291
292         
// TODO: important ? breaks when HR blur is being used
293         
//centerTap.a = max(centerTap.a, 0.1f);
294
295         
float sampleCount = centerTap.a;
296         float4 sum = centerTap * sampleCount;
297         
298         float2 lenStep = centerTap.aa * (
1.0 / (TAPS-1.0));
299         float4 steps = (_Offsets.xyxy * _MainTex_TexelSize.xyxy) * lenStep.xyxy * float4(
1,1, -1,-1);
300         
301         
for(int l=1; l<TAPS; l++)
302         {
303             float4 sampleUV = i.uv1.xyxy + steps * (
float)l;
304             
305             float4 sample0 = tex2D(_MainTex, sampleUV.xy);
306             float4 sample1 = tex2D(_MainTex, sampleUV.zw);
307     
308             float2 maxLen01 = float2(sample0.a, sample1.a);
309             float2 r = lenStep.xx * (
float)l;
310             
311             float2 weight01 = smoothstep(float2(-
0.4,-0.4),float2(0.0,0.0), maxLen01-r);
312             sum += sample0 * weight01.x + sample1 * weight01.y;
313
314             sampleCount += dot(weight01,
1);
315         }
316         
317         float4 returnValue = sum / (
1e-5f + sampleCount);
318
319         
//returnValue.a = centerTap.a;
320         
//return centerTap.a;
321
322         
return returnValue;
323     }
324
325
326     float4 fragVisualize (v2f i) : SV_Target
327     {
328         float4 returnValue = tex2D(_MainTex, i.uv1.xy);
329         returnValue.rgb = lerp(float3(
0.0,0.0,0.0), float3(1.0,1.0,1.0), saturate(returnValue.a/_CurveParams.x));
330         
return returnValue;
331     }
332
333
334     float4 fragBoxDownsample (v2f i) : SV_Target
335     {
336         
//float4 returnValue = tex2D(_MainTex, i.uv1.xy);
337         float4 returnValue = tex2D(_MainTex, i.uv1.xy +
0.75*_MainTex_TexelSize.xy);
338         returnValue += tex2D(_MainTex, i.uv1.xy -
0.75*_MainTex_TexelSize.xy);
339         returnValue += tex2D(_MainTex, i.uv1.xy +
0.75*_MainTex_TexelSize.xy * float2(1,-1));
340         returnValue += tex2D(_MainTex, i.uv1.xy -
0.75*_MainTex_TexelSize.xy * float2(1,-1));
341
342         
return returnValue/4;
343     }
344
345     float4 fragBlurAlphaWeighted (v2fBlur i) : SV_Target
346     {
347         
const float ALPHA_WEIGHT = 2.0f;
348         float4 sum = float4 (
0,0,0,0);
349         
float w = 0;
350         
float weights = 0;
351         
const float G_WEIGHTS[6] = {1.0, 0.8, 0.675, 0.5, 0.2, 0.075};
352
353         float4 sampleA = tex2D(_MainTex, i.uv.xy);
354
355         float4 sampleB = tex2D(_MainTex, i.uv01.xy);
356         float4 sampleC = tex2D(_MainTex, i.uv01.zw);
357         float4 sampleD = tex2D(_MainTex, i.uv23.xy);
358         float4 sampleE = tex2D(_MainTex, i.uv23.zw);
359         float4 sampleF = tex2D(_MainTex, i.uv45.xy);
360         float4 sampleG = tex2D(_MainTex, i.uv45.zw);
361         float4 sampleH = tex2D(_MainTex, i.uv67.xy);
362         float4 sampleI = tex2D(_MainTex, i.uv67.zw);
363         float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
364         float4 sampleK = tex2D(_MainTex, i.uv89.zw);
365                                 
366         w = sampleA.a * G_WEIGHTS[
0]; sum += sampleA * w; weights += w;
367         w = saturate(ALPHA_WEIGHT*sampleB.a) * G_WEIGHTS[
1]; sum += sampleB * w; weights += w;
368         w = saturate(ALPHA_WEIGHT*sampleC.a) * G_WEIGHTS[
1]; sum += sampleC * w; weights += w;
369         w = saturate(ALPHA_WEIGHT*sampleD.a) * G_WEIGHTS[
2]; sum += sampleD * w; weights += w;
370         w = saturate(ALPHA_WEIGHT*sampleE.a) * G_WEIGHTS[
2]; sum += sampleE * w; weights += w;
371         w = saturate(ALPHA_WEIGHT*sampleF.a) * G_WEIGHTS[
3]; sum += sampleF * w; weights += w;
372         w = saturate(ALPHA_WEIGHT*sampleG.a) * G_WEIGHTS[
3]; sum += sampleG * w; weights += w;
373         w = saturate(ALPHA_WEIGHT*sampleH.a) * G_WEIGHTS[
4]; sum += sampleH * w; weights += w;
374         w = saturate(ALPHA_WEIGHT*sampleI.a) * G_WEIGHTS[
4]; sum += sampleI * w; weights += w;
375         w = saturate(ALPHA_WEIGHT*sampleJ.a) * G_WEIGHTS[
5]; sum += sampleJ * w; weights += w;
376         w = saturate(ALPHA_WEIGHT*sampleK.a) * G_WEIGHTS[
5]; sum += sampleK * w; weights += w;
377
378         sum /= weights +
1e-4f;
379
380         sum.a = sampleA.a;
381         
if(sampleA.a<1e-2f) sum.rgb = sampleA.rgb;
382
383         
return sum;
384     }
385     
386     float4 fragBlurForFgCoc (v2fBlur i) : SV_Target
387     {
388         float4 sum = float4 (
0,0,0,0);
389         
float w = 0;
390         
float weights = 0;
391         
const float G_WEIGHTS[6] = {1.0, 0.8, 0.675, 0.5, 0.2, 0.075};
392
393         float4 sampleA = tex2D(_MainTex, i.uv.xy);
394
395         float4 sampleB = tex2D(_MainTex, i.uv01.xy);
396         float4 sampleC = tex2D(_MainTex, i.uv01.zw);
397         float4 sampleD = tex2D(_MainTex, i.uv23.xy);
398         float4 sampleE = tex2D(_MainTex, i.uv23.zw);
399         float4 sampleF = tex2D(_MainTex, i.uv45.xy);
400         float4 sampleG = tex2D(_MainTex, i.uv45.zw);
401         float4 sampleH = tex2D(_MainTex, i.uv67.xy);
402         float4 sampleI = tex2D(_MainTex, i.uv67.zw);
403         float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
404         float4 sampleK = tex2D(_MainTex, i.uv89.zw);
405                                 
406         w = sampleA.a * G_WEIGHTS[
0]; sum += sampleA * w; weights += w;
407         w = smoothstep(-
0.5,0.0,sampleB.a-sampleA.a) * G_WEIGHTS[1]; sum += sampleB * w; weights += w;
408         w = smoothstep(-
0.5,0.0,sampleC.a-sampleA.a) * G_WEIGHTS[1]; sum += sampleC * w; weights += w;
409         w = smoothstep(-
0.5,0.0,sampleD.a-sampleA.a) * G_WEIGHTS[2]; sum += sampleD * w; weights += w;
410         w = smoothstep(-
0.5,0.0,sampleE.a-sampleA.a) * G_WEIGHTS[2]; sum += sampleE * w; weights += w;
411         w = smoothstep(-
0.5,0.0,sampleF.a-sampleA.a) * G_WEIGHTS[3]; sum += sampleF * w; weights += w;
412         w = smoothstep(-
0.5,0.0,sampleG.a-sampleA.a) * G_WEIGHTS[3]; sum += sampleG * w; weights += w;
413         w = smoothstep(-
0.5,0.0,sampleH.a-sampleA.a) * G_WEIGHTS[4]; sum += sampleH * w; weights += w;
414         w = smoothstep(-
0.5,0.0,sampleI.a-sampleA.a) * G_WEIGHTS[4]; sum += sampleI * w; weights += w;
415         w = smoothstep(-
0.5,0.0,sampleJ.a-sampleA.a) * G_WEIGHTS[5]; sum += sampleJ * w; weights += w;
416         w = smoothstep(-
0.5,0.0,sampleK.a-sampleA.a) * G_WEIGHTS[5]; sum += sampleK * w; weights += w;
417
418         sum /= weights +
1e-4f;
419
420         
return sum;
421     }
422
423     float4 fragGaussBlur (v2fBlur i) : SV_Target
424     {
425         float4 sum = float4 (
0,0,0,0);
426         
float w = 0;
427         
float weights = 0;
428         
const float G_WEIGHTS[9] = {1.0, 0.8, 0.65, 0.5, 0.4, 0.2, 0.1, 0.05, 0.025};
429
430         float4 sampleA = tex2D(_MainTex, i.uv.xy);
431
432         float4 sampleB = tex2D(_MainTex, i.uv01.xy);
433         float4 sampleC = tex2D(_MainTex, i.uv01.zw);
434         float4 sampleD = tex2D(_MainTex, i.uv23.xy);
435         float4 sampleE = tex2D(_MainTex, i.uv23.zw);
436         float4 sampleF = tex2D(_MainTex, i.uv45.xy);
437         float4 sampleG = tex2D(_MainTex, i.uv45.zw);
438         float4 sampleH = tex2D(_MainTex, i.uv67.xy);
439         float4 sampleI = tex2D(_MainTex, i.uv67.zw);
440         float4 sampleJ = tex2D(_MainTex, i.uv89.xy);
441         float4 sampleK = tex2D(_MainTex, i.uv89.zw);
442
443         w = sampleA.a * G_WEIGHTS[
0]; sum += sampleA * w; weights += w;
444         w = sampleB.a * G_WEIGHTS[
1]; sum += sampleB * w; weights += w;
445         w = sampleC.a * G_WEIGHTS[
1]; sum += sampleC * w; weights += w;
446         w = sampleD.a * G_WEIGHTS[
2]; sum += sampleD * w; weights += w;
447         w = sampleE.a * G_WEIGHTS[
2]; sum += sampleE * w; weights += w;
448         w = sampleF.a * G_WEIGHTS[
3]; sum += sampleF * w; weights += w;
449         w = sampleG.a * G_WEIGHTS[
3]; sum += sampleG * w; weights += w;
450         w = sampleH.a * G_WEIGHTS[
4]; sum += sampleH * w; weights += w;
451         w = sampleI.a * G_WEIGHTS[
4]; sum += sampleI * w; weights += w;
452         w = sampleJ.a * G_WEIGHTS[
5]; sum += sampleJ * w; weights += w;
453         w = sampleK.a * G_WEIGHTS[
5]; sum += sampleK * w; weights += w;
454
455         sum /= weights +
1e-4f;
456
457         
return sum;
458     }
459
460     float4 frag4TapBlurForLRSpawn (v2f i) : SV_Target
461     {
462         float4 tap = tex2D(_MainTex, i.uv.xy);
463         
464         float4 tapA = tex2D(_MainTex, i.uv.xy +
0.75 * _MainTex_TexelSize.xy);
465         float4 tapB = tex2D(_MainTex, i.uv.xy -
0.75 * _MainTex_TexelSize.xy);
466         float4 tapC = tex2D(_MainTex, i.uv.xy +
0.75 * _MainTex_TexelSize.xy * float2(1,-1));
467         float4 tapD = tex2D(_MainTex, i.uv.xy -
0.75 * _MainTex_TexelSize.xy * float2(1,-1));
468         
469         float4 weights = saturate(
10.0 * float4(tapA.a, tapB.a, tapC.a, tapD.a));
470         
float sumWeights = dot(weights, 1);
471
472         float4 color = (tapA*weights.x + tapB*weights.y + tapC*weights.z + tapD*weights.w);
473
474         float4 outColor = tap;
475         
if(tap.a * sumWeights * 8.0 > 1e-5f) outColor.rgb = color.rgb/sumWeights;
476
477         
return outColor;
478     }
479
480     float4 fragCaptureColorAndSignedCoc (v2f i) : SV_Target
481     {
482         float4 color = tex2D (_MainTex, i.uv1.xy);
483         
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
484         d = Linear01Depth (d);
485         color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d +
1e-5f);
486         color.a = clamp( max(
0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x) * sign(d - _CurveParams.w);
487         
488         
return color;
489     }
490     
491     float4 fragCaptureCoc (v2f i) : SV_Target
492     {
493         float4 color = float4(
0,0,0,0); //tex2D (_MainTex, i.uv1.xy);
494         
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
495         d = Linear01Depth (d);
496         color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d +
1e-5f);
497         color.a = clamp( max(
0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
498         
499         
return color;
500     }
501
502     float4 AddFgCoc (v2f i) : SV_Target
503     {
504         
return tex2D (_MainTex, i.uv1.xy);
505     }
506
507     float4 fragMergeCoc (v2f i) : SV_Target
508     {
509         float4 color = tex2D (_FgOverlap, i.uv1.xy);
// this is the foreground overlap value
510         
float fgCoc = color.a;
511
512         
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
513         d = Linear01Depth (d);
514         color.a = _CurveParams.z * abs(d - _CurveParams.w) / (d +
1e-5f);
515         color.a = clamp( max(
0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
516         
517         
return max(color.aaaa, float4(fgCoc,fgCoc,fgCoc,fgCoc));
518     }
519
520     float4 fragCombineCocWithMaskBlur (v2f i) : SV_Target
521     {
522         
float bgAndFgCoc = tex2D (_MainTex, i.uv1.xy).a;
523         
float fgOverlapCoc = tex2D (_FgOverlap, i.uv1.xy).a;
524
525         
return (bgAndFgCoc < 0.01) * saturate(fgOverlapCoc-bgAndFgCoc);
526     }
527     
528     float4 fragCaptureForegroundCoc (v2f i) : SV_Target
529     {
530         float4 color = float4(
0,0,0,0); //tex2D (_MainTex, i.uv1.xy);
531         
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
532         d = Linear01Depth (d);
533         color.a = _CurveParams.z * (_CurveParams.w-d) / (d +
1e-5f);
534         color.a = clamp(max(
0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
535         
536         
return color;
537     }
538
539     float4 fragCaptureForegroundCocMask (v2f i) : SV_Target
540     {
541         float4 color = float4(
0,0,0,0);
542         
float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv1.xy);
543         d = Linear01Depth (d);
544         color.a = _CurveParams.z * (_CurveParams.w-d) / (d +
1e-5f);
545         color.a = clamp(max(
0.0, color.a - _CurveParams.y), 0.0, _CurveParams.x);
546         
547         
return color.a > 0;
548     }
549     
550     float4 fragBlendInHighRez (v2f i) : SV_Target
551     {
552         float4 tapHighRez = tex2D(_MainTex, i.uv.xy);
553         
return float4(tapHighRez.rgb, 1.0-saturate(tapHighRez.a*5.0));
554     }
555     
556     float4 fragBlendInLowRezParts (v2f i) : SV_Target
557     {
558         float4
from = tex2D(_MainTex, i.uv1.xy);
559         
from.a = saturate(from.a * _Offsets.w) / (_CurveParams.x + 1e-5f);
560         
float square = from.a * from.a;
561         
from.a = square * square * _CurveParams.x;
562         
return from;
563     }
564     
565     float4 fragUpsampleWithAlphaMask(v2f i) : SV_Target
566     {
567         float4 c = tex2D(_MainTex, i.uv1.xy);
568         
return c;
569     }
570     
571     float4 fragAlphaMask(v2f i) : SV_Target
572     {
573         float4 c = tex2D(_MainTex, i.uv1.xy);
574         c.a = saturate(c.a*
100.0);
575         
return c;
576     }
577         
578     ENDCG
579     
580 Subshader
581 {
582  
583  
// pass 0
584  
585  Pass {
586       ZTest Always Cull Off ZWrite Off
587       ColorMask A
588
589       CGPROGRAM
590
591       #pragma target
3.0
592       #pragma vertex vert
593       #pragma fragment fragCaptureCoc
594       
595       ENDCG
596     }
597
598  
// pass 1
599  
600  Pass
601  {
602       ZTest Always Cull Off ZWrite Off
603
604       CGPROGRAM
605
606       #pragma target
3.0
607       #pragma vertex vertBlurPlusMinus
608       #pragma fragment fragGaussBlur
609
610       ENDCG
611     }
612
613  
// pass 2
614
615  Pass {
616       ZTest Always Cull Off ZWrite Off
617
618       CGPROGRAM
619
620       #pragma target
3.0
621       #pragma vertex vertBlurPlusMinus
622       #pragma fragment fragBlurForFgCoc
623
624       ENDCG
625     }
626     
627     
628  
// pass 3
629  
630  Pass
631  {
632       ZTest Always Cull Off ZWrite Off
633       ColorMask A
634       BlendOp Max, Max
635       Blend One One, One One
636
637       CGPROGRAM
638
639       #pragma target
3.0
640       #pragma vertex vert
641       #pragma fragment AddFgCoc
642
643       ENDCG
644     }
645         
646
647  
// pass 4
648   
649  Pass
650  {
651       ZTest Always Cull Off ZWrite Off
652       ColorMask A
653
654       CGPROGRAM
655
656       #pragma target
3.0
657       #pragma vertex vert
658       #pragma fragment fragCaptureForegroundCoc
659
660       ENDCG
661     }
662
663  
// pass 5
664  
665  Pass {
666       ZTest Always Cull Off ZWrite Off
667
668       CGPROGRAM
669
670       #pragma target
3.0
671       #pragma vertex vert
672       #pragma fragment fragBlurBox
673
674       ENDCG
675     }
676
677  
// pass 6
678  
679  Pass {
680       ZTest Always Cull Off ZWrite Off
681
682       CGPROGRAM
683
684       #pragma target
3.0
685       #pragma vertex vert
686       #pragma fragment frag4TapBlurForLRSpawn
687
688       ENDCG
689     }
690
691  
// pass 7
692  
693  Pass {
694       ZTest Always Cull Off ZWrite Off
695       ColorMask RGB
696       Blend SrcAlpha OneMinusSrcAlpha
697
698       CGPROGRAM
699
700       #pragma target
3.0
701       #pragma vertex vert
702       #pragma fragment fragBlendInHighRez
703
704       ENDCG
705     }
706     
707  
// pass 8
708  
709  Pass
710  {
711       ZTest Always Cull Off ZWrite Off
712       ColorMask A
713
714       CGPROGRAM
715
716       #pragma target
3.0
717       #pragma vertex vert
718       #pragma fragment fragCaptureForegroundCocMask
719
720       ENDCG
721     }
722     
723
724  
// pass 9
725  
726  Pass {
727       ZTest Always Cull Off ZWrite Off
728
729       CGPROGRAM
730
731       #pragma target
3.0
732       #pragma vertex vert
733       #pragma fragment fragBlurUpsampleCheap
734
735       ENDCG
736     }
737
738  
// pass 10
739  
740  Pass {
741       ZTest Always Cull Off ZWrite Off
742
743       CGPROGRAM
744
745       #pragma target
3.0
746       #pragma vertex vert
747       #pragma fragment fragCaptureColorAndSignedCoc
748
749       ENDCG
750     }
751
752  
// pass 11
753  
754  Pass {
755       ZTest Always Cull Off ZWrite Off
756
757       CGPROGRAM
758
759       #pragma target
3.0
760       #pragma vertex vert
761       #pragma fragment fragBlurInsaneMQ
762
763       ENDCG
764     }
765
766  
// pass 12
767  
768  Pass {
769       ZTest Always Cull Off ZWrite Off
770
771       CGPROGRAM
772
773       #pragma target
3.0
774       #pragma vertex vert
775       #pragma fragment fragBlurUpsampleCombineMQ
776
777       ENDCG
778     }
779     
780     
// pass 13
781  Pass {
782       ZTest Always Cull Off ZWrite Off
783
784       ColorMask A
785
786       CGPROGRAM
787
788       #pragma target
3.0
789       #pragma vertex vert
790       #pragma fragment fragMergeCoc
791
792       ENDCG
793     }
794     
795  
// pass 14
796  
797  Pass {
798       ZTest Always Cull Off ZWrite Off
799
800       ColorMask A
801       BlendOp Max, Max
802       Blend One One, One One
803
804       CGPROGRAM
805
806       #pragma target
3.0
807       #pragma vertex vert
808       #pragma fragment fragCombineCocWithMaskBlur
809
810       ENDCG
811     }
812
813  
// pass 15
814  
815  Pass {
816       ZTest Always Cull Off ZWrite Off
817
818       CGPROGRAM
819
820       #pragma target
3.0
821       #pragma vertex vert
822       #pragma fragment fragBoxDownsample
823
824       ENDCG
825     }
826
827  
// pass 16
828  Pass {
829       ZTest Always Cull Off ZWrite Off
830
831         CGPROGRAM
832
833         #pragma target
3.0
834         #pragma vertex vert
835         #pragma fragment fragVisualize
836
837         ENDCG
838     }
839
840  
// pass 17
841  
842  Pass {
843       ZTest Always Cull Off ZWrite Off
844
845       CGPROGRAM
846
847       #pragma target
3.0
848       #pragma vertex vert
849       #pragma fragment fragBlurInsaneHQ
850
851       ENDCG
852     }
853
854  
// pass 18
855  
856  Pass {
857       ZTest Always Cull Off ZWrite Off
858
859       CGPROGRAM
860
861       #pragma target
3.0
862       #pragma vertex vert
863       #pragma fragment fragBlurUpsampleCombineHQ
864
865       ENDCG
866     }
867
868   
// pass 19
869
870  Pass {
871       ZTest Always Cull Off ZWrite Off
872
873       CGPROGRAM
874
875       #pragma target
3.0
876       #pragma vertex vertBlurPlusMinus
877       #pragma fragment fragBlurAlphaWeighted
878
879       ENDCG
880     }
881     
882   
// pass 20
883  
884  Pass {
885       ZTest Always Cull Off ZWrite Off
886
887       CGPROGRAM
888
889       #pragma target
3.0
890       #pragma vertex vert
891       #pragma fragment fragAlphaMask
892
893       ENDCG
894     }
895     
896   
// pass 21
897  
898  Pass {
899       ZTest Always Cull Off ZWrite Off
900
901       BlendOp Add, Add
902       Blend DstAlpha OneMinusDstAlpha, Zero One
903
904       CGPROGRAM
905
906       #pragma target
3.0
907       #pragma vertex vertFlip
908       #pragma fragment fragBlurBox
909
910       ENDCG
911     }
912     
913   
// pass 22
914  
915  Pass {
916       ZTest Always Cull Off ZWrite Off
917
918       
// destination alpha needs to stay intact as we have layed alpha before
919       BlendOp Add, Add
920       Blend DstAlpha One, Zero One
921
922       CGPROGRAM
923       
924       #pragma target
3.0
925       #pragma vertex vert
926       #pragma fragment fragUpsampleWithAlphaMask
927
928       ENDCG
929     }
930 }
931   
932 Fallback off
933
934 }


Gõ tìm kiếm nhanh...