Blender V5.3
eevee_depth_of_field_accumulator.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
12
20
21/* -------------------------------------------------------------------- */
24
25#ifndef SRT_CONSTANT_is_hole_fill
26# define SRT_CONSTANT_is_hole_fill 0
27#endif
28
29/* Quality options */
30#if SRT_CONSTANT_is_hole_fill
31/* No need for very high density for hole_fill. */
32# define gather_ring_count int(3)
33# define gather_ring_density int(3)
34# define gather_max_density_change int(0)
35# define gather_density_change_ring int(1)
36#else
37# define gather_ring_count int(DOF_GATHER_RING_COUNT)
38# define gather_ring_density int(3)
39# define gather_max_density_change int(50) /* Dictates the maximum good quality blur. */
40# define gather_density_change_ring int(1)
41#endif
42
43namespace eevee::dof {
44
47 float weight;
48 float dist; /* TODO remove */
49 /* For scatter occlusion. */
50 float coc;
51 float coc_sqr;
52 /* For ring bucket merging. */
54
56};
57
59
60/* -------------------------------------------------------------------- */
63
64#define unit_ring_radius float(1.0f / float(gather_ring_count))
65#define unit_sample_radius float(1.0f / float(gather_ring_count + 0.5f))
66#define large_kernel_radius float(0.5f + float(gather_ring_count))
67#define smaller_kernel_radius float(0.5f + float(gather_ring_count - gather_density_change_ring))
68/* NOTE(fclem) the bias is reducing issues with density change visible transition. */
69#define radius_downscale_factor float(smaller_kernel_radius / large_kernel_radius)
70#define change_density_at_ring int((gather_ring_count - gather_density_change_ring + 1))
71#define coc_radius_error float(2.0f)
72
74
81
84
86
87 [[uniform(0)]] const DepthOfFieldData &dof_buf;
88
91
92 /* -------------------------------------------------------------------- */
95
96 /* Intersection with the center of the kernel. */
97 float dof_intersection_weight(float coc,
98 float distance_from_center,
99 float intersection_multiplier)
100 {
102 return step(0.0f, (abs(coc) - distance_from_center));
103 }
104 /* (Slide 64). */
105 return saturate((abs(coc) - distance_from_center) * intersection_multiplier + 0.5f);
106 }
107
108 /* Returns weight of the sample for the outer bucket (containing previous
109 * rings). */
110 float dof_gather_accum_weight(float coc, float bordering_radius, bool first_ring)
111 {
112 /* First ring has nothing to be mixed against. */
113 if (first_ring) {
114 return 0.0f;
115 }
116 return saturate(coc - bordering_radius);
117 }
118
119 void dof_gather_amend_weight(DofGatherData &sample_data, float weight)
120 {
121 sample_data.color *= weight;
122 sample_data.coc *= weight;
123 sample_data.coc_sqr *= weight;
124 sample_data.weight *= weight;
125 }
126
128 float weight,
129 DofGatherData &accum_data)
130 {
131 accum_data.color += sample_data.color * weight;
132 accum_data.coc += sample_data.coc * weight;
133 accum_data.coc_sqr += sample_data.coc * (sample_data.coc * weight);
134 accum_data.weight += weight;
135 }
136
138 float bordering_radius,
139 float intersection_multiplier,
140 bool first_ring,
141 const bool do_fast_gather,
142 const bool foreground,
143 DofGatherData &ring_data,
144 DofGatherData &accum_data)
145 {
146 if (do_fast_gather) {
147 for (int i = 0; i < 2; i++) {
148 dof_gather_accumulate_sample(pair_data[i], 1.0f, accum_data);
149 accum_data.layer_opacity += 1.0f;
150 }
151 return;
152 }
153
154#if 0
155 constexpr float mirroring_threshold = -dof_layer_threshold - dof_layer_offset;
156 /* TODO(fclem) Promote to parameter? dither with Noise? */
157 constexpr float mirroring_min_distance = 15.0f;
158 if (pair_data[0].coc < mirroring_threshold &&
159 (pair_data[1].coc - mirroring_min_distance) > pair_data[0].coc)
160 {
161 pair_data[1].coc = pair_data[0].coc;
162 }
163 else if (pair_data[1].coc < mirroring_threshold &&
164 (pair_data[0].coc - mirroring_min_distance) > pair_data[1].coc)
165 {
166 pair_data[0].coc = pair_data[1].coc;
167 }
168#endif
169
170 for (int i = 0; i < 2; i++) {
171 float sample_weight = dof_sample_weight(pair_data[i].coc);
172 float layer_weight = dof_layer_weight(pair_data[i].coc, foreground, consts.is_resolve);
173 float inter_weight = dof_intersection_weight(
174 pair_data[i].coc, pair_data[i].dist, intersection_multiplier);
175 float weight = inter_weight * layer_weight * sample_weight;
176
177 /* If a CoC is larger than bordering radius we accumulate it to the general accumulator.
178 * If not, we accumulate to the ring bucket. This is to have more consistent sample
179 * occlusion.
180 */
181 float accum_weight = dof_gather_accum_weight(pair_data[i].coc, bordering_radius, first_ring);
182 dof_gather_accumulate_sample(pair_data[i], weight * accum_weight, accum_data);
183 dof_gather_accumulate_sample(pair_data[i], weight * (1.0f - accum_weight), ring_data);
184
185 accum_data.layer_opacity += layer_weight;
186
187 if (foreground) {
188 ring_data.transparency += 1.0f - inter_weight * layer_weight;
189 }
190 else {
191 float coc = foreground ? -pair_data[i].coc : pair_data[i].coc;
192 ring_data.transparency += saturate(coc - bordering_radius);
193 }
194 }
195 }
196
198 int sample_count,
199 bool first_ring,
200 const bool do_fast_gather,
201 /* accum_data occludes the ring_data if true. */
202 const bool reversed_occlusion,
203 DofGatherData &accum_data)
204 {
205 if (do_fast_gather) {
206 /* Do nothing as ring_data contains nothing. All samples are already in
207 * accum_data. */
208 return;
209 }
210
211 if (first_ring) {
212 /* Layer opacity is directly accumulated into accum_data data. */
213 accum_data.color = ring_data.color;
214 accum_data.coc = ring_data.coc;
215 accum_data.coc_sqr = ring_data.coc_sqr;
216 accum_data.weight = ring_data.weight;
217
218 accum_data.transparency = ring_data.transparency / float(sample_count);
219 return;
220 }
221
222 if (ring_data.weight == 0.0f) {
223 return;
224 }
225
226 float ring_avg_coc = ring_data.coc / ring_data.weight;
227 float accum_avg_coc = accum_data.coc / accum_data.weight;
228
229 /* Smooth test to set opacity to see if the ring average coc occludes the
230 * accumulation. Test is reversed to be multiplied against opacity. */
231 float ring_occlu = saturate(accum_avg_coc - ring_avg_coc);
232 /* The bias here is arbitrary. Seems to avoid weird looking foreground in most
233 * cases. We might need to make it a parameter or find a relative bias. */
234 float accum_occlu = saturate((ring_avg_coc - accum_avg_coc) * 0.1f - 1.0f);
235
236 if (consts.is_resolve) {
237 ring_occlu = accum_occlu = 0.0f;
238 }
239
241 ring_occlu = 0.0f;
242 accum_occlu = 0.0f;
243 }
244
245 /* (Slide 40) */
246 float ring_opacity = saturate(1.0f - ring_data.transparency / float(sample_count));
247 float accum_opacity = 1.0f - accum_data.transparency;
248
249 if (reversed_occlusion) {
250 /* Accum_data occludes the ring. */
251 float alpha = (accum_data.weight == 0.0f) ? 0.0f : accum_opacity * accum_occlu;
252 float one_minus_alpha = 1.0f - alpha;
253
254 accum_data.color += ring_data.color * one_minus_alpha;
255 accum_data.coc += ring_data.coc * one_minus_alpha;
256 accum_data.coc_sqr += ring_data.coc_sqr * one_minus_alpha;
257 accum_data.weight += ring_data.weight * one_minus_alpha;
258
259 accum_data.transparency *= 1.0f - ring_opacity;
260 }
261 else {
262 /* Ring occludes the accum_data (Same as reference). */
263 float alpha = (accum_data.weight == 0.0f) ? 1.0f : (ring_opacity * ring_occlu);
264 float one_minus_alpha = 1.0f - alpha;
265
266 accum_data.color = accum_data.color * one_minus_alpha + ring_data.color;
267 accum_data.coc = accum_data.coc * one_minus_alpha + ring_data.coc;
268 accum_data.coc_sqr = accum_data.coc_sqr * one_minus_alpha + ring_data.coc_sqr;
269 accum_data.weight = accum_data.weight * one_minus_alpha + ring_data.weight;
270 }
271 }
272
273 /* FIXME(fclem) Seems to be wrong since it needs `ringcount + 1` as input for
274 * slight-focus gather. */
275 /* This should be replaced by web_sample_count_get() but doing so is breaking other things. */
276 int dof_gather_total_sample_count(const int ring_count, const int ring_density)
277 {
278 return (ring_count * ring_count - ring_count) * ring_density + 1;
279 }
280
282 float bordering_radius,
283 int i_radius,
284 const bool do_fast_gather,
285 const bool foreground,
286 const bool resolve,
287 DofGatherData &accum_data)
288 {
289 float layer_weight = dof_layer_weight(center_data.coc, foreground, resolve);
290 float sample_weight = dof_sample_weight(center_data.coc);
291 float weight = layer_weight * sample_weight;
292 float accum_weight = dof_gather_accum_weight(center_data.coc, bordering_radius, false);
293
294 if (do_fast_gather) {
295 /* Hope for the compiler to optimize the above. */
296 layer_weight = 1.0f;
297 sample_weight = 1.0f;
298 accum_weight = 1.0f;
299 weight = 1.0f;
300 }
301
302 center_data.transparency = 1.0f - weight;
303
304 dof_gather_accumulate_sample(center_data, weight * accum_weight, accum_data);
305
306 if (!do_fast_gather) {
307 if (resolve) {
308 /* NOTE(fclem): Hack to smooth transition to full in-focus opacity. */
309 int total_sample_count = dof_gather_total_sample_count(i_radius + 1,
311 float fac = saturate(1.0f - abs(center_data.coc) / float(dof_layer_threshold));
312 accum_data.layer_opacity += float(total_sample_count) * fac * fac;
313 }
314 accum_data.layer_opacity += layer_weight;
315
316 /* Logic of dof_gather_accumulate_sample(). */
317 weight *= (1.0f - accum_weight);
318 center_data.coc_sqr = center_data.coc * (center_data.coc * weight);
319 center_data.color *= weight;
320 center_data.coc *= weight;
321 center_data.weight = weight;
322
323 if (foreground && !resolve) {
324 /* Reduce issue with closer foreground over distant foreground. */
325 float ring_area = square(bordering_radius);
326 dof_gather_amend_weight(center_data, ring_area);
327 }
328
329 /* Accumulate center as its own ring. */
331 center_data, 1, false, do_fast_gather, foreground, accum_data);
332 }
333 }
334
336 const int ring_density,
337 int density_change)
338 {
339 int sample_count_per_density_change = dof_gather_total_sample_count(ring_count, ring_density) -
341 ring_count - gather_density_change_ring,
342 ring_density);
343
344 return dof_gather_total_sample_count(ring_count, ring_density) +
345 sample_count_per_density_change * density_change;
346 }
347
348 void dof_gather_accumulate_resolve(int total_sample_count,
349 DofGatherData accum_data,
350 float4 &out_col,
351 float &out_weight,
352 float2 &out_occlusion)
353 {
354 float weight_inv = safe_rcp(accum_data.weight);
355 out_col = accum_data.color * weight_inv;
356 out_occlusion = float2(abs(accum_data.coc), accum_data.coc_sqr) * weight_inv;
357
358 if (consts.is_foreground) {
359 out_weight = 1.0f - accum_data.transparency;
360 }
361 else if (accum_data.weight > 0.0f) {
362 out_weight = accum_data.layer_opacity / float(total_sample_count);
363 }
364 else {
365 out_weight = 0.0f;
366 }
367 /* Gathering may not accumulate to 1.0 alpha because of float precision. */
368 if (out_weight > 0.99f) {
369 out_weight = 1.0f;
370 }
371 else if (out_weight < 0.01f) {
372 out_weight = 0.0f;
373 }
374 /* Same thing for alpha channel. */
375 if (out_col.a > 0.993f) {
376 out_col.a = 1.0f;
377 }
378 else if (out_col.a < 0.003f) {
379 out_col.a = 0.0f;
380 }
381 }
382
383 float dof_load_gather_coc(sampler2D gather_input_coc_tx, float2 uv, float lod)
384 {
385 float coc = textureLod(gather_input_coc_tx, uv, lod).r;
386 /* We gather at half-resolution. CoC must be divided by 2 to be compared against radii. */
387 return coc * 0.5f;
388 }
389
391
392 /* -------------------------------------------------------------------- */
395
396 /* Radii needs to be half-resolution CoC sizes. */
397 bool dof_do_density_change(float base_radius, float min_intersectable_radius)
398 {
399 /* Reduce artifact for very large blur. */
400 min_intersectable_radius *= 0.1f;
401
402 bool need_new_density = (base_radius * unit_ring_radius > min_intersectable_radius);
403 bool larger_than_min_density = (base_radius * radius_downscale_factor >
405
406 return need_new_density && larger_than_min_density;
407 }
408
410 float base_radius,
412 float2 &center_co,
413 float &lod,
414 float &intersection_multiplier)
415 {
416 /* Jitter center half a ring to reduce undersampling. */
417 float2 jitter_ofs = 0.499f * sample_disk(noise);
418 if (consts.use_lut) {
419 jitter_ofs *= dof_buf.bokeh_anisotropic_scale;
420 }
421 center_co = frag_coord + jitter_ofs * base_radius * unit_sample_radius;
422
423 /* TODO(fclem) Seems like the default lod selection is too big. Bias to avoid blocky moving out
424 * of focus shapes. */
425 constexpr float lod_bias = -2.0f;
426 lod = max(floor(log2(base_radius * unit_sample_radius) + 0.5f) + lod_bias, 0.0f);
427
428 if (no_gather_mipmaps) {
429 lod = 0.0f;
430 }
431 /* (Slide 64). */
432 intersection_multiplier = pow(0.5f, lod);
433 }
434
436 sampler2D color_tx,
437 sampler2D color_bilinear_tx,
438 sampler2D coc_tx,
439 float base_radius,
440 float min_intersectable_radius,
441 const bool do_fast_gather,
442 const bool do_density_change,
443 float4 &out_color,
444 float &out_weight,
445 float2 &out_occlusion)
446 {
447 float2 noise_offset = sampling.rng_2D_get(SAMPLING_LENS_U);
449 float2(0.0f, 0.0f) :
451 random::interleaved_gradient(frag_coord, 1, noise_offset.y));
452
453 if (!do_fast_gather) {
454 /* Jitter the radius to reduce noticeable density changes. */
455 base_radius += noise.x * unit_ring_radius * base_radius;
456 }
457 else {
458 /* Jittering the radius more than we need means we are going to feather the bokeh shape half
459 * a ring. So we need to compensate for fast gather that does not check CoC intersection. */
460 base_radius += (0.5f - noise.x) * 1.5f * unit_ring_radius * base_radius;
461 }
462 /* TODO(@fclem): another seed? For now Cranley-Patterson rotation with golden ratio. */
463 noise.x = fract(noise.x * 6.1803398875f);
464
465 float lod, isect_mul;
466 float2 center_co;
467 dof_gather_init(frag_coord + 0.5f, base_radius, noise, center_co, lod, isect_mul);
468
469 bool first_ring = true;
470
471 DofGatherData accum_data = {};
472
473 int density_change = 0;
474 for (int ring = gather_ring_count; ring > 0; ring--) {
475 int sample_pair_count = gather_ring_density * ring;
476
477 float step_rot = M_PI / float(sample_pair_count);
478 float2x2 step_rot_mat = from_rotation(AngleRadian{step_rot});
479
480 float angle_offset = noise.y * step_rot;
481 float2 offset = float2(cos(angle_offset), sin(angle_offset));
482
483 float ring_radius = float(ring) * unit_sample_radius * base_radius;
484
485 /* Slide 38. */
486 float bordering_radius = ring_radius +
487 (0.5f + coc_radius_error) * base_radius * unit_sample_radius;
488 DofGatherData ring_data = {};
489 for (int sample_pair = 0; sample_pair < sample_pair_count; sample_pair++) {
490 offset = step_rot_mat * offset;
491
492 DofGatherData pair_data[2];
493 for (int i = 0; i < 2; i++) {
494 float2 offset_co = ((i == 0) ? offset : -offset);
495 if (consts.use_lut) [[static_branch]] {
496 /* Scaling to 0.25 for speed. Improves texture cache hit. */
497 offset_co = texture(bokeh_lut_tx, offset_co * 0.25f + 0.5f).rg;
498 offset_co *= (consts.is_foreground) ? -dof_buf.bokeh_anisotropic_scale :
499 dof_buf.bokeh_anisotropic_scale;
500 }
501 float2 sample_co = center_co + offset_co * ring_radius;
502 float2 sample_uv = sample_co * dof_buf.gather_uv_fac;
503 if (do_fast_gather) {
504 pair_data[i].color = textureLod(color_bilinear_tx, sample_uv, lod);
505 }
506 else {
507 pair_data[i].color = textureLod(color_tx, sample_uv, lod);
508 }
509 pair_data[i].coc = dof_load_gather_coc(coc_tx, sample_uv, lod);
510 pair_data[i].dist = ring_radius;
511 }
512
514 bordering_radius,
515 isect_mul,
516 first_ring,
517 do_fast_gather,
519 ring_data,
520 accum_data);
521 }
522
523 if (consts.is_foreground) {
524 /* Reduce issue with closer foreground over distant foreground. */
525 /* TODO(fclem) this seems to not be completely correct as the issue remains. */
526 float ring_area = (square(float(ring) + 0.5f + coc_radius_error) -
527 square(float(ring) - 0.5f + coc_radius_error)) *
528 square(base_radius * unit_sample_radius);
529 dof_gather_amend_weight(ring_data, ring_area);
530 }
531
533 sample_pair_count * 2,
534 first_ring,
535 do_fast_gather,
537 accum_data);
538
539 first_ring = false;
540
541 if (do_density_change && (ring == change_density_at_ring) &&
542 (density_change < gather_max_density_change))
543 {
544 if (dof_do_density_change(base_radius, min_intersectable_radius)) {
545 base_radius *= radius_downscale_factor;
547 /* We need to account for the density change in the weights (slide 62).
548 * For that multiply old kernel data by its area divided by the new kernel area. */
549 const float outer_rings_weight = 1.0f /
551 /* Samples are already weighted per ring in foreground pass. */
552 if (!consts.is_foreground) {
553 dof_gather_amend_weight(accum_data, outer_rings_weight);
554 }
555 /* Re-init kernel position & sampling parameters. */
556 dof_gather_init(frag_coord + 0.5f, base_radius, noise, center_co, lod, isect_mul);
557 density_change++;
558 }
559 }
560 }
561
562 {
563 /* Center sample. */
564 float2 sample_uv = center_co * dof_buf.gather_uv_fac;
565 DofGatherData center_data;
566 if (do_fast_gather) {
567 center_data.color = textureLod(color_bilinear_tx, sample_uv, lod);
568 }
569 else {
570 center_data.color = textureLod(color_tx, sample_uv, lod);
571 }
572 center_data.coc = dof_load_gather_coc(coc_tx, sample_uv, lod);
573 center_data.dist = 0.0f;
574
575 /* Slide 38. */
576 float bordering_radius = (0.5f + coc_radius_error) * base_radius * unit_sample_radius;
577
579 bordering_radius,
580 0,
581 do_fast_gather,
583 false,
584 accum_data);
585 }
586
588 gather_ring_count, gather_ring_density, density_change);
590 total_sample_count, accum_data, out_color, out_weight, out_occlusion);
591
592 if (debug_gather_perf && density_change > 0) {
593 float fac = saturate(float(density_change) / float(10.0f));
594 out_color.rgb = average(out_color.rgb) * neon_gradient(fac);
595 }
596 if (debug_gather_perf && do_fast_gather) {
597 out_color.rgb = average(out_color.rgb) * float3(0.0f, 1.0f, 0.0f);
598 }
599 if (debug_scatter_perf) {
600 out_color.rgb = average(out_color.rgb) * float3(0.0f, 1.0f, 0.0f);
601 }
602
603 /* Output premultiplied color so we can use bilinear sampler in resolve pass. */
604 out_color *= out_weight;
605 }
606
608
609 /* -------------------------------------------------------------------- */
614
616 sampler2DDepth depth_tx,
617 sampler2D color_tx,
618 sampler2D bkh_lut_tx, /* Renamed because of ugly macro job. */
619 float radius,
620 float4 &out_color,
621 float &out_weight,
622 float &out_center_coc)
623 {
624 float2 noise_offset = sampling.rng_2D_get(SAMPLING_LENS_U);
626 float2(0.0f) :
628 random::interleaved_gradient(frag_coord, 5, noise_offset.y));
629
630 DofGatherData fg_accum = {};
631 DofGatherData bg_accum = {};
632
633 int i_radius = clamp(int(radius), 0, int(dof_layer_threshold));
634
635 constexpr float sample_count_max = float(DOF_SLIGHT_FOCUS_SAMPLE_MAX);
636 /* Scale by search area. */
637 float sample_count = sample_count_max * saturate(square(radius) / square(dof_layer_threshold));
638
639 bool first_ring = true;
640
641 for (float s = 0.0f; s < sample_count; s++) {
642 float2 rand2 = fract(random::hammersley_2d(s, sample_count) + noise);
643 float2 offset = sample_disk(rand2) * radius;
644 float ring_dist = length(offset);
645
646 DofGatherData pair_data[2];
647 for (int i = 0; i < 2; i++) {
648 float2 sample_offset = ((i == 0) ? offset : -offset);
649 /* OPTI: could precompute the factor. */
650 float2 sample_uv = (frag_coord + sample_offset) / float2(textureSize(depth_tx, 0));
651 float depth = reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r);
652 pair_data[i].coc = dof_coc_from_depth(views, dof_buf, sample_uv, depth);
653 pair_data[i].color = colorspace::safe_color(textureLod(color_tx, sample_uv, 0.0f));
654 pair_data[i].dist = ring_dist;
655 if (consts.use_lut) {
656 /* Contains sub-pixel distance to bokeh shape. */
657 int2 lut_texel = int2(round(sample_offset)) + dof_max_slight_focus_radius;
658 pair_data[i].dist = texelFetch(bkh_lut_tx, lut_texel, 0).r;
659 }
660 pair_data[i].coc = clamp(pair_data[i].coc, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
661 }
662
663 float bordering_radius = ring_dist + 0.5f;
664 constexpr float isect_mul = 1.0f;
665 DofGatherData bg_ring = {};
667 pair_data, bordering_radius, isect_mul, first_ring, false, false, bg_ring, bg_accum);
668 /* Treat each sample as a ring. */
669 dof_gather_accumulate_sample_ring(bg_ring, 2, first_ring, false, false, bg_accum);
670
671 if (consts.use_lut) {
672 /* Swap distances in order to flip bokeh shape for foreground. */
673 float tmp = pair_data[0].dist;
674 pair_data[0].dist = pair_data[1].dist;
675 pair_data[1].dist = tmp;
676 }
677 DofGatherData fg_ring = {};
679 pair_data, bordering_radius, isect_mul, first_ring, false, true, fg_ring, fg_accum);
680 /* Treat each sample as a ring. */
681 dof_gather_accumulate_sample_ring(fg_ring, 2, first_ring, false, true, fg_accum);
682
683 first_ring = false;
684 }
685
686 /* Center sample. */
687 float2 sample_uv = frag_coord / float2(textureSize(depth_tx, 0));
688 DofGatherData center_data;
689 center_data.color = colorspace::safe_color(textureLod(color_tx, sample_uv, 0.0f));
690 center_data.coc = dof_coc_from_depth(
691 views, dof_buf, sample_uv, reverse_z::read(textureLod(depth_tx, sample_uv, 0.0f).r));
692 center_data.coc = clamp(center_data.coc, -dof_buf.coc_abs_max, dof_buf.coc_abs_max);
693 center_data.dist = 0.0f;
694
695 out_center_coc = center_data.coc;
696
697 /* Slide 38. */
698 float bordering_radius = 0.5f;
699
701 center_data, bordering_radius, i_radius, false, true, true, fg_accum);
703 center_data, bordering_radius, i_radius, false, false, true, bg_accum);
704
705 float4 bg_col, fg_col;
706 float bg_weight, fg_weight;
707 float2 unused_occlusion;
708
709 int total_sample_count = int(sample_count) * 2 + 1;
711 total_sample_count, bg_accum, bg_col, bg_weight, unused_occlusion);
713 total_sample_count, fg_accum, fg_col, fg_weight, unused_occlusion);
714
715 /* Fix weighting issues on perfectly focus to slight focus transitioning areas. */
716 if (abs(center_data.coc) < 0.5f) {
717 bg_col = center_data.color;
718 bg_weight = 1.0f;
719 }
720
721 /* Alpha Over */
722 float alpha = 1.0f - fg_weight;
723 out_weight = bg_weight * alpha + fg_weight;
724 out_color = bg_col * bg_weight * alpha + fg_col * fg_weight;
725 }
726};
727
728} // namespace eevee::dof
729
#define M_PI
btScalar max
#define no_gather_occlusion
#define dof_layer_offset
#define debug_gather_perf
float dof_sample_weight(float coc)
#define dof_max_slight_focus_radius
#define dof_layer_threshold
float dof_layer_weight(float coc, const bool is_foreground, const bool is_resolve)
#define debug_scatter_perf
#define no_smooth_intersection
#define DOF_SLIGHT_FOCUS_DENSITY
#define no_gather_mipmaps
#define no_gather_random
float dof_coc_from_depth(const draw::View &views, DepthOfFieldData dof_data, float2 uv, float depth)
float2 sample_disk(float2 rand)
#define uniform(slot)
#define frag_coord
#define compilation_constant
#define resource_table
#define sampler(slot)
#define static_branch
#define condition(cond)
#define sin
#define round
T fract(T) RET
#define pow
#define cos
#define log2
#define abs
#define floor
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2, false, false, false, true > sampler2DDepth
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
float3 neon_gradient(float t)
float noise(float p)
float square(float v)
float2x2 from_rotation(AngleRadian rotation)
float safe_rcp(float a)
float average(float2 a)
MatBase< float, 2, 2 > float2x2
float4 safe_color(float4 c)
float interleaved_gradient(float2 pixel, float seed, float offset)
float2 hammersley_2d(T i, T sample_count)
T read(T depth_buffer_value)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define saturate(a)
Definition smaa.cc:319
float2 rng_2D_get(const eSamplingDimension dim) const
void dof_slight_focus_gather(float2 frag_coord, sampler2DDepth depth_tx, sampler2D color_tx, sampler2D bkh_lut_tx, float radius, float4 &out_color, float &out_weight, float &out_center_coc)
float dof_gather_accum_weight(float coc, float bordering_radius, bool first_ring)
bool dof_do_density_change(float base_radius, float min_intersectable_radius)
void dof_gather_accumulate_sample(DofGatherData sample_data, float weight, DofGatherData &accum_data)
float dof_load_gather_coc(sampler2D gather_input_coc_tx, float2 uv, float lod)
void dof_gather_accumulate_sample_pair(DofGatherData pair_data[2], float bordering_radius, float intersection_multiplier, bool first_ring, const bool do_fast_gather, const bool foreground, DofGatherData &ring_data, DofGatherData &accum_data)
int dof_gather_total_sample_count(const int ring_count, const int ring_density)
void dof_gather_accumulator(float2 frag_coord, sampler2D color_tx, sampler2D color_bilinear_tx, sampler2D coc_tx, float base_radius, float min_intersectable_radius, const bool do_fast_gather, const bool do_density_change, float4 &out_color, float &out_weight, float2 &out_occlusion)
void dof_gather_init(float2 frag_coord, float base_radius, float2 noise, float2 &center_co, float &lod, float &intersection_multiplier)
void dof_gather_accumulate_resolve(int total_sample_count, DofGatherData accum_data, float4 &out_col, float &out_weight, float2 &out_occlusion)
int dof_gather_total_sample_count_with_density_change(const int ring_count, const int ring_density, int density_change)
void dof_gather_amend_weight(DofGatherData &sample_data, float weight)
float dof_intersection_weight(float coc, float distance_from_center, float intersection_multiplier)
void dof_gather_accumulate_sample_ring(DofGatherData ring_data, int sample_count, bool first_ring, const bool do_fast_gather, const bool reversed_occlusion, DofGatherData &accum_data)
void dof_gather_accumulate_center_sample(DofGatherData center_data, float bordering_radius, int i_radius, const bool do_fast_gather, const bool foreground, const bool resolve, DofGatherData &accum_data)
float x
float y