Blender V5.0
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
39#include "draw_pass.hh"
40
41#include "eevee_film_shared.hh"
43
44#include <sstream>
45
46namespace blender::eevee {
47
48using namespace draw;
49
50class Instance;
51
52/* -------------------------------------------------------------------- */
55
56class Film {
57 public:
61 static constexpr bool use_box_filter = false;
62
70
71 private:
72 Instance &inst_;
73
75 gpu::Texture *combined_final_tx_ = nullptr;
76
78 bool use_compute_ = false;
79
82 std::string ui_aov_name_;
83
88 Texture color_accum_tx_;
89 Texture value_accum_tx_;
91 Texture depth_tx_;
93 Texture cryptomatte_tx_;
95 SwapChain<Texture, 2> combined_tx_;
97 SwapChain<Texture, 2> weight_tx_;
98
99 PassSimple accumulate_ps_ = {"Film.Accumulate"};
100 PassSimple copy_ps_ = {"Film.Copy"};
101 PassSimple cryptomatte_post_ps_ = {"Film.Cryptomatte.Post"};
102
103 FilmData &data_;
104 int2 display_extent = int2(-1);
105
107 /* Store the pass types needed by the viewport compositor separately, because some passes might
108 * be enabled but not used by the viewport compositor, so they needn't be written. */
109 eViewLayerEEVEEPassType viewport_compositor_enabled_passes_ = eViewLayerEEVEEPassType(0);
110 PassCategory enabled_categories_ = PassCategory(0);
111 bool use_reprojection_ = false;
112 bool is_valid_render_extent_ = true;
113
114 public:
115 Film(Instance &inst, FilmData &data) : inst_(inst), data_(data) {};
116 ~Film() {};
117
118 void init(const int2 &full_extent, const rcti *output_rect);
119
120 void sync();
121 void end_sync();
122
124 {
125 return data_;
126 }
127
129 void accumulate(View &view, gpu::Texture *combined_final_tx);
130
132 void cryptomatte_sort();
133
135 void display();
136
137 float *read_pass(eViewLayerEEVEEPassType pass_type, int layer_offset);
138 float *read_aov(ViewLayerAOV *aov);
139
140 gpu::Texture *get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset);
142
144
147 {
148 return data_.render_extent;
149 }
150 inline bool is_valid_render_extent() const
151 {
152 return is_valid_render_extent_;
153 }
154
157 {
158 return data_.extent;
159 }
161 {
162 return data_.offset;
163 }
164
167 {
168 return display_extent;
169 }
170
173 {
174 return data_.overscan;
175 }
176
178 static int overscan_pixels_get(float overscan, int2 extent)
179 {
180 return math::ceil(max_ff(0.0f, overscan) * math::reduce_max(extent));
181 }
182
184 {
185 return data_.scaling_factor;
186 }
187
188 float2 pixel_jitter_get() const;
189
191 {
192 return data_.background_opacity;
193 }
194
196 int cryptomatte_layer_len_get() const;
197
213
222
223 /* Returns layer offset in the accumulation texture. -1 if the pass is not enabled. */
225 {
226 switch (pass_type) {
228 return data_.combined_id;
230 return data_.depth_id;
232 return data_.mist_id;
234 return data_.normal_id;
236 return data_.position_id;
238 return data_.vector_id;
240 return data_.diffuse_light_id;
242 return data_.diffuse_color_id;
244 return data_.specular_light_id;
246 return data_.specular_color_id;
248 return data_.volume_light_id;
250 return data_.emission_id;
252 return data_.environment_id;
254 return data_.shadow_id;
256 return data_.ambient_occlusion_id;
258 return data_.transparent_id;
260 return data_.cryptomatte_object_id;
262 return data_.cryptomatte_asset_id;
264 return data_.cryptomatte_material_id;
265 default:
266 return -1;
267 }
268 }
269
271 const ViewLayer *view_layer)
272 {
274
275 auto build_cryptomatte_passes = [&](const char *pass_name) {
276 const int num_cryptomatte_passes = (view_layer->cryptomatte_levels + 1) / 2;
277 for (int pass = 0; pass < num_cryptomatte_passes; pass++) {
278 std::stringstream ss;
279 ss.fill('0');
280 ss << pass_name;
281 ss.width(2);
282 ss << pass;
283 result.append(ss.str());
284 }
285 };
286
287 switch (pass_type) {
290 break;
293 break;
295 result.append(RE_PASSNAME_MIST);
296 break;
299 break;
302 break;
305 break;
308 break;
311 break;
314 break;
317 break;
320 break;
322 result.append(RE_PASSNAME_EMIT);
323 break;
326 break;
329 break;
331 result.append(RE_PASSNAME_AO);
332 break;
335 break;
337 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_OBJECT);
338 break;
340 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_ASSET);
341 break;
343 build_cryptomatte_passes(RE_PASSNAME_CRYPTOMATTE_MATERIAL);
344 break;
345 default:
346 BLI_assert(0);
347 break;
348 }
349 return result;
350 }
351
352 private:
353 void init_aovs(const Set<std::string> &passes_used_by_viewport_compositor);
354 void sync_mist();
355
359 void update_sample_table();
360
361 void init_pass(PassSimple &pass, gpu::Shader *sh);
362};
363
365
366} // 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_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_DEPTH
@ 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_DEPTH
#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_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)
gpu::Texture * get_pass_texture(eViewLayerEEVEEPassType pass_type, int layer_offset)
struct blender::eevee::Film::DepthState depth
int scaling_factor_get() const
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
void accumulate(View &view, gpu::Texture *combined_final_tx)
float * read_aov(ViewLayerAOV *aov)
StorageBuffer< AOVsInfoData > aovs_info
Definition eevee_film.hh:59
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:61
gpu::Texture * get_aov_texture(ViewLayerAOV *aov)
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
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