Blender V5.3
eevee_depth_of_field_gather.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
9
10namespace eevee::dof {
11
22
35namespace gather {
36
40
41[[compute, local_size(DOF_GATHER_GROUP_SIZE, DOF_GATHER_GROUP_SIZE)]]
44 [[resource_table]] const Tiles &tiles,
45 [[global_invocation_id]] const uint3 global_id)
46{
47 [[resource_table]] Accumulator &accum = gather.accumulator;
48
49 int2 tile_co = int2(global_id.xy / DOF_TILES_SIZE);
50 CocTile coc_tile = dof_coc_tile_load(tiles.in_tiles_fg_img, tiles.in_tiles_bg_img, tile_co);
51 CocTilePrediction prediction = dof_coc_tile_prediction_get(coc_tile, false);
52
53 float base_radius, min_radius, min_intersectable_radius;
54 bool can_early_out;
55 if (gather.accumulator.consts.is_foreground) {
56 base_radius = -coc_tile.fg_min_coc;
57 min_radius = -coc_tile.fg_max_coc;
58 min_intersectable_radius = -coc_tile.fg_max_intersectable_coc;
59 can_early_out = !prediction.do_foreground;
60 }
61 else {
62 base_radius = coc_tile.bg_max_coc;
63 min_radius = coc_tile.bg_min_coc;
64 min_intersectable_radius = coc_tile.bg_min_intersectable_coc;
65 can_early_out = !prediction.do_background;
66 }
67
68 bool do_fast_gather = dof_do_fast_gather(
69 base_radius, min_radius, accum.consts.is_foreground, false);
70
71 /* Gather at half resolution. Divide CoC by 2. */
72 base_radius *= 0.5f;
73 min_intersectable_radius *= 0.5f;
74
75 bool do_density_change = accum.dof_do_density_change(base_radius, min_intersectable_radius);
76
77 float4 out_color;
78 float out_weight;
79 float2 out_occlusion;
80
81 if (can_early_out) {
82 out_color = float4(0.0f);
83 out_weight = 0.0f;
84 out_occlusion = float2(0.0f, 0.0f);
85 }
86 else if (do_fast_gather) {
87 accum.dof_gather_accumulator(float2(global_id.xy),
88 gather.color_tx,
89 gather.color_bilinear_tx,
90 gather.coc_tx,
91 base_radius,
92 min_intersectable_radius,
93 true,
94 false,
95 out_color,
96 out_weight,
97 out_occlusion);
98 }
99 else if (do_density_change) {
100 accum.dof_gather_accumulator(float2(global_id.xy),
101 gather.color_tx,
102 gather.color_bilinear_tx,
103 gather.coc_tx,
104 base_radius,
105 min_intersectable_radius,
106 false,
107 true,
108 out_color,
109 out_weight,
110 out_occlusion);
111 }
112 else {
113 accum.dof_gather_accumulator(float2(global_id.xy),
114 gather.color_tx,
115 gather.color_bilinear_tx,
116 gather.coc_tx,
117 base_radius,
118 min_intersectable_radius,
119 false,
120 false,
121 out_color,
122 out_weight,
123 out_occlusion);
124 }
125
126 int2 out_texel = int2(global_id.xy);
127 imageStore(gather.out_color_img, out_texel, out_color);
128 imageStore(gather.out_weight_img, out_texel, float4(out_weight));
129 imageStore(srt.out_occlusion_img, out_texel, out_occlusion.xyxy);
130}
131
132} // namespace gather
133
143namespace hole_fill {
144
145[[compute, local_size(DOF_GATHER_GROUP_SIZE, DOF_GATHER_GROUP_SIZE)]]
147 [[resource_table]] const Tiles &tiles,
148 [[global_invocation_id]] const uint3 global_id)
149{
150 [[resource_table]] Accumulator &accum = gather.accumulator;
151
152 int2 tile_co = int2(global_id.xy / DOF_TILES_SIZE);
153 CocTile coc_tile = dof_coc_tile_load(tiles.in_tiles_fg_img, tiles.in_tiles_bg_img, tile_co);
154 CocTilePrediction prediction = dof_coc_tile_prediction_get(coc_tile, false);
155
156 float base_radius = -coc_tile.fg_min_coc;
157 float min_radius = -coc_tile.fg_max_coc;
158 float min_intersectable_radius = dof_tile_large_coc;
159 bool can_early_out = !prediction.do_hole_fill;
160
161 bool do_fast_gather = dof_do_fast_gather(
162 base_radius, min_radius, accum.consts.is_foreground, false);
163
164 /* Gather at half resolution. Divide CoC by 2. */
165 base_radius *= 0.5f;
166 min_intersectable_radius *= 0.5f;
167
168 float4 out_color = float4(0.0f);
169 float out_weight = 0.0f;
170 float2 unused_occlusion = float2(0.0f, 0.0f);
171
172 if (can_early_out) {
173 /* Early out. */
174 }
175 else if (do_fast_gather) {
176 accum.dof_gather_accumulator(float2(global_id.xy),
177 gather.color_tx,
178 gather.color_bilinear_tx,
179 gather.coc_tx,
180 base_radius,
181 min_intersectable_radius,
182 true,
183 false,
184 out_color,
185 out_weight,
186 unused_occlusion);
187 }
188 else {
189 accum.dof_gather_accumulator(float2(global_id.xy),
190 gather.color_tx,
191 gather.color_bilinear_tx,
192 gather.coc_tx,
193 base_radius,
194 min_intersectable_radius,
195 false,
196 false,
197 out_color,
198 out_weight,
199 unused_occlusion);
200 }
201
202 int2 out_texel = int2(global_id.xy);
203 imageStore(gather.out_color_img, out_texel, out_color);
204 imageStore(gather.out_weight_img, out_texel, float4(out_weight));
205}
206
207} // namespace hole_fill
208
209} // namespace eevee::dof
210
213 .is_hole_fill = false,
214 .is_resolve = false,
215 .is_foreground = false,
216 .use_lut = true,
217 });
220 .is_hole_fill = false,
221 .is_resolve = false,
222 .is_foreground = false,
223 .use_lut = false,
224 });
227 .is_hole_fill = false,
228 .is_resolve = false,
229 .is_foreground = true,
230 .use_lut = true,
231 });
234 .is_hole_fill = false,
235 .is_resolve = false,
236 .is_foreground = true,
237 .use_lut = false,
238 });
239
242 .is_hole_fill = true,
243 .is_resolve = false,
244 .is_foreground = false,
245 .use_lut = false,
246 });
PipelineCompute eevee_depth_of_field_hole_fill(eevee::dof::hole_fill::comp_main, eevee::dof::AccumulatorConstants{ .is_hole_fill=true,.is_resolve=false,.is_foreground=false,.use_lut=false, })
PipelineCompute eevee_depth_of_field_gather_background_no_lut(eevee::dof::gather::comp_main, eevee::dof::AccumulatorConstants{ .is_hole_fill=false,.is_resolve=false,.is_foreground=false,.use_lut=false, })
PipelineCompute eevee_depth_of_field_gather_foreground_lut(eevee::dof::gather::comp_main, eevee::dof::AccumulatorConstants{ .is_hole_fill=false,.is_resolve=false,.is_foreground=true,.use_lut=true, })
PipelineCompute eevee_depth_of_field_gather_background_lut(eevee::dof::gather::comp_main, eevee::dof::AccumulatorConstants{ .is_hole_fill=false,.is_resolve=false,.is_foreground=false,.use_lut=true, })
PipelineCompute eevee_depth_of_field_gather_foreground_no_lut(eevee::dof::gather::comp_main, eevee::dof::AccumulatorConstants{ .is_hole_fill=false,.is_resolve=false,.is_foreground=true,.use_lut=false, })
bool dof_do_fast_gather(float max_absolute_coc, float min_absolute_coc, const bool is_foreground, const bool is_resolve)
CocTilePrediction dof_coc_tile_prediction_get(CocTile tile, const bool is_resolve)
CocTile dof_coc_tile_load(image2D tiles_fg_img, image2D tiles_bg_img, int2 texel)
@ SFLOAT_16_16_16_16
#define image(slot, qualifiers, format)
#define resource_table
#define sampler(slot)
#define global_invocation_id
#define compute
#define local_size(...)
ImageBase< float, 2 > image2D
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
SamplerBase< float, 2 > sampler2D
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
void comp_main(Resources &srt, Gather &gather, const Tiles &tiles, const uint3 global_id)
void comp_main(Gather &gather, const Tiles &tiles, const uint3 global_id)
bool dof_do_density_change(float base_radius, float min_intersectable_radius)
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)