Blender V5.3
eevee_depth_of_field.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
19
20#pragma once
21
23
24#include "draw_pass.hh"
25
26namespace blender::eevee {
27
28using namespace draw;
29
30class Instance;
31
32/* -------------------------------------------------------------------- */
35
46
49
51
52 private:
53 class Instance &inst_;
54
55 static constexpr GPUSamplerState no_filter = GPUSamplerState::default_sampler();
56 static constexpr GPUSamplerState with_filter = {GPU_SAMPLER_FILTERING_LINEAR};
57
59 gpu::Texture *input_color_tx_ = nullptr;
60 gpu::Texture *output_color_tx_ = nullptr;
61
63 TextureFromPool bokeh_gather_lut_tx_ = {"dof_bokeh_gather_lut"};
64 TextureFromPool bokeh_resolve_lut_tx_ = {"dof_bokeh_resolve_lut"};
65 TextureFromPool bokeh_scatter_lut_tx_ = {"dof_bokeh_scatter_lut"};
66 PassSimple bokeh_lut_ps_ = {"BokehLut"};
67
69 TextureFromPool setup_coc_tx_ = {"dof_setup_coc"};
70 TextureFromPool setup_color_tx_ = {"dof_setup_color"};
71 int3 dispatch_setup_size_ = int3(-1);
72 PassSimple setup_ps_ = {"Setup"};
73
74 /* Reduce buffer mip chains with view texture per level. */
75 TextureFromPool reduced_coc_tx_ = {"dof_reduced_coc"};
76 TextureFromPool reduced_color_tx_ = {"dof_reduced_color"};
77 std::array<gpu::Texture *, DOF_MIP_COUNT> reduced_coc_mip_views_;
78 std::array<gpu::Texture *, DOF_MIP_COUNT> reduced_color_mip_views_;
79
81 TextureFromPool stabilize_output_tx_ = {"dof_taa"};
82 gpu::Texture *stabilize_input_ = nullptr;
83 bool32_t stabilize_valid_history_ = false;
84 int3 dispatch_stabilize_size_ = int3(-1);
85 PassSimple stabilize_ps_ = {"Stabilize"};
86
88 TextureFromPool downsample_tx_ = {"dof_downsample"};
89 int3 dispatch_downsample_size_ = int3(-1);
90 PassSimple downsample_ps_ = {"Downsample"};
91
93 DepthOfFieldScatterListBuf scatter_fg_list_buf_;
94 DepthOfFieldScatterListBuf scatter_bg_list_buf_;
95 DrawIndirectBuf scatter_fg_indirect_buf_;
96 DrawIndirectBuf scatter_bg_indirect_buf_;
97 int3 dispatch_reduce_size_ = int3(-1);
98 PassSimple reduce_ps_ = {"Reduce"};
99
103 int3 dispatch_tiles_flatten_size_ = int3(-1);
104 PassSimple tiles_flatten_ps_ = {"TilesFlatten"};
105
107 int tiles_dilate_ring_count_ = -1;
108 int tiles_dilate_ring_width_mul_ = -1;
109 int3 dispatch_tiles_dilate_size_ = int3(-1);
110 PassSimple tiles_dilate_minmax_ps_ = {"TilesDilateMinmax"};
111 PassSimple tiles_dilate_minabs_ps_ = {"TilesDilateMinabs"};
112
116 SwapChain<TextureFromPool, 2> weight_bg_tx_;
117 SwapChain<TextureFromPool, 2> weight_fg_tx_;
118 TextureFromPool occlusion_tx_ = {"dof_occlusion"};
119 int3 dispatch_gather_size_ = int3(-1);
120 PassSimple gather_fg_ps_ = {"GatherFg"};
121 PassSimple gather_bg_ps_ = {"GatherBg"};
122
124 TextureFromPool hole_fill_color_tx_ = {"dof_color_hole_fill"};
125 TextureFromPool hole_fill_weight_tx_ = {"dof_weight_hole_fill"};
126 PassSimple hole_fill_ps_ = {"HoleFill"};
127
129 int3 dispatch_filter_size_ = int3(-1);
130 PassSimple filter_fg_ps_ = {"FilterFg"};
131 PassSimple filter_bg_ps_ = {"FilterBg"};
132
134 Framebuffer scatter_fg_fb_ = {"dof_scatter_fg"};
135 Framebuffer scatter_bg_fb_ = {"dof_scatter_bg"};
136 PassSimple scatter_fg_ps_ = {"ScatterFg"};
137 PassSimple scatter_bg_ps_ = {"ScatterBg"};
138
140 gpu::Texture *resolve_stable_color_tx_ = nullptr;
141 int3 dispatch_resolve_size_ = int3(-1);
142 PassSimple resolve_ps_ = {"Resolve"};
143
145
147 float user_overblur_ = 0.0f;
148 float fx_max_coc_ = 0.0f;
150 bool do_jitter_ = false;
152 bool use_bokeh_lut_ = false;
153
155 float fx_radius_ = 0.0f;
157 float jitter_radius_ = 0.0f;
159 float focus_distance_ = 0.0f;
161 int2 extent_ = int2(0);
162
163 bool enabled_ = false;
164
165 public:
166 DepthOfField(Instance &inst) : inst_(inst) {};
168
169 void init();
170
171 void sync();
172
176 void jitter_apply(float4x4 &winmat, float4x4 &viewmat);
177
182 void render(View &view,
183 gpu::Texture **input_tx,
184 gpu::Texture **output_tx,
185 DepthOfFieldBuffer &dof_buffer);
186
187 bool postfx_enabled() const
188 {
189 return fx_radius_ > 0.0f;
190 }
191
192 bool enabled() const
193 {
194 return enabled_;
195 }
196
197 private:
198 void bokeh_lut_pass_sync();
199 void setup_pass_sync();
200 void stabilize_pass_sync();
201 void downsample_pass_sync();
202 void reduce_pass_sync();
203 void tiles_flatten_pass_sync();
204 void tiles_dilate_pass_sync();
205 void gather_pass_sync();
206 void filter_pass_sync();
207 void scatter_pass_sync();
208 void hole_fill_pass_sync();
209 void resolve_pass_sync();
210
215 void update_sample_table();
216};
217
219
220} // namespace blender::eevee
int32_t bool32_t
void jitter_apply(float4x4 &winmat, float4x4 &viewmat)
A running instance of the engine.
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageBuffer< DrawCommand, true > DrawIndirectBuf
Definition draw_pass.hh:73
draw::UniformBuffer< DepthOfFieldData > DepthOfFieldDataBuf
draw::StorageArrayBuffer< ScatterRect, 16, true > DepthOfFieldScatterListBuf
@ GPU_SAMPLER_FILTERING_LINEAR
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
static constexpr GPUSamplerState default_sampler()