Blender V5.0
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
75 Texture reduced_coc_tx_ = {"dof_reduced_coc"};
76 Texture reduced_color_tx_ = {"dof_reduced_color"};
77
79 TextureFromPool stabilize_output_tx_ = {"dof_taa"};
80 gpu::Texture *stabilize_input_ = nullptr;
81 bool32_t stabilize_valid_history_ = false;
82 int3 dispatch_stabilize_size_ = int3(-1);
83 PassSimple stabilize_ps_ = {"Stabilize"};
84
86 TextureFromPool downsample_tx_ = {"dof_downsample"};
87 int3 dispatch_downsample_size_ = int3(-1);
88 PassSimple downsample_ps_ = {"Downsample"};
89
91 DepthOfFieldScatterListBuf scatter_fg_list_buf_;
92 DepthOfFieldScatterListBuf scatter_bg_list_buf_;
93 DrawIndirectBuf scatter_fg_indirect_buf_;
94 DrawIndirectBuf scatter_bg_indirect_buf_;
95 int3 dispatch_reduce_size_ = int3(-1);
96 PassSimple reduce_ps_ = {"Reduce"};
97
101 int3 dispatch_tiles_flatten_size_ = int3(-1);
102 PassSimple tiles_flatten_ps_ = {"TilesFlatten"};
103
105 int tiles_dilate_ring_count_ = -1;
106 int tiles_dilate_ring_width_mul_ = -1;
107 int3 dispatch_tiles_dilate_size_ = int3(-1);
108 PassSimple tiles_dilate_minmax_ps_ = {"TilesDilateMinmax"};
109 PassSimple tiles_dilate_minabs_ps_ = {"TilesDilateMinabs"};
110
114 SwapChain<TextureFromPool, 2> weight_bg_tx_;
115 SwapChain<TextureFromPool, 2> weight_fg_tx_;
116 TextureFromPool occlusion_tx_ = {"dof_occlusion"};
117 int3 dispatch_gather_size_ = int3(-1);
118 PassSimple gather_fg_ps_ = {"GatherFg"};
119 PassSimple gather_bg_ps_ = {"GatherBg"};
120
122 TextureFromPool hole_fill_color_tx_ = {"dof_color_hole_fill"};
123 TextureFromPool hole_fill_weight_tx_ = {"dof_weight_hole_fill"};
124 PassSimple hole_fill_ps_ = {"HoleFill"};
125
127 int3 dispatch_filter_size_ = int3(-1);
128 PassSimple filter_fg_ps_ = {"FilterFg"};
129 PassSimple filter_bg_ps_ = {"FilterBg"};
130
132 Framebuffer scatter_fg_fb_ = {"dof_scatter_fg"};
133 Framebuffer scatter_bg_fb_ = {"dof_scatter_bg"};
134 PassSimple scatter_fg_ps_ = {"ScatterFg"};
135 PassSimple scatter_bg_ps_ = {"ScatterBg"};
136
138 gpu::Texture *resolve_stable_color_tx_ = nullptr;
139 int3 dispatch_resolve_size_ = int3(-1);
140 PassSimple resolve_ps_ = {"Resolve"};
141
143
145 float user_overblur_ = 0.0f;
146 float fx_max_coc_ = 0.0f;
148 bool do_jitter_ = false;
150 bool use_bokeh_lut_ = false;
151
153 float fx_radius_ = 0.0f;
155 float jitter_radius_ = 0.0f;
157 float focus_distance_ = 0.0f;
159 int2 extent_ = int2(0);
160
161 bool enabled_ = false;
162
163 public:
164 DepthOfField(Instance &inst) : inst_(inst) {};
166
167 void init();
168
169 void sync();
170
174 void jitter_apply(float4x4 &winmat, float4x4 &viewmat);
175
180 void render(View &view,
181 gpu::Texture **input_tx,
182 gpu::Texture **output_tx,
183 DepthOfFieldBuffer &dof_buffer);
184
185 bool postfx_enabled() const
186 {
187 return fx_radius_ > 0.0f;
188 }
189
190 bool enabled() const
191 {
192 return enabled_;
193 }
194
195 private:
196 void bokeh_lut_pass_sync();
197 void setup_pass_sync();
198 void stabilize_pass_sync();
199 void downsample_pass_sync();
200 void reduce_pass_sync();
201 void tiles_flatten_pass_sync();
202 void tiles_dilate_pass_sync();
203 void gather_pass_sync();
204 void filter_pass_sync();
205 void scatter_pass_sync();
206 void hole_fill_pass_sync();
207 void resolve_pass_sync();
208
213 void update_sample_table();
214};
215
217
218} // namespace blender::eevee
static AppView * view
int32_t bool32_t
@ GPU_SAMPLER_FILTERING_LINEAR
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:71
draw::UniformBuffer< DepthOfFieldData > DepthOfFieldDataBuf
draw::StorageArrayBuffer< ScatterRect, 16, true > DepthOfFieldScatterListBuf
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< int32_t, 3 > int3
static constexpr GPUSamplerState default_sampler()