Blender V5.3
sync.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "BKE_appdir.hh"
6#include "BKE_geometry_set.hh"
7#include "BKE_object_types.hh"
8#include "BKE_scene.hh"
10#include "DNA_scene_types.h"
11#include "DNA_userdef_types.h"
12#include "DNA_world_types.h"
13#include "RE_engine.h"
14#include "RNA_prototypes.hh"
15#include "RNA_types.hh"
16
17#include "scene/background.h"
18#include "scene/bake.h"
19#include "scene/camera.h"
20#include "scene/curves.h"
21#include "scene/film.h"
22#include "scene/integrator.h"
23#include "scene/light.h"
24#include "scene/mesh.h"
25#include "scene/object.h"
26#include "scene/procedural.h"
27#include "scene/scene.h"
28#include "scene/shader.h"
29#include "scene/shader_graph.h"
30#include "scene/shader_nodes.h"
31
32#include "device/device.h"
33
34#include "blender/device.h"
35#include "blender/session.h"
36#include "blender/sync.h"
37#include "blender/util.h"
38
39#include "integrator/denoiser.h"
40
41#include "util/debug.h"
42
43#include "util/hash.h"
44#include "util/log.h"
45
47
48static const char *cryptomatte_prefix = "Crypto";
49
50/* Constructor */
51
53 blender::Main &b_data,
54 blender::Scene &b_scene,
55 Scene *scene,
56 bool preview,
57 bool use_developer_ui,
58 Progress &progress)
59 : b_engine(&b_engine),
60 b_data(&b_data),
61 b_scene(&b_scene),
62 b_bake_target(nullptr),
63 shader_map(scene),
64 object_map(scene),
65 procedural_map(scene),
66 geometry_map(scene),
67 particle_system_map(scene),
68 world_map(nullptr),
69 world_recalc(false),
70 scene(scene),
71 preview(preview),
72 use_developer_ui(use_developer_ui),
73 dicing_rate(1.0f),
74 max_subdivisions(12),
75 progress(progress)
76
77{
78 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene.id);
79 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
80 dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate") :
81 RNA_float_get(&cscene, "dicing_rate");
82 max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
83}
84
86
88{
89 /* Update data and scene pointers in case they change in session reset,
90 * for example after undo.
91 * Note that we do not modify the `has_updates_` flag here because the sync
92 * reset is also used during viewport navigation. */
93 this->b_data = &b_data;
94 this->b_scene = &b_scene;
95}
96
98{
99 has_updates_ = true;
100}
101
103{
104 b_bake_target = &b_object;
105}
106
107/* Sync */
108
109void BlenderSync::sync_recalc(blender::Depsgraph &b_depsgraph,
110 blender::bScreen *b_screen,
111 blender::View3D *b_v3d,
112 blender::RegionView3D *b_rv3d)
113{
114 /* Sync recalc flags from blender to cycles. Actual update is done separate,
115 * so we can do it later on if doing it immediate is not suitable. */
116 blender::Object *b_dicing_camera_object = get_dicing_camera_object(b_v3d, b_rv3d);
117 bool dicing_camera_updated = false;
118
119 /* Iterate over all IDs in this depsgraph. */
120 blender::DEGIDIterData deg_iter_data{};
121 deg_iter_data.graph = &b_depsgraph;
122 deg_iter_data.only_updated = true;
126 &deg_iter_data,
127 blender::ID *,
128 b_id)
129 {
130 /* TODO(sergey): Can do more selective filter here. For example, ignore changes made to
131 * screen data-block. Note that sync_data() needs to be called after object deletion, and
132 * currently this is ensured by the scene ID tagged for update, which sets the `has_updates_`
133 * flag. */
134 has_updates_ = true;
135
136 const bool updated_shading = ((b_id->recalc & (blender::ID_RECALC_SHADING |
138
139 /* Material */
140 if (b_id->id_type() == blender::ID_MA) {
141 shader_map.set_recalc(b_id);
142 }
143 /* Light */
144 else if (b_id->id_type() == blender::ID_LA) {
145 shader_map.set_recalc(b_id);
146 geometry_map.set_recalc(b_id);
147 }
148 /* Object */
149 else if (b_id->id_type() == blender::ID_OB) {
150 blender::Object *b_ob = blender::id_cast<blender::Object *>(b_id);
151 const bool can_have_geometry = object_can_have_geometry(*b_ob);
152 const bool is_light = !can_have_geometry && object_is_light(*b_ob);
153
154 if (((b_ob->transflag & blender::OB_DUPLI) != 0) && updated_shading) {
155 /* Needed for object color updates on instancer, among other things. */
156 object_map.set_recalc(b_ob);
157 }
158
159 if (can_have_geometry || is_light) {
160 const bool updated_geometry = (b_id->recalc & blender::ID_RECALC_GEOMETRY) != 0 ||
161 (b_ob->data &&
162 (b_ob->data->recalc & blender::ID_RECALC_ALL) != 0);
163 const bool updated_transform = (b_id->recalc & blender::ID_RECALC_TRANSFORM) != 0;
164
165 /* Geometry (mesh, hair, volume). */
166 if (can_have_geometry) {
167 if (updated_transform || updated_shading) {
168 object_map.set_recalc(b_ob);
169 }
170
171 const bool use_adaptive_subdiv = object_subdivision_type(
172 *b_ob, preview, use_adaptive_subdivision) !=
174
175 /* Need to recompute geometry if the geometry changed, or the transform changed
176 * and using adaptive subdivision. */
177 if (updated_geometry || (updated_transform && use_adaptive_subdiv)) {
178 blender::ID *key = BKE_object_is_modified(*b_ob) ?
179 &b_ob->id :
180 object_get_data(*b_ob, use_adaptive_subdiv);
181 geometry_map.set_recalc(key);
182
183 /* Sync all contained geometry instances as well when the object changed.. */
184 const map<void *, set<blender::ID *>>::const_iterator instance_geometries =
185 instance_geometries_by_object.find(b_ob);
186 if (instance_geometries != instance_geometries_by_object.end()) {
187 for (blender::ID *geometry : instance_geometries->second) {
188 geometry_map.set_recalc(geometry);
189 }
190 }
191 }
192
193 if (updated_geometry) {
194 if (!b_ob->particlesystem.is_empty()) {
195 particle_system_map.set_recalc(b_ob);
196 }
197 }
198 }
199 /* Light */
200 else if (is_light) {
201 if (updated_transform || updated_shading) {
202 object_map.set_recalc(b_ob);
203 geometry_map.set_recalc(b_ob);
204 }
205
206 if (updated_geometry) {
207 geometry_map.set_recalc(b_ob);
208 }
209 }
210 }
211 else if (object_is_camera(*b_ob)) {
212 shader_map.set_recalc(b_ob);
213 }
214
215 if (b_dicing_camera_object == b_ob) {
216 dicing_camera_updated = true;
217 }
218 }
219 /* Mesh */
220 else if (b_id->id_type() == blender::ID_ME) {
221 geometry_map.set_recalc(b_id);
222 }
223 /* World */
224 else if (b_id->id_type() == blender::ID_WO) {
225 const blender::World *b_world = blender::id_cast<blender::World *>(b_id);
226 if (world_map == b_world) {
227 world_recalc = true;
228 }
229 shader_map.set_recalc(b_id);
230 }
231 /* Scene */
232 else if (b_id->id_type() == blender::ID_SCE) {
233 shader_map.set_recalc(b_id);
234 }
235 /* Volume */
236 else if (b_id->id_type() == blender::ID_VO) {
237 geometry_map.set_recalc(b_id);
238 }
239 /* Camera */
240 else if (b_id->id_type() == blender::ID_CA) {
241 if (b_dicing_camera_object && b_dicing_camera_object->data == b_id) {
242 dicing_camera_updated = true;
243 }
244 }
245 }
246 ITER_END;
247
248 if (use_adaptive_subdivision) {
249 /* Mark all meshes as needing to be exported again if dicing changed. */
250 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene->id);
251 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
252 bool dicing_prop_changed = false;
253
254 const float updated_dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate") :
255 RNA_float_get(&cscene, "dicing_rate");
256
257 if (dicing_rate != updated_dicing_rate) {
258 dicing_rate = updated_dicing_rate;
259 dicing_prop_changed = true;
260 }
261
262 const int updated_max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
263
264 if (max_subdivisions != updated_max_subdivisions) {
265 max_subdivisions = updated_max_subdivisions;
266 dicing_prop_changed = true;
267 }
268
269 if ((dicing_camera_updated && !region_view3d_navigating_or_transforming(b_rv3d)) ||
270 dicing_prop_changed)
271 {
272 has_updates_ = true;
273
274 for (const pair<const GeometryKey, Geometry *> &iter : geometry_map.key_to_scene_data()) {
275 Geometry *geom = iter.second;
276 if (geom->is_mesh()) {
277 Mesh *mesh = static_cast<Mesh *>(geom);
278 if (mesh->get_subdivision_type() != Mesh::SUBDIVISION_NONE) {
279 geometry_map.set_recalc(iter.first.id);
280 }
281 }
282 }
283 }
284 }
285
286 if (b_v3d) {
287 const BlenderViewportParameters new_viewport_parameters(b_screen, b_v3d, use_developer_ui);
288
289 if (viewport_parameters.shader_modified(new_viewport_parameters)) {
290 world_recalc = true;
291 has_updates_ = true;
292 }
293
294 has_updates_ |= viewport_parameters.modified(new_viewport_parameters);
295 }
296}
297
299 blender::Depsgraph &b_depsgraph,
300 blender::bScreen *b_screen,
301 blender::View3D *b_v3d,
302 blender::RegionView3D *b_rv3d,
303 const int width,
304 const int height,
305 const DeviceInfo &denoise_device_info)
306{
307 /* For auto refresh images. */
308 ImageManager *image_manager = scene->image_manager.get();
309 const float frame = BKE_scene_frame_get(b_scene);
310 const bool frame_update = frame_last_synced != frame;
311 const bool auto_refresh_update = image_manager->set_animation_frame_update(frame);
312
313 if (frame_update) {
314 frame_last_synced = frame;
315 has_updates_ = true;
316 }
317
318 if (!has_updates_ && !auto_refresh_update) {
319 return;
320 }
321
322 const scoped_timer timer;
323
324 blender::ViewLayer &b_view_layer = *DEG_get_evaluated_view_layer(&b_depsgraph);
325
326 /* TODO(sergey): This feels weak to pass view layer to the integrator, and even weaker to have an
327 * implicit check on whether it is a background render or not. What is the nicer thing here? */
328 const bool background = !b_v3d;
329
331 sync_view_layer(b_view_layer);
332 sync_integrator(b_view_layer, background, denoise_device_info);
333 sync_film(b_view_layer, b_screen, b_v3d);
334 sync_shaders(b_depsgraph, b_screen, b_v3d, auto_refresh_update, frame_update);
335 sync_images();
336
337 geometry_synced.clear(); /* use for objects and motion sync */
338
339 sync_objects_and_motion(b_render, b_depsgraph, b_screen, b_v3d, b_rv3d, width, height);
340
341 geometry_synced.clear();
342
343 /* Shader sync done at the end, since object sync uses it.
344 * false = don't delete unused shaders, not supported. */
345 shader_map.post_sync(false);
346
347 LOG_INFO << "Total time spent synchronizing data: " << timer.get_time();
348
349 has_updates_ = false;
350}
351
352/* Integrator */
353
355 bool background,
356 const DeviceInfo &denoise_device_info)
357{
358 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene->id);
359 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
360
361 /* No adaptive subdivision for baking, mesh needs to match Blender exactly. */
362 use_adaptive_subdivision = !b_bake_target;
363
364 Integrator *integrator = scene->integrator;
365
366 integrator->set_min_bounce(get_int(cscene, "min_light_bounces"));
367 integrator->set_max_bounce(get_int(cscene, "max_bounces"));
368
369 integrator->set_max_diffuse_bounce(get_int(cscene, "diffuse_bounces"));
370 integrator->set_max_glossy_bounce(get_int(cscene, "glossy_bounces"));
371 integrator->set_max_transmission_bounce(get_int(cscene, "transmission_bounces"));
372 integrator->set_max_volume_bounce(get_int(cscene, "volume_bounces"));
373 integrator->set_transparent_min_bounce(get_int(cscene, "min_transparent_bounces"));
374 integrator->set_transparent_max_bounce(get_int(cscene, "transparent_max_bounces"));
375
376 integrator->set_volume_ray_marching(get_boolean(cscene, "volume_biased"));
377 integrator->set_volume_max_steps(get_int(cscene, "volume_max_steps"));
378 const float volume_step_rate = (preview) ? get_float(cscene, "volume_preview_step_rate") :
379 get_float(cscene, "volume_step_rate");
380 integrator->set_volume_step_rate(volume_step_rate);
381
382 integrator->set_caustics_reflective(get_boolean(cscene, "caustics_reflective"));
383 integrator->set_caustics_refractive(get_boolean(cscene, "caustics_refractive"));
384 integrator->set_filter_glossy(get_float(cscene, "blur_glossy"));
385
386 integrator->set_use_pixel_jitter(get_boolean(cscene, "use_pixel_jitter"));
387
388 bool use_custom_pixel_jitter_sample = false;
389 blender::PropertyRNA *override_pixel_jitter_sample_prop = RNA_struct_find_property(
390 &scene_rna_ptr, "[\"override_pixel_jitter_sample\"]");
391 if (override_pixel_jitter_sample_prop) {
392 const int array_length = RNA_property_array_length(&scene_rna_ptr,
393 override_pixel_jitter_sample_prop);
394 if (array_length == 2) {
395 array<float> pixel_jitter_sample_arr(2);
396 RNA_property_float_get_array(
397 &scene_rna_ptr, override_pixel_jitter_sample_prop, &pixel_jitter_sample_arr[0]);
398 integrator->set_custom_pixel_jitter_sample(pixel_jitter_sample_arr);
399 use_custom_pixel_jitter_sample = true;
400 }
401 else if (array_length != 0) {
402 printf("%s: scene.custom_pixel_jitter_sample length is not 0 or 2.\n", __func__);
403 }
404 }
405 integrator->set_use_custom_pixel_jitter_sample(use_custom_pixel_jitter_sample);
406
407 int seed = get_int(cscene, "seed");
408 if (get_boolean(cscene, "use_animated_seed")) {
409 seed = hash_uint2(b_scene->r.cfra, get_int(cscene, "seed"));
410 if (b_scene->r.subframe != 0.0f) {
411 /* TODO(sergey): Ideally should be some sort of hash_merge,
412 * but this is good enough for now.
413 */
414 seed += hash_uint2((int)(b_scene->r.subframe * (float)INT_MAX), get_int(cscene, "seed"));
415 }
416 }
417
418 integrator->set_seed(seed);
419
420 integrator->set_sample_clamp_direct(get_float(cscene, "sample_clamp_direct"));
421 integrator->set_sample_clamp_indirect(get_float(cscene, "sample_clamp_indirect"));
422 if (!preview) {
423 integrator->set_motion_blur(view_layer.use_motion_blur);
424 }
425
426 const bool use_light_tree = get_boolean(cscene, "use_light_tree");
427 integrator->set_use_light_tree(use_light_tree);
428 integrator->set_light_sampling_threshold(get_float(cscene, "light_sampling_threshold"));
429
430 if (integrator->use_light_tree_is_modified()) {
431 scene->light_manager->tag_update(scene, LightManager::UPDATE_ALL);
432 }
433
434 SamplingPattern sampling_pattern = (SamplingPattern)get_enum(
435 cscene, "sampling_pattern", SAMPLING_NUM_PATTERNS, SAMPLING_PATTERN_TABULATED_SOBOL);
436
437 switch (sampling_pattern) {
439 if (!background) {
440 /* For interactive rendering, ensure that the first sample is in itself
441 * blue-noise-distributed for smooth viewport navigation. */
442 sampling_pattern = SAMPLING_PATTERN_BLUE_NOISE_FIRST;
443 }
444 else {
445 /* For non-interactive rendering, default to a full blue-noise pattern. */
446 sampling_pattern = SAMPLING_PATTERN_BLUE_NOISE_PURE;
447 }
448 break;
451 /* Always allowed. */
452 break;
453 default:
454 /* If not using developer UI, default to blue noise for "advanced" patterns. */
455 if (!use_developer_ui) {
456 sampling_pattern = SAMPLING_PATTERN_BLUE_NOISE_PURE;
457 }
458 break;
459 }
460
461 const bool is_vertex_baking = b_bake_target &&
462 b_scene->r.bake.target != blender::R_BAKE_TARGET_IMAGE_TEXTURES;
463 scene->bake_manager->set_use_seed(is_vertex_baking);
464 if (is_vertex_baking) {
465 /* When baking vertex colors, the "pixels" in the output are unrelated to their neighbors,
466 * so blue-noise sampling makes no sense. */
467 sampling_pattern = SAMPLING_PATTERN_TABULATED_SOBOL;
468 }
469
470 integrator->set_sampling_pattern(sampling_pattern);
471
472 int samples = 1;
473 bool use_adaptive_sampling = false;
474 if (preview) {
475 samples = get_int(cscene, "preview_samples");
476 use_adaptive_sampling = RNA_boolean_get(&cscene, "use_preview_adaptive_sampling");
477 integrator->set_use_adaptive_sampling(use_adaptive_sampling);
478 integrator->set_adaptive_threshold(get_float(cscene, "preview_adaptive_threshold"));
479 integrator->set_adaptive_min_samples(get_int(cscene, "preview_adaptive_min_samples"));
480 }
481 else {
482 samples = get_int(cscene, "samples");
483 use_adaptive_sampling = RNA_boolean_get(&cscene, "use_adaptive_sampling");
484 integrator->set_use_adaptive_sampling(use_adaptive_sampling);
485 integrator->set_adaptive_threshold(get_float(cscene, "adaptive_threshold"));
486 integrator->set_adaptive_min_samples(get_int(cscene, "adaptive_min_samples"));
487 }
488
489 if (get_boolean(cscene, "use_fast_gi")) {
490 if (preview) {
491 integrator->set_ao_bounces(get_int(cscene, "ao_bounces"));
492 }
493 else {
494 integrator->set_ao_bounces(get_int(cscene, "ao_bounces_render"));
495 }
496 }
497 else {
498 integrator->set_ao_bounces(0);
499 }
500
501#ifdef WITH_CYCLES_DEBUG
502 DirectLightSamplingType direct_light_sampling_type = (DirectLightSamplingType)get_enum(
503 cscene, "direct_light_sampling_type", DIRECT_LIGHT_SAMPLING_NUM, DIRECT_LIGHT_SAMPLING_MIS);
504 integrator->set_direct_light_sampling_type(direct_light_sampling_type);
505#endif
506
507 integrator->set_use_guiding(get_boolean(cscene, "use_guiding"));
508 integrator->set_use_surface_guiding(get_boolean(cscene, "use_surface_guiding"));
509 integrator->set_use_volume_guiding(get_boolean(cscene, "use_volume_guiding"));
510 integrator->set_guiding_training_samples(get_int(cscene, "guiding_training_samples"));
511
512 if (use_developer_ui) {
513 integrator->set_deterministic_guiding(get_boolean(cscene, "use_deterministic_guiding"));
514 integrator->set_surface_guiding_probability(get_float(cscene, "surface_guiding_probability"));
515 integrator->set_volume_guiding_probability(get_float(cscene, "volume_guiding_probability"));
516 integrator->set_use_guiding_direct_light(get_boolean(cscene, "use_guiding_direct_light"));
517 integrator->set_use_guiding_mis_weights(get_boolean(cscene, "use_guiding_mis_weights"));
518 const GuidingDistributionType guiding_distribution_type = (GuidingDistributionType)get_enum(
519 cscene, "guiding_distribution_type", GUIDING_NUM_TYPES, GUIDING_TYPE_PARALLAX_AWARE_VMM);
520 integrator->set_guiding_distribution_type(guiding_distribution_type);
521 const GuidingDirectionalSamplingType guiding_directional_sampling_type =
522 (GuidingDirectionalSamplingType)get_enum(cscene,
523 "guiding_directional_sampling_type",
526 integrator->set_guiding_directional_sampling_type(guiding_directional_sampling_type);
527 integrator->set_guiding_roughness_threshold(get_float(cscene, "guiding_roughness_threshold"));
528 }
529
530 DenoiseParams denoise_params = get_denoise_params(
531 *b_scene, &b_view_layer, background, denoise_device_info);
532
533 /* No denoising support for vertex color baking, vertices packed into image
534 * buffer have no relation to neighbors. */
535 if (is_vertex_baking) {
536 denoise_params.use = false;
537 }
538
539 integrator->set_use_denoise(denoise_params.use);
540
541 /* Only update denoiser parameters if the denoiser is actually used. This allows to tweak
542 * denoiser parameters before enabling it without render resetting on every change. The downside
543 * is that the interface and the integrator are technically out of sync. */
544 if (denoise_params.use) {
545 integrator->set_denoiser_type(denoise_params.type);
546 integrator->set_denoise_use_gpu(denoise_params.use_gpu);
547 integrator->set_denoise_start_sample(denoise_params.start_sample);
548 integrator->set_denoiser_passes(denoise_params.passes);
549 integrator->set_denoiser_prefilter(denoise_params.prefilter);
550 integrator->set_denoiser_quality(denoise_params.quality);
551 integrator->set_denoiser_upscale_factor(denoise_params.upscale_factor);
552 }
553
554 float scrambling_distance = get_float(cscene, "scrambling_distance");
555 const bool auto_scrambling_distance = get_boolean(cscene, "auto_scrambling_distance");
556 if (auto_scrambling_distance) {
557 if (samples == 0) {
558 /* If samples is 0, then viewport rendering is set to render infinitely. In that case we
559 * override the samples value with 4096 so the Automatic Scrambling Distance algorithm
560 * picks a Scrambling Distance value with a good balance of performance and correlation
561 * artifacts when rendering to high sample counts. */
562 samples = 4096;
563 }
564
565 if (use_adaptive_sampling) {
566 /* If Adaptive Sampling is enabled, use "min_samples" in the Automatic Scrambling Distance
567 * algorithm to avoid artifacts common with Adaptive Sampling + Scrambling Distance. */
568 const AdaptiveSampling adaptive_sampling = integrator->get_adaptive_sampling();
569 samples = min(samples, adaptive_sampling.min_samples);
570 }
571 scrambling_distance *= 4.0f / sqrtf(samples);
572 }
573
574 /* Only use scrambling distance in the viewport if user wants to and they're not using DLSS.
575 * DLSS typically accumulates multiple 1spp renders over time.
576 * In an ideal world this would converge to a correct result, but in most situations with
577 * scrambling, DLSS disregards previous samples since they're so different, ultimately leading to
578 * flickering and artifacts. */
579 const bool preview_scrambling_distance = get_boolean(cscene, "preview_scrambling_distance");
580 if ((preview && !preview_scrambling_distance) ||
581 sampling_pattern != SAMPLING_PATTERN_TABULATED_SOBOL ||
582 (denoise_params.use && denoise_params.type == DENOISER_DLSS))
583 {
584 scrambling_distance = 1.0f;
585 }
586
587 if (scrambling_distance != 1.0f) {
588 LOG_INFO << "Using scrambling distance: " << scrambling_distance;
589 }
590 integrator->set_scrambling_distance(scrambling_distance);
591
592 /* UPDATE_NONE as we don't want to tag the integrator as modified (this was done by the
593 * set calls above), but we need to make sure that the dependent things are tagged. */
594 integrator->tag_update(scene, Integrator::UPDATE_NONE);
595}
596
597/* Scene Attributes */
598
600{
601 SceneAttributes *scene_attribute = scene->scene_attribute;
602
603 blender::Scene *scene = b_scene;
604 float frame = BKE_scene_frame_get(b_scene);
605 float time = FRA2TIME(frame);
606
607 scene_attribute->set_time(time);
608 scene_attribute->set_frame(frame);
609}
610
611/* Film */
612
613void BlenderSync::sync_film(blender::ViewLayer &b_view_layer,
614 blender::bScreen *b_screen,
615 blender::View3D *b_v3d)
616{
617 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene->id);
618 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
619 blender::PointerRNA view_layer_rna_ptr = RNA_pointer_create_id_subdata(
620 b_scene->id, blender::RNA_ViewLayer, &b_view_layer);
621 blender::PointerRNA crl = RNA_pointer_get(&view_layer_rna_ptr, "cycles");
622
623 Film *film = scene->film;
624
625 if (b_v3d) {
626 const BlenderViewportParameters new_viewport_parameters(b_screen, b_v3d, use_developer_ui);
627 film->set_display_pass(new_viewport_parameters.display_pass);
628 film->set_show_active_pixels(new_viewport_parameters.show_active_pixels);
629 }
630
631 film->set_exposure(get_float(cscene, "film_exposure"));
632 film->set_filter_type(
633 (FilterType)get_enum(cscene, "pixel_filter_type", FILTER_NUM_TYPES, FILTER_BLACKMAN_HARRIS));
634 const float filter_width = (film->get_filter_type() == FILTER_BOX) ?
635 1.0f :
636 get_float(cscene, "filter_width");
637 film->set_filter_width(filter_width);
638
639 if (b_scene->world) {
640 film->set_mist_start(b_scene->world->miststa);
641 film->set_mist_depth(b_scene->world->mistdist);
642
643 switch (b_scene->world->mistype) {
645 film->set_mist_falloff(2.0f);
646 break;
648 film->set_mist_falloff(1.0f);
649 break;
651 film->set_mist_falloff(0.5f);
652 break;
653 }
654 }
655
656 /* Blender viewport does not support proper shadow catcher compositing, so force an approximate
657 * mode to improve visual feedback. */
658 if (b_v3d) {
659 film->set_use_approximate_shadow_catcher(true);
660 }
661 else {
662 film->set_use_approximate_shadow_catcher(!get_boolean(crl, "use_pass_shadow_catcher"));
663 }
664
665 /* Denoising passes. */
666 film->set_denoising_pass_follow_reflections(
667 get_boolean(crl, "denoising_pass_follow_reflections"));
668 film->set_denoising_pass_use_albedo_roughness_weighting(
669 get_boolean(crl, "denoising_pass_use_albedo_roughness_weighting"));
670}
671
672/* Render Layer */
673
675{
676 view_layer.name = b_view_layer.name;
677
678 /* Filter. */
679 view_layer.use_background_shader = (b_view_layer.layflag & blender::SCE_LAY_SKY) != 0;
680 /* Always enable surfaces for baking, otherwise there is nothing to bake to. */
681 view_layer.use_surfaces = (b_view_layer.layflag & blender::SCE_LAY_SOLID) != 0 || b_bake_target;
682 view_layer.use_hair = (b_view_layer.layflag & blender::SCE_LAY_STRAND) != 0;
683 view_layer.use_volumes = (b_view_layer.layflag & blender::SCE_LAY_VOLUMES) != 0;
684 view_layer.use_motion_blur = (b_view_layer.layflag & blender::SCE_LAY_MOTION_BLUR) != 0 &&
685 (b_scene->r.mode & blender::R_MBLUR) != 0;
686
687 /* Material override. */
688 view_layer.material_override = b_view_layer.mat_override;
689 /* World override. */
690 view_layer.world_override = b_view_layer.world_override;
691
692 /* Sample override. */
693 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene->id);
694 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
695 const int use_layer_samples = get_enum(cscene, "use_layer_samples");
696
697 view_layer.bound_samples = (use_layer_samples == 1);
698 view_layer.samples = 0;
699
700 if (use_layer_samples != 2) {
701 const int samples = b_view_layer.samples;
702 view_layer.samples = samples;
703 }
704}
705
707{
708 if (engine->re) {
709 return RE_engine_get_render_data(engine->re);
710 }
711 return nullptr;
712}
713
714/* Images */
715void BlenderSync::sync_images()
716{
717 /* Sync is a convention for this API, but currently it frees unused buffers. */
718
719 const bool is_interface_locked = engine_render_get(b_engine) &&
721 if (is_interface_locked == false && BlenderSession::headless == false) {
722 /* If interface is not locked, it's possible image is needed for
723 * the display.
724 */
725 return;
726 }
727 /* Free buffers used by images which are not needed for render. */
728 for (blender::Image &b_image : b_data->images) {
729 const bool is_builtin = image_is_builtin(b_image, *b_engine);
730 if (is_builtin == false) {
731 BKE_image_free_buffers_ex(&b_image, true);
732 }
733 /* TODO(sergey): Free builtin images not used by any shader. */
734 }
735}
736
737/* Passes */
738
740{
741 const string name = b_pass.name;
742#define MAP_PASS(passname, passtype, noisy) \
743 if (name == passname) { \
744 type = passtype; \
745 mode = (noisy) ? PassMode::NOISY : PassMode::DENOISED; \
746 return true; \
747 } \
748 ((void)0)
749
750 /* NOTE: Keep in sync with defined names from engine.py */
751
752 MAP_PASS("Combined", PASS_COMBINED, false);
753 MAP_PASS("Noisy Image", PASS_COMBINED, true);
754
755 MAP_PASS("Depth", PASS_DEPTH, false);
756 MAP_PASS("Mist", PASS_MIST, false);
757 MAP_PASS("Position", PASS_POSITION, false);
758 MAP_PASS("Normal", PASS_NORMAL, false);
759 MAP_PASS("Object Index", PASS_OBJECT_ID, false);
760 MAP_PASS("UV", PASS_UV, false);
761 MAP_PASS("Vector", PASS_MOTION, false);
762 MAP_PASS("Material Index", PASS_MATERIAL_ID, false);
763
764 MAP_PASS("Diffuse Direct", PASS_DIFFUSE_DIRECT, false);
765 MAP_PASS("Glossy Direct", PASS_GLOSSY_DIRECT, false);
766 MAP_PASS("Transmission Direct", PASS_TRANSMISSION_DIRECT, false);
767 MAP_PASS("Volume Direct", PASS_VOLUME_DIRECT, false);
768
769 MAP_PASS("Diffuse Indirect", PASS_DIFFUSE_INDIRECT, false);
770 MAP_PASS("Glossy Indirect", PASS_GLOSSY_INDIRECT, false);
771 MAP_PASS("Transmission Indirect", PASS_TRANSMISSION_INDIRECT, false);
772 MAP_PASS("Volume Indirect", PASS_VOLUME_INDIRECT, false);
773 MAP_PASS("Volume Scatter", PASS_VOLUME_SCATTER, false);
774 MAP_PASS("Volume Transmit", PASS_VOLUME_TRANSMIT, false);
775 MAP_PASS("Volume Majorant", PASS_VOLUME_MAJORANT, false);
776
777 MAP_PASS("Diffuse Color", PASS_DIFFUSE_COLOR, false);
778 MAP_PASS("Glossy Color", PASS_GLOSSY_COLOR, false);
779 MAP_PASS("Transmission Color", PASS_TRANSMISSION_COLOR, false);
780
781 MAP_PASS("Emission", PASS_EMISSION, false);
782 MAP_PASS("Environment", PASS_BACKGROUND, false);
783 MAP_PASS("Ambient Occlusion", PASS_AO, false);
784
785 MAP_PASS("BakePrimitive", PASS_BAKE_PRIMITIVE, false);
786 MAP_PASS("BakeSeed", PASS_BAKE_SEED, false);
787 MAP_PASS("BakeDifferential", PASS_BAKE_DIFFERENTIAL, false);
788
789 MAP_PASS("Denoising Albedo", PASS_DENOISING_ALBEDO, true);
790 MAP_PASS("Denoising Specular Albedo", PASS_DENOISING_SPECULAR_ALBEDO, true);
791 MAP_PASS("Denoising Normal", PASS_DENOISING_NORMAL, true);
792 MAP_PASS("Denoising Roughness", PASS_DENOISING_ROUGHNESS, true);
793 MAP_PASS("Denoising Depth", PASS_DENOISING_DEPTH, true);
794 MAP_PASS("Denoising Backward Motion", PASS_DENOISING_BACKWARD_MOTION, true);
795 MAP_PASS("Denoising Specular Motion", PASS_DENOISING_SPECULAR_MOTION, true);
796
797 MAP_PASS("Shadow Catcher", PASS_SHADOW_CATCHER, false);
798 MAP_PASS("Noisy Shadow Catcher", PASS_SHADOW_CATCHER, true);
799
800 MAP_PASS("AdaptiveAuxBuffer", PASS_ADAPTIVE_AUX_BUFFER, false);
801 MAP_PASS("Debug Sample Count", PASS_SAMPLE_COUNT, false);
802 MAP_PASS("Render Time", PASS_RENDER_TIME, false);
803
804 MAP_PASS("Guiding Color", PASS_GUIDING_COLOR, false);
805 MAP_PASS("Guiding Probability", PASS_GUIDING_PROBABILITY, false);
806 MAP_PASS("Guiding Average Roughness", PASS_GUIDING_AVG_ROUGHNESS, false);
807
809 type = PASS_CRYPTOMATTE;
810 mode = PassMode::DENOISED;
811 return true;
812 }
813
814#undef MAP_PASS
815
816 return false;
817}
818
819static Pass *pass_add(Scene *scene,
820 PassType type,
821 const char *name,
823{
824 Pass *pass = scene->create_node<Pass>();
825
826 pass->set_type(type);
827 pass->set_name(ustring(name));
828 pass->set_mode(mode);
829
830 return pass;
831}
832
834 blender::ViewLayer &b_view_layer)
835{
836 /* Delete all existing passes. */
837 const vector<Pass *> &scene_passes = scene->passes;
838 scene->delete_nodes(set<Pass *>(scene_passes.begin(), scene_passes.end()));
839
840 /* Always add combined pass. */
841 pass_add(scene, PASS_COMBINED, "Combined");
842
843 /* Cryptomatte stores two ID/weight pairs per RGBA layer.
844 * User facing parameter is the number of pairs. */
845 const int crypto_depth = divide_up(min(16, b_view_layer.cryptomatte_levels), 2);
846 scene->film->set_cryptomatte_depth(crypto_depth);
847 CryptomatteType cryptomatte_passes = CRYPT_NONE;
849 cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_OBJECT);
850 }
852 cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_MATERIAL);
853 }
855 cryptomatte_passes = (CryptomatteType)(cryptomatte_passes | CRYPT_ASSET);
856 }
857 scene->film->set_cryptomatte_passes(cryptomatte_passes);
858
859 unordered_set<string> expected_passes;
860
861 /* Custom AOV passes. */
862 for (blender::ViewLayerAOV &b_aov : b_view_layer.aovs) {
863 if ((b_aov.flag & blender::AOV_CONFLICT) != 0) {
864 continue;
865 }
866
867 const string name = b_aov.name;
868 const PassType type = (b_aov.type == blender::AOV_TYPE_COLOR) ? PASS_AOV_COLOR :
870
871 pass_add(scene, type, name.c_str());
872 expected_passes.insert(name);
873 }
874
875 /* Light Group passes. */
876 for (blender::ViewLayerLightgroup &b_lightgroup : b_view_layer.lightgroups) {
877 const string name = string_printf("Combined_%s", b_lightgroup.name);
878
879 Pass *pass = pass_add(scene, PASS_COMBINED, name.c_str(), PassMode::NOISY);
880 pass->set_lightgroup(ustring(b_lightgroup.name));
881 expected_passes.insert(name);
882 }
883
884 /* Sync the passes that were defined in engine.py. */
885 for (blender::RenderPass &b_pass : b_rlay.passes) {
886 PassType pass_type = PASS_NONE;
887 PassMode pass_mode = PassMode::DENOISED;
888
889 if (!get_known_pass_type(b_pass, pass_type, pass_mode)) {
890 if (!expected_passes.contains(b_pass.name)) {
891 LOG_ERROR << "Unknown pass " << b_pass.name;
892 }
893 continue;
894 }
895
896 if (pass_type == PASS_MOTION && ((b_view_layer.layflag & blender::SCE_LAY_MOTION_BLUR) != 0 &&
897 (b_scene->r.mode & blender::R_MBLUR) != 0))
898 {
899 continue;
900 }
901
902 pass_add(scene, pass_type, b_pass.name, pass_mode);
903 }
904
905 scene->film->set_pass_alpha_threshold(b_view_layer.pass_alpha_threshold);
906}
907
908void BlenderSync::free_data_after_sync(blender::Depsgraph &b_depsgraph)
909{
910 /* When viewport display is not needed during render we can force some
911 * caches to be releases from blender side in order to reduce peak memory
912 * footprint during synchronization process.
913 */
914
915 const bool is_interface_locked = engine_render_get(b_engine) &&
917 const bool is_persistent_data = engine_render_get(b_engine) &&
919 const bool can_free_caches =
920 (BlenderSession::headless || is_interface_locked) &&
921 /* Baking re-uses the depsgraph multiple times, clearing crashes
922 * reading un-evaluated mesh data which isn't aligned with the
923 * geometry we're baking, see #71012. */
924 !b_bake_target &&
925 /* Persistent data must main caches for performance and correctness. */
926 !is_persistent_data;
927
928 if (!can_free_caches) {
929 return;
930 }
931
932 /* TODO(sergey): We can actually remove the whole dependency graph,
933 * but that will need some API support first.
934 */
935
936 blender::DEGObjectIterSettings deg_iter_settings{};
937 deg_iter_settings.depsgraph = &b_depsgraph;
941 blender::DEGObjectIterData deg_iter_data{};
942 deg_iter_data.settings = &deg_iter_settings;
943 deg_iter_data.graph = deg_iter_settings.depsgraph;
944 deg_iter_data.flag = deg_iter_settings.flags;
945
949 &deg_iter_data,
951 b_ob)
952 {
953 /* Grease pencil render requires all evaluated objects available as-is after Cycles is done
954 * with its part. */
955 if (b_ob->type == blender::OB_GREASE_PENCIL ||
956 (b_ob->runtime->contained_geometry_types &
958 {
959 continue;
960 }
961 BKE_object_free_caches(b_ob);
962 }
963 ITER_END;
964}
965
966/* Scene Parameters */
967
969 blender::Main &b_data,
970 blender::Scene &b_scene,
971 const bool background,
972 const bool use_developer_ui)
973{
974 SceneParams params;
975 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene.id);
976 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
977 const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
978
979 if (shadingsystem == 0) {
981 }
982 else if (shadingsystem == 1) {
984 }
985
986 if (background || (use_developer_ui && get_enum(cscene, "debug_bvh_type"))) {
987 params.bvh_type = BVH_TYPE_STATIC;
988 }
989 else {
990 params.bvh_type = BVH_TYPE_DYNAMIC;
991 }
992
993 params.use_bvh_spatial_split = RNA_boolean_get(&cscene, "debug_use_spatial_splits");
994 params.use_bvh_compact_structure = RNA_boolean_get(&cscene, "debug_use_compact_bvh");
995 params.use_bvh_unaligned_nodes = RNA_boolean_get(&cscene, "debug_use_hair_bvh");
996 params.num_bvh_time_steps = RNA_int_get(&cscene, "debug_bvh_time_steps");
997
998 blender::PointerRNA csscene = RNA_pointer_get(&scene_rna_ptr, "cycles_curves");
999 params.hair_subdivisions = get_int(csscene, "subdivisions");
1000 params.hair_shape = (CurveShapeType)get_enum(
1001 csscene, "shape", CURVE_NUM_SHAPE_TYPES, CURVE_THICK);
1002
1003 float texture_resolution;
1004 int texture_limit;
1005 if (background) {
1006 texture_resolution = RNA_float_get(&cscene, "texture_resolution_render");
1007 texture_limit = RNA_enum_get(&cscene, "texture_limit_render");
1008 }
1009 else {
1010 texture_resolution = RNA_float_get(&cscene, "texture_resolution");
1011 texture_limit = RNA_enum_get(&cscene, "texture_limit");
1012 }
1013 if ((b_scene.r.mode & blender::R_SIMPLIFY) != 0) {
1014 params.texture_resolution = (texture_resolution < 1.0f) ? texture_resolution : 1.0f;
1015 params.texture_limit = (texture_limit > 0) ? (1 << (texture_limit + 6)) : 0;
1016 }
1017 else {
1018 params.texture_resolution = 1.0f;
1019 params.texture_limit = 0;
1020 }
1021
1023
1024 params.background = background;
1025 params.use_texture_cache = b_scene.r.scemode & blender::R_USE_TEXTURE_CACHE;
1027 params.texture_cache_path = blender_absolute_path(
1028 b_data, nullptr, b_preferences.texture_cachedir);
1029
1030 return params;
1031}
1032
1033/* Session Parameters */
1034
1036 blender::UserDef &b_preferences,
1037 blender::Scene &b_scene,
1038 bool background,
1039 float pixelsize)
1040{
1041 SessionParams params;
1042
1043 /* Feature Set */
1044 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene.id);
1045 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
1046
1047 if (background) {
1048 /* Viewport and preview renders do not require temp directory and do request session
1049 * parameters more often than the background render.
1050 * Optimize RNA-C++ usage and memory allocation a bit by saving string access which we know
1051 * is not needed for viewport render. */
1053 }
1054
1055 /* Headless and background rendering. */
1057 params.background = background;
1058
1059 /* Device */
1060 params.threads = blender_device_threads(b_scene);
1061 params.device = blender_device_info(b_preferences,
1062 b_scene,
1063 params.background,
1064 (b_engine.flag & blender::RE_ENGINE_PREVIEW) != 0,
1065 params.denoise_device);
1066
1067 /* samples */
1068 const int samples = get_int(cscene, "samples");
1069 const int preview_samples = get_int(cscene, "preview_samples");
1070 const bool use_sample_subset = get_boolean(cscene, "use_sample_subset");
1071 const int sample_subset_offset = get_int(cscene, "sample_offset");
1072 const int sample_subset_length = get_int(cscene, "sample_subset_length");
1073
1074 if (background) {
1075 params.samples = samples;
1076
1077 params.use_sample_subset = use_sample_subset;
1078 params.sample_subset_offset = sample_subset_offset;
1079 params.sample_subset_length = sample_subset_length;
1080 }
1081 else {
1082 params.samples = preview_samples;
1083 if (params.samples == 0) {
1084 params.samples = INT_MAX;
1085 }
1086 params.use_sample_subset = false;
1087 params.sample_subset_offset = 0;
1088 params.sample_subset_length = 0;
1089 }
1090
1091 /* Viewport Performance */
1092 if (b_scene.r.preview_pixel_size == 0) {
1093 /* Automatic pixel size. */
1094 params.pixel_size = (pixelsize > 1.5f) ? 2 : 1;
1095 }
1096 else {
1097 /* Specific user chosen pixel size. */
1098 params.pixel_size = b_scene.r.preview_pixel_size;
1099 }
1100
1101 if (background) {
1102 params.pixel_size = 1;
1103 }
1104
1105 /* shading system - scene level needs full refresh */
1106 const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
1107
1108 if (shadingsystem == 0) {
1110 }
1111 else if (shadingsystem == 1) {
1113 }
1114
1115 /* Time limit. */
1116 if (background) {
1117 params.time_limit = (double)get_float(cscene, "time_limit");
1118 }
1119 else {
1120 /* For the viewport it kind of makes more sense to think in terms of the noise floor, which
1121 * is usually higher than acceptable level for the final frame. */
1122 /* TODO: It might be useful to support time limit in the viewport as well, but needs some
1123 * extra thoughts and input. */
1124 params.time_limit = 0.0;
1125 }
1126
1127 /* Profiling. */
1128 params.use_profiling = params.device.has_profiling &&
1129 (b_engine.flag & blender::RE_ENGINE_PREVIEW) == 0 && background &&
1131
1132 if (background) {
1133 params.use_auto_tile = true;
1134 params.tile_size = max(get_int(cscene, "tile_size"), 8);
1135 }
1136 else {
1137 params.use_auto_tile = false;
1138 }
1139
1140 return params;
1141}
1142
1144 blender::ViewLayer *b_view_layer,
1145 bool background,
1146 const DeviceInfo &denoise_device_info)
1147{
1148 enum DenoiserInput {
1149 DENOISER_INPUT_RGB = 1,
1150 DENOISER_INPUT_RGB_ALBEDO = 2,
1151 DENOISER_INPUT_RGB_ALBEDO_NORMAL = 3,
1152
1153 DENOISER_INPUT_NUM,
1154 };
1155
1156 enum DenoiserUpscaleQuality {
1157 DENOISER_UPSCALE_NONE = 0,
1158 DENOISER_UPSCALE_QUALITY = 1,
1159 DENOISER_UPSCALE_BALANCED = 2,
1160 DENOISER_UPSCALE_PERFORMANCE = 3,
1161 DENOISER_UPSCALE_ULTRA_PERFORMANCE = 4,
1162
1163 DENOISER_UPSCALE_NUM,
1164 };
1165
1166 DenoiseParams denoising;
1167 blender::PointerRNA scene_rna_ptr = RNA_id_pointer_create(&b_scene.id);
1168 blender::PointerRNA cscene = RNA_pointer_get(&scene_rna_ptr, "cycles");
1169
1170 int input_passes = -1;
1171
1172 if (background) {
1173 /* Final Render Denoising */
1174 denoising.use = get_boolean(cscene, "use_denoising");
1175 denoising.type = (DenoiserType)get_enum(cscene, "denoiser", DENOISER_NUM, DENOISER_NONE);
1176 denoising.use_gpu = get_boolean(cscene, "denoising_use_gpu");
1177 denoising.prefilter = (DenoiserPrefilter)get_enum(
1178 cscene, "denoising_prefilter", DENOISER_PREFILTER_NUM, DENOISER_PREFILTER_NONE);
1179 denoising.quality = (DenoiserQuality)get_enum(
1180 cscene, "denoising_quality", DENOISER_QUALITY_NUM, DENOISER_QUALITY_HIGH);
1181
1182 input_passes = (DenoiserInput)get_enum(
1183 cscene, "denoising_input_passes", DENOISER_INPUT_NUM, DENOISER_INPUT_RGB_ALBEDO_NORMAL);
1184
1185 if (b_view_layer) {
1186 blender::PointerRNA view_layer_rna_ptr = RNA_pointer_create_id_subdata(
1187 b_scene.id, blender::RNA_ViewLayer, b_view_layer);
1188 blender::PointerRNA clayer = RNA_pointer_get(&view_layer_rna_ptr, "cycles");
1189 if (!get_boolean(clayer, "use_denoising")) {
1190 denoising.use = false;
1191 }
1192 }
1193 }
1194 else {
1195 /* Viewport Denoising */
1196 denoising.use = get_boolean(cscene, "use_preview_denoising");
1197 denoising.type = (DenoiserType)get_enum(
1198 cscene, "preview_denoiser", DENOISER_NUM, DENOISER_NONE);
1199 denoising.use_gpu = get_boolean(cscene, "preview_denoising_use_gpu");
1200 denoising.prefilter = (DenoiserPrefilter)get_enum(
1201 cscene, "preview_denoising_prefilter", DENOISER_PREFILTER_NUM, DENOISER_PREFILTER_FAST);
1202 denoising.quality = (DenoiserQuality)get_enum(
1203 cscene, "preview_denoising_quality", DENOISER_QUALITY_NUM, DENOISER_QUALITY_BALANCED);
1204 denoising.start_sample = get_int(cscene, "preview_denoising_start_sample");
1205
1206 input_passes = (DenoiserInput)get_enum(
1207 cscene, "preview_denoising_input_passes", DENOISER_INPUT_NUM, DENOISER_INPUT_RGB_ALBEDO);
1208
1209 /* Auto select fastest denoiser. */
1210 if (denoising.type == DENOISER_NONE) {
1211 denoising.type = Denoiser::automatic_viewport_denoiser_type(denoise_device_info);
1212 if (denoising.type == DENOISER_NONE) {
1213 denoising.use = false;
1214 }
1215 }
1216
1217 if (denoising.type == DENOISER_DLSS) {
1218 /* Disable denoising when DLSS is not supported. */
1219 if (!Denoiser::is_device_supported(denoising.type, denoise_device_info)) {
1220 denoising.use = false;
1221 }
1222
1223 denoising.start_sample = 0;
1224
1225 switch ((DenoiserUpscaleQuality)get_enum(cscene,
1226 "preview_denoising_upscale_quality",
1227 DENOISER_UPSCALE_NUM,
1228 DENOISER_UPSCALE_BALANCED))
1229 {
1230 case DENOISER_UPSCALE_NONE:
1231 denoising.quality = DENOISER_QUALITY_HIGH;
1232 denoising.upscale_factor = 1.0f;
1233 break;
1234 case DENOISER_UPSCALE_QUALITY:
1235 denoising.quality = DENOISER_QUALITY_HIGH;
1236 denoising.upscale_factor = 1.0f / 0.66666667f;
1237 break;
1238 default:
1239 case DENOISER_UPSCALE_BALANCED:
1241 denoising.upscale_factor = 1.0f / 0.58f;
1242 break;
1243 case DENOISER_UPSCALE_PERFORMANCE:
1244 denoising.quality = DENOISER_QUALITY_FAST;
1245 denoising.upscale_factor = 2.0f;
1246 break;
1247 case DENOISER_UPSCALE_ULTRA_PERFORMANCE:
1248 denoising.quality = DENOISER_QUALITY_FAST;
1249 denoising.upscale_factor = 3.0f;
1250 break;
1251 }
1252
1256 return denoising;
1257 }
1258 }
1259
1260 switch (input_passes) {
1261 case DENOISER_INPUT_RGB:
1262 denoising.passes = DENOISER_PASS_NONE;
1263 break;
1264
1265 case DENOISER_INPUT_RGB_ALBEDO:
1266 denoising.passes = DENOISER_PASS_ALBEDO;
1267 break;
1268
1269 case DENOISER_INPUT_RGB_ALBEDO_NORMAL:
1271 break;
1272
1273 default:
1274 LOG_ERROR << "Unhandled input passes enum " << input_passes;
1275 break;
1276 }
1277
1278 return denoising;
1279}
1280
#define ITER_END
#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance)
#define FRA2TIME(a)
int blender_device_threads(blender::Scene &b_scene)
DeviceInfo blender_device_info(blender::UserDef &b_preferences, blender::Scene &b_scene, bool background, bool preview, DeviceInfo &preferences_device)
btScalar max
static bool headless
static bool print_render_stats
static SessionParams get_session_params(blender::RenderEngine &b_engine, blender::UserDef &b_preferences, blender::Scene &b_scene, bool background, float pixelsize)
Definition sync.cpp:1035
void sync_data(blender::RenderData &b_render, blender::Depsgraph &b_depsgraph, blender::bScreen *b_screen, blender::View3D *b_v3d, blender::RegionView3D *b_rv3d, const int width, const int height, const DeviceInfo &denoise_device_info)
Definition sync.cpp:298
void set_bake_target(blender::Object &b_object)
Definition sync.cpp:102
BlenderSync(blender::RenderEngine &b_engine, blender::Main &b_data, blender::Scene &b_scene, Scene *scene, bool preview, bool use_developer_ui, Progress &progress)
Definition sync.cpp:52
void tag_update()
Definition sync.cpp:97
void reset(blender::Main &b_data, blender::Scene &b_scene)
Definition sync.cpp:87
void sync_view_layer(blender::ViewLayer &b_view_layer)
Definition sync.cpp:674
void sync_render_passes(blender::RenderLayer &b_rlay, blender::ViewLayer &b_view_layer)
Definition sync.cpp:833
void sync_integrator(blender::ViewLayer &b_view_layer, bool background, const DeviceInfo &denoise_device_info)
Definition sync.cpp:354
static DenoiseParams get_denoise_params(blender::Scene &b_scene, blender::ViewLayer *b_view_layer, bool background, const DeviceInfo &denoise_device)
Definition sync.cpp:1143
void free_data_after_sync(blender::Depsgraph &b_depsgraph)
Definition sync.cpp:908
void sync_recalc(blender::Depsgraph &b_depsgraph, blender::bScreen *b_screen, blender::View3D *b_v3d, blender::RegionView3D *b_rv3d)
Definition sync.cpp:109
void sync_scene_attributes()
Definition sync.cpp:599
static SceneParams get_scene_params(blender::UserDef &b_preferences, blender::Main &b_data, blender::Scene &b_scene, const bool background, const bool use_developer_ui)
Definition sync.cpp:968
CPU cpu
Definition debug.h:143
float upscale_factor
Definition denoise.h:90
DenoiserType type
Definition denoise.h:73
DenoiserQuality quality
Definition denoise.h:89
bool use_gpu
Definition denoise.h:86
DenoiserPassMask passes
Definition denoise.h:79
int start_sample
Definition denoise.h:76
DenoiserPrefilter prefilter
Definition denoise.h:88
NODE_DECLARE bool use
Definition denoise.h:70
static DenoiserType automatic_viewport_denoiser_type(const DeviceInfo &denoise_device_info)
Definition denoiser.cpp:225
static bool is_device_supported(DenoiserType type, const DeviceInfo &denoise_device_info)
Definition denoiser.cpp:205
bool has_profiling
Definition film.h:29
bool is_mesh() const
bool set_animation_frame_update(const int frame)
void tag_update(Scene *scene, const uint32_t flag)
AdaptiveSampling get_adaptive_sampling() const
@ SUBDIVISION_NONE
Definition scene/mesh.h:114
Definition pass.h:50
std::string texture_cache_path
Definition scene.h:89
BVHLayout bvh_layout
Definition scene.h:72
bool background
Definition scene.h:91
bool use_bvh_unaligned_nodes
Definition scene.h:77
int texture_limit
Definition scene.h:82
float texture_resolution
Definition scene.h:81
bool auto_texture_cache
Definition scene.h:87
bool use_bvh_spatial_split
Definition scene.h:75
CurveShapeType hair_shape
Definition scene.h:80
int num_bvh_time_steps
Definition scene.h:78
int hair_subdivisions
Definition scene.h:79
BVHType bvh_type
Definition scene.h:74
bool use_bvh_compact_structure
Definition scene.h:76
bool use_texture_cache
Definition scene.h:85
ShadingSystem shadingsystem
Definition scene.h:65
Definition scene.h:133
Film * film
Definition scene.h:147
T * create_node(Args &&...)=delete
DeviceInfo denoise_device
ShadingSystem shadingsystem
DeviceInfo device
double get_time() const
Definition time.h:52
#define printf
DenoiserQuality
Definition denoise.h:55
@ DENOISER_QUALITY_FAST
Definition denoise.h:58
@ DENOISER_QUALITY_NUM
Definition denoise.h:59
@ DENOISER_QUALITY_BALANCED
Definition denoise.h:57
@ DENOISER_QUALITY_HIGH
Definition denoise.h:56
DenoiserPrefilter
Definition denoise.h:39
@ DENOISER_PREFILTER_FAST
Definition denoise.h:46
@ DENOISER_PREFILTER_NONE
Definition denoise.h:42
@ DENOISER_PREFILTER_NUM
Definition denoise.h:52
@ DENOISER_PASS_NONE
Definition denoise.h:27
@ DENOISER_PASS_DEPTH
Definition denoise.h:32
@ DENOISER_PASS_ROUGHNESS
Definition denoise.h:31
@ DENOISER_PASS_NORMAL
Definition denoise.h:30
@ DENOISER_PASS_ALBEDO
Definition denoise.h:28
@ DENOISER_PASS_SPECULAR_ALBEDO
Definition denoise.h:29
@ DENOISER_PASS_BACKWARD_MOTION
Definition denoise.h:33
@ DENOISER_PASS_SPECULAR_MOTION
Definition denoise.h:34
DenoiserType
Definition denoise.h:11
@ DENOISER_NONE
Definition denoise.h:17
@ DENOISER_NUM
Definition denoise.h:15
@ DENOISER_DLSS
Definition denoise.h:14
#define CCL_NAMESPACE_END
FilterType
Definition film.h:21
@ FILTER_NUM_TYPES
Definition film.h:26
@ FILTER_BOX
Definition film.h:22
@ FILTER_BLACKMAN_HARRIS
Definition film.h:24
uint hash_uint2(uint kx, uint ky)
#define INT_MAX
DirectLightSamplingType
@ DIRECT_LIGHT_SAMPLING_MIS
@ DIRECT_LIGHT_SAMPLING_NUM
CryptomatteType
@ CRYPT_ASSET
@ CRYPT_NONE
@ CRYPT_OBJECT
@ CRYPT_MATERIAL
CurveShapeType
@ CURVE_THICK
@ CURVE_NUM_SHAPE_TYPES
GuidingDirectionalSamplingType
@ GUIDING_DIRECTIONAL_SAMPLING_NUM_TYPES
@ GUIDING_DIRECTIONAL_SAMPLING_TYPE_RIS
SamplingPattern
@ SAMPLING_PATTERN_AUTOMATIC
@ SAMPLING_PATTERN_BLUE_NOISE_FIRST
@ SAMPLING_PATTERN_TABULATED_SOBOL
@ SAMPLING_PATTERN_BLUE_NOISE_PURE
@ SAMPLING_NUM_PATTERNS
PassType
@ PASS_EMISSION
@ PASS_POSITION
@ PASS_BACKGROUND
@ PASS_TRANSMISSION_DIRECT
@ PASS_VOLUME_DIRECT
@ PASS_UV
@ PASS_TRANSMISSION_COLOR
@ PASS_GUIDING_COLOR
@ PASS_DEPTH
@ PASS_MIST
@ PASS_VOLUME_SCATTER
@ PASS_TRANSMISSION_INDIRECT
@ PASS_BAKE_SEED
@ PASS_SHADOW_CATCHER
@ PASS_VOLUME_MAJORANT
@ PASS_DENOISING_NORMAL
@ PASS_DIFFUSE_DIRECT
@ PASS_MOTION
@ PASS_MATERIAL_ID
@ PASS_AO
@ PASS_COMBINED
@ PASS_DENOISING_BACKWARD_MOTION
@ PASS_DIFFUSE_INDIRECT
@ PASS_RENDER_TIME
@ PASS_GUIDING_PROBABILITY
@ PASS_ADAPTIVE_AUX_BUFFER
@ PASS_OBJECT_ID
@ PASS_DENOISING_SPECULAR_MOTION
@ PASS_DENOISING_ROUGHNESS
@ PASS_AOV_COLOR
@ PASS_NONE
@ PASS_DENOISING_SPECULAR_ALBEDO
@ PASS_VOLUME_INDIRECT
@ PASS_NORMAL
@ PASS_CRYPTOMATTE
@ PASS_DIFFUSE_COLOR
@ PASS_SAMPLE_COUNT
@ PASS_GLOSSY_DIRECT
@ PASS_DENOISING_ALBEDO
@ PASS_AOV_VALUE
@ PASS_GUIDING_AVG_ROUGHNESS
@ PASS_GLOSSY_COLOR
@ PASS_GLOSSY_INDIRECT
@ PASS_BAKE_DIFFERENTIAL
@ PASS_VOLUME_TRANSMIT
@ PASS_DENOISING_DEPTH
@ PASS_BAKE_PRIMITIVE
GuidingDistributionType
@ GUIDING_NUM_TYPES
@ GUIDING_TYPE_PARALLAX_AWARE_VMM
#define LOG_ERROR
Definition log.h:101
#define LOG_INFO
Definition log.h:106
void DEG_iterator_ids_end(BLI_Iterator *iter)
void DEG_iterator_objects_next(BLI_Iterator *iter)
const char * BKE_tempdir_session() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1283
@ R_TEXTURE_CACHE_AUTO_GENERATE
@ WO_MIST_INVERSE_QUADRATIC
void BKE_image_free_buffers_ex(Image *image, bool do_lock)
void DEG_iterator_ids_next(BLI_Iterator *iter)
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
void DEG_iterator_objects_end(BLI_Iterator *iter)
@ ID_RECALC_ALL
Definition DNA_ID.h:1190
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ VIEW_LAYER_CRYPTOMATTE_ASSET
@ VIEW_LAYER_CRYPTOMATTE_MATERIAL
@ VIEW_LAYER_CRYPTOMATTE_OBJECT
@ RE_ENGINE_PREVIEW
Definition RE_engine.h:64
void DEG_iterator_ids_begin(BLI_Iterator *iter, DEGIDIterData *data)
void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
@ R_BAKE_TARGET_IMAGE_TEXTURES
@ BVH_TYPE_DYNAMIC
Definition params.h:33
@ BVH_TYPE_STATIC
Definition params.h:40
PassMode
Definition pass.h:20
@ DENOISED
Definition pass.h:22
@ NOISY
Definition pass.h:21
#define sqrtf
@ SHADINGSYSTEM_OSL
@ SHADINGSYSTEM_SVM
#define min(a, b)
Definition sort.cc:38
bool string_startswith(const string_view s, const string_view start)
Definition string.cpp:106
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition string.cpp:25
BVHLayout bvh_layout
Definition debug.h:47
ustring name
Definition graph/node.h:178
DEGObjectIterSettings * settings
unsigned int recalc
Definition DNA_ID.h:446
ListBaseT< struct ParticleSystem > particlesystem
eObject_TransFlag transflag
struct Render * re
Definition RE_engine.h:148
ListBaseT< RenderPass > passes
Definition RE_pipeline.h:99
eViewLayerAOVFlag flag
eViewLayerAOVType type
ListBaseT< ViewLayerAOV > aovs
ListBaseT< ViewLayerLightgroup > lightgroups
eViewLayerCryptomatteFlags cryptomatte_flag
struct World * world_override
struct Material * mat_override
static blender::RenderData * engine_render_get(blender::RenderEngine *engine)
Definition sync.cpp:706
static bool get_known_pass_type(blender::RenderPass &b_pass, PassType &type, PassMode &mode)
Definition sync.cpp:739
#define MAP_PASS(passname, passtype, noisy)
static Pass * pass_add(Scene *scene, PassType type, const char *name, PassMode mode=PassMode::DENOISED)
Definition sync.cpp:819
static CCL_NAMESPACE_BEGIN const char * cryptomatte_prefix
Definition sync.cpp:48
ccl_device_inline bool is_light(const ccl_global KernelLightTreeEmitter *kemitter)
Definition tree.h:69
ccl_device_inline size_t divide_up(const size_t x, const size_t y)
Definition types_base.h:54