Blender V4.5
eevee_film.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
28
29#pragma once
30
31#include <string>
32
33#include "BLI_math_vector.hh"
34#include "BLI_set.hh"
35
36#include "DNA_scene_types.h"
37#include "DRW_render.hh"
38
40
41#include <sstream>
42
43namespace blender::eevee {
44
45class Instance;
46
47/* -------------------------------------------------------------------- */
50
51class Film {
52 public:
56 static constexpr bool use_box_filter = false;
57
65
66 private:
67 Instance &inst_;
68
70 GPUTexture *combined_final_tx_ = nullptr;
71
73 bool use_compute_;
74
77 std::string ui_aov_name_;
78
83 Texture color_accum_tx_;
84 Texture value_accum_tx_;
86 Texture depth_tx_;
88 Texture cryptomatte_tx_;
90 SwapChain<Texture, 2> combined_tx_;
92 SwapChain<Texture, 2> weight_tx_;
93
94 PassSimple accumulate_ps_ = {"Film.Accumulate"};
95 PassSimple copy_ps_ = {"Film.Copy"};
96 PassSimple cryptomatte_post_ps_ = {"Film.Cryptomatte.Post"};
97
98 FilmData &data_;
99 int2 display_extent;
100
102 /* Store the pass types needed by the viewport compositor separately, because some passes might
103 * be enabled but not used by the viewport compositor, so they needn't be written. */
104 eViewLayerEEVEEPassType viewport_compositor_enabled_passes_ = eViewLayerEEVEEPassType(0);
105 PassCategory enabled_categories_ = PassCategory(0);
106 bool use_reprojection_ = false;
107 bool is_valid_render_extent_ = true;
108
109 public:
110 Film(Instance &inst, FilmData &data) : inst_(inst), data_(data){};
111 ~Film(){};
112
113 void init(const int2 &full_extent, const rcti *output_rect);
114
115 void sync();
116 void end_sync();
117
119 {
120 return data_;
121 }
122
124 void accumulate(View &view, GPUTexture *combined_final_tx);
125
127 void cryptomatte_sort();
128
130 void display();
131
132 float *read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset);
133 float *read_aov(ViewLayerAOV *aov);
134
135 GPUTexture *get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset);
136 GPUTexture *get_aov_texture(ViewLayerAOV *aov);
137
139
142 {
143 return data_.render_extent;
144 }
145 inline bool is_valid_render_extent() const
146 {
147 return is_valid_render_extent_;
148 }
149
152 {
153 return data_.extent;
154 }
156 {
157 return data_.offset;
158 }
159
162 {
163 return display_extent;
164 }
165
168 {
169 return data_.overscan;
170 }
171
173 static int overscan_pixels_get(float overscan, int2 extent)
174 {
175 return math::ceil(max_ff(0.0f, overscan) * math::reduce_max(extent));
176 }
177
179 {
180 return data_.scaling_factor;
181 }
182
183 float2 pixel_jitter_get() const;
184
186 {
187 return data_.background_opacity;
188 }
189
191 int cryptomatte_layer_len_get() const;
192
208
217
218 /* Returns layer offset in the accumulation texture. -1 if the pass is not enabled. */
220 {
221 switch (pass_type) {
223 return data_.combined_id;
225 return data_.depth_id;
227 return data_.mist_id;
229 return data_.normal_id;
231 return data_.position_id;
233 return data_.vector_id;
235 return data_.diffuse_light_id;
237 return data_.diffuse_color_id;
239 return data_.specular_light_id;
241 return data_.specular_color_id;
243 return data_.volume_light_id;
245 return data_.emission_id;
247 return data_.environment_id;
249 return data_.shadow_id;
251 return data_.ambient_occlusion_id;
253 return data_.transparent_id;
255 return data_.cryptomatte_object_id;
257 return data_.cryptomatte_asset_id;
259 return data_.cryptomatte_material_id;
260 default:
261 return -1;
262 }
263 }
264
266 const ViewLayer *view_layer)
267 {
269
270 auto build_cryptomatte_passes = [&](const char *pass_name) {
271 const int num_cryptomatte_passes = (view_layer->cryptomatte_levels + 1) / 2;
272 for (int pass = 0; pass < num_cryptomatte_passes; pass++) {
273 std::stringstream ss;
274 ss.fill('0');
275 ss << pass_name;
276 ss.width(2);
277 ss << pass;
278 result.append(ss.str());
279 }
280 };
281
282 switch (pass_type) {
285 break;
287 result.append(RE_PASSNAME_Z);
288 break;
290 result.append(RE_PASSNAME_MIST);
291 break;
294 break;
297 break;
300 break;
303 break;
306 break;
309 break;
312 break;
315 break;
317 result.append(RE_PASSNAME_EMIT);
318 break;
321 break;
324 break;
326 result.append(RE_PASSNAME_AO);
327 break;
330 break;
332 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_OBJECT);
333 break;
335 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_ASSET);
336 break;
338 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_MATERIAL);
339 break;
340 default:
341 BLI_assert(0);
342 break;
343 }
344 return result;
345 }
346
347 private:
348 void init_aovs(const Set<std::string> &passes_used_by_viewport_compositor);
349 void sync_mist();
350
354 void update_sample_table();
355
356 void init_pass(PassSimple &pass, GPUShader *sh);
357};
358
360
361} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
MINLINE float max_ff(float a, float b)
#define ELEM(...)
eViewLayerEEVEEPassType
@ EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL
@ EEVEE_RENDER_PASS_AO
@ EEVEE_RENDER_PASS_NORMAL
@ EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT
@ EEVEE_RENDER_PASS_DIFFUSE_LIGHT
@ EEVEE_RENDER_PASS_VOLUME_LIGHT
@ EEVEE_RENDER_PASS_DIFFUSE_COLOR
@ EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET
@ EEVEE_RENDER_PASS_Z
@ EEVEE_RENDER_PASS_ENVIRONMENT
@ EEVEE_RENDER_PASS_COMBINED
@ EEVEE_RENDER_PASS_SPECULAR_LIGHT
@ EEVEE_RENDER_PASS_VECTOR
@ EEVEE_RENDER_PASS_SPECULAR_COLOR
@ EEVEE_RENDER_PASS_EMIT
@ EEVEE_RENDER_PASS_MIST
@ EEVEE_RENDER_PASS_TRANSPARENT
@ EEVEE_RENDER_PASS_SHADOW
@ EEVEE_RENDER_PASS_POSITION
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_CRYPTOMATTE_MATERIAL
#define RE_PASSNAME_NORMAL
#define RE_PASSNAME_CRYPTOMATTE_ASSET
#define RE_PASSNAME_VECTOR
#define RE_PASSNAME_EMIT
#define RE_PASSNAME_GLOSSY_COLOR
#define RE_PASSNAME_GLOSSY_DIRECT
#define RE_PASSNAME_SHADOW
#define RE_PASSNAME_MIST
#define RE_PASSNAME_ENVIRONMENT
#define RE_PASSNAME_POSITION
#define RE_PASSNAME_DIFFUSE_COLOR
#define RE_PASSNAME_AO
#define RE_PASSNAME_Z
#define RE_PASSNAME_VOLUME_LIGHT
#define RE_PASSNAME_CRYPTOMATTE_OBJECT
#define RE_PASSNAME_TRANSPARENT
#define RE_PASSNAME_DIFFUSE_DIRECT
static AppView * view
BMesh const char void * data
void init()
float2 pixel_jitter_get() const
int2 film_offset_get() const
int2 display_extent_get() const
int render_overscan_get() const
int pass_id_get(eViewLayerEEVEEPassType pass_type) const
static bool pass_is_float3(eViewLayerEEVEEPassType pass_type)
struct blender::eevee::Film::DepthState depth
GPUTexture * get_aov_texture(ViewLayerAOV *aov)
int scaling_factor_get() const
void accumulate(View &view, GPUTexture *combined_final_tx)
static const Vector< std::string > pass_to_render_pass_names(eViewLayerEEVEEPassType pass_type, const ViewLayer *view_layer)
int cryptomatte_layer_len_get() const
static ePassStorageType pass_storage_type(eViewLayerEEVEEPassType pass_type)
float * read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset)
bool is_valid_render_extent() const
int2 film_extent_get() const
void write_viewport_compositor_passes()
static int overscan_pixels_get(float overscan, int2 extent)
const FilmData & get_data()
int2 render_extent_get() const
AOVsInfoDataBuf aovs_info
Definition eevee_film.hh:54
float * read_aov(ViewLayerAOV *aov)
GPUTexture * get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset)
eViewLayerEEVEEPassType enabled_passes_get() const
Film(Instance &inst, FilmData &data)
float background_opacity_get() const
static constexpr bool use_box_filter
Definition eevee_film.hh:56
A running instance of the engine.
DRWState
Definition draw_state.hh:25
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageBuffer< AOVsInfoData > AOVsInfoDataBuf
T reduce_max(const VecBase< T, Size > &a)
T ceil(const T &a)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
short cryptomatte_levels