2 * Copyright 2011-2013 Blender Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "render/background.h"
18 #include "render/camera.h"
19 #include "render/film.h"
20 #include "render/graph.h"
21 #include "render/integrator.h"
22 #include "render/light.h"
23 #include "render/mesh.h"
24 #include "render/nodes.h"
25 #include "render/object.h"
26 #include "render/scene.h"
27 #include "render/shader.h"
28 #include "render/curves.h"
30 #include "device/device.h"
32 #include "blender/blender_sync.h"
33 #include "blender/blender_session.h"
34 #include "blender/blender_util.h"
36 #include "util/util_debug.h"
37 #include "util/util_foreach.h"
38 #include "util/util_opengl.h"
39 #include "util/util_hash.h"
45 BlenderSync::BlenderSync(BL::RenderEngine& b_engine,
46 BL::BlendData& b_data,
54 shader_map(&scene->shaders),
55 object_map(&scene->objects),
56 mesh_map(&scene->meshes),
57 light_map(&scene->lights),
58 particle_system_map(&scene->particle_systems),
68 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
69 dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate") : RNA_float_get(&cscene, "dicing_rate");
70 max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
73 BlenderSync::~BlenderSync()
79 bool BlenderSync::sync_recalc()
81 /* sync recalc flags from blender to cycles. actual update is done separate,
82 * so we can do it later on if doing it immediate is not suitable */
84 BL::BlendData::materials_iterator b_mat;
85 bool has_updated_objects = b_data.objects.is_updated();
86 for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
87 if(b_mat->is_updated() || (b_mat->node_tree() && b_mat->node_tree().is_updated())) {
88 shader_map.set_recalc(*b_mat);
91 Shader *shader = shader_map.find(*b_mat);
92 if(has_updated_objects && shader != NULL && shader->has_object_dependency) {
93 shader_map.set_recalc(*b_mat);
98 BL::BlendData::lamps_iterator b_lamp;
100 for(b_data.lamps.begin(b_lamp); b_lamp != b_data.lamps.end(); ++b_lamp)
101 if(b_lamp->is_updated() || (b_lamp->node_tree() && b_lamp->node_tree().is_updated()))
102 shader_map.set_recalc(*b_lamp);
104 bool dicing_prop_changed = false;
107 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
109 float updated_dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate")
110 : RNA_float_get(&cscene, "dicing_rate");
112 if(dicing_rate != updated_dicing_rate) {
113 dicing_rate = updated_dicing_rate;
114 dicing_prop_changed = true;
117 int updated_max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
119 if(max_subdivisions != updated_max_subdivisions) {
120 max_subdivisions = updated_max_subdivisions;
121 dicing_prop_changed = true;
125 BL::BlendData::objects_iterator b_ob;
127 for(b_data.objects.begin(b_ob); b_ob != b_data.objects.end(); ++b_ob) {
128 if(b_ob->is_updated()) {
129 object_map.set_recalc(*b_ob);
130 light_map.set_recalc(*b_ob);
133 if(object_is_mesh(*b_ob)) {
134 if(b_ob->is_updated_data() || b_ob->data().is_updated() ||
135 (dicing_prop_changed && object_subdivision_type(*b_ob, preview, experimental) != Mesh::SUBDIVISION_NONE))
137 BL::ID key = BKE_object_is_modified(*b_ob)? *b_ob: b_ob->data();
138 mesh_map.set_recalc(key);
141 else if(object_is_light(*b_ob)) {
142 if(b_ob->is_updated_data() || b_ob->data().is_updated())
143 light_map.set_recalc(*b_ob);
146 if(b_ob->is_updated_data()) {
147 BL::Object::particle_systems_iterator b_psys;
148 for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys)
149 particle_system_map.set_recalc(*b_ob);
153 BL::BlendData::meshes_iterator b_mesh;
155 for(b_data.meshes.begin(b_mesh); b_mesh != b_data.meshes.end(); ++b_mesh) {
156 if(b_mesh->is_updated()) {
157 mesh_map.set_recalc(*b_mesh);
161 BL::BlendData::worlds_iterator b_world;
163 for(b_data.worlds.begin(b_world); b_world != b_data.worlds.end(); ++b_world) {
164 if(world_map == b_world->ptr.data) {
165 if(b_world->is_updated() ||
166 (b_world->node_tree() && b_world->node_tree().is_updated()))
170 else if(b_world->node_tree() && b_world->use_nodes()) {
171 Shader *shader = scene->default_background;
172 if(has_updated_objects && shader->has_object_dependency) {
180 shader_map.has_recalc() ||
181 object_map.has_recalc() ||
182 light_map.has_recalc() ||
183 mesh_map.has_recalc() ||
184 particle_system_map.has_recalc() ||
185 BlendDataObjects_is_updated_get(&b_data.ptr) ||
191 void BlenderSync::sync_data(BL::RenderSettings& b_render,
192 BL::Depsgraph& b_depsgraph,
193 BL::SpaceView3D& b_v3d,
194 BL::Object& b_override,
195 int width, int height,
196 void **python_thread_state)
198 BL::ViewLayer b_view_layer = b_depsgraph.view_layer();
200 sync_view_layer(b_v3d, b_view_layer);
203 sync_shaders(b_depsgraph);
205 sync_curve_settings();
207 mesh_synced.clear(); /* use for objects and motion sync */
209 if(scene->need_motion() == Scene::MOTION_PASS ||
210 scene->need_motion() == Scene::MOTION_NONE ||
211 scene->camera->motion_position == Camera::MOTION_POSITION_CENTER)
213 sync_objects(b_depsgraph);
215 sync_motion(b_render,
219 python_thread_state);
226 void BlenderSync::sync_integrator()
228 BL::RenderSettings r = b_scene.render();
229 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
231 experimental = (get_enum(cscene, "feature_set") != 0);
233 Integrator *integrator = scene->integrator;
234 Integrator previntegrator = *integrator;
236 integrator->max_bounce = get_int(cscene, "max_bounces");
238 integrator->max_diffuse_bounce = get_int(cscene, "diffuse_bounces");
239 integrator->max_glossy_bounce = get_int(cscene, "glossy_bounces");
240 integrator->max_transmission_bounce = get_int(cscene, "transmission_bounces");
241 integrator->max_volume_bounce = get_int(cscene, "volume_bounces");
243 integrator->transparent_max_bounce = get_int(cscene, "transparent_max_bounces");
245 integrator->volume_max_steps = get_int(cscene, "volume_max_steps");
246 integrator->volume_step_size = get_float(cscene, "volume_step_size");
248 integrator->caustics_reflective = get_boolean(cscene, "caustics_reflective");
249 integrator->caustics_refractive = get_boolean(cscene, "caustics_refractive");
250 integrator->filter_glossy = get_float(cscene, "blur_glossy");
252 integrator->seed = get_int(cscene, "seed");
253 if(get_boolean(cscene, "use_animated_seed")) {
254 integrator->seed = hash_int_2d(b_scene.frame_current(),
255 get_int(cscene, "seed"));
256 if(b_scene.frame_subframe() != 0.0f) {
257 /* TODO(sergey): Ideally should be some sort of hash_merge,
258 * but this is good enough for now.
260 integrator->seed += hash_int_2d((int)(b_scene.frame_subframe() * (float)INT_MAX),
261 get_int(cscene, "seed"));
265 integrator->sampling_pattern = (SamplingPattern)get_enum(
268 SAMPLING_NUM_PATTERNS,
269 SAMPLING_PATTERN_SOBOL);
271 integrator->sample_clamp_direct = get_float(cscene, "sample_clamp_direct");
272 integrator->sample_clamp_indirect = get_float(cscene, "sample_clamp_indirect");
274 if(integrator->motion_blur != r.use_motion_blur()) {
275 scene->object_manager->tag_update(scene);
276 scene->camera->tag_update();
279 integrator->motion_blur = r.use_motion_blur();
282 integrator->method = (Integrator::Method)get_enum(cscene,
284 Integrator::NUM_METHODS,
287 integrator->sample_all_lights_direct = get_boolean(cscene, "sample_all_lights_direct");
288 integrator->sample_all_lights_indirect = get_boolean(cscene, "sample_all_lights_indirect");
289 integrator->light_sampling_threshold = get_float(cscene, "light_sampling_threshold");
291 int diffuse_samples = get_int(cscene, "diffuse_samples");
292 int glossy_samples = get_int(cscene, "glossy_samples");
293 int transmission_samples = get_int(cscene, "transmission_samples");
294 int ao_samples = get_int(cscene, "ao_samples");
295 int mesh_light_samples = get_int(cscene, "mesh_light_samples");
296 int subsurface_samples = get_int(cscene, "subsurface_samples");
297 int volume_samples = get_int(cscene, "volume_samples");
299 if(get_boolean(cscene, "use_square_samples")) {
300 integrator->diffuse_samples = diffuse_samples * diffuse_samples;
301 integrator->glossy_samples = glossy_samples * glossy_samples;
302 integrator->transmission_samples = transmission_samples * transmission_samples;
303 integrator->ao_samples = ao_samples * ao_samples;
304 integrator->mesh_light_samples = mesh_light_samples * mesh_light_samples;
305 integrator->subsurface_samples = subsurface_samples * subsurface_samples;
306 integrator->volume_samples = volume_samples * volume_samples;
309 integrator->diffuse_samples = diffuse_samples;
310 integrator->glossy_samples = glossy_samples;
311 integrator->transmission_samples = transmission_samples;
312 integrator->ao_samples = ao_samples;
313 integrator->mesh_light_samples = mesh_light_samples;
314 integrator->subsurface_samples = subsurface_samples;
315 integrator->volume_samples = volume_samples;
318 if(b_scene.render().use_simplify()) {
320 integrator->ao_bounces = get_int(cscene, "ao_bounces");
323 integrator->ao_bounces = get_int(cscene, "ao_bounces_render");
327 integrator->ao_bounces = 0;
330 if(integrator->modified(previntegrator))
331 integrator->tag_update(scene);
336 void BlenderSync::sync_film()
338 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
340 Film *film = scene->film;
341 Film prevfilm = *film;
343 film->exposure = get_float(cscene, "film_exposure");
344 film->filter_type = (FilterType)get_enum(cscene,
347 FILTER_BLACKMAN_HARRIS);
348 film->filter_width = (film->filter_type == FILTER_BOX)? 1.0f: get_float(cscene, "filter_width");
350 if(b_scene.world()) {
351 BL::WorldMistSettings b_mist = b_scene.world().mist_settings();
353 film->mist_start = b_mist.start();
354 film->mist_depth = b_mist.depth();
356 switch(b_mist.falloff()) {
357 case BL::WorldMistSettings::falloff_QUADRATIC:
358 film->mist_falloff = 2.0f;
360 case BL::WorldMistSettings::falloff_LINEAR:
361 film->mist_falloff = 1.0f;
363 case BL::WorldMistSettings::falloff_INVERSE_QUADRATIC:
364 film->mist_falloff = 0.5f;
369 if(film->modified(prevfilm))
370 film->tag_update(scene);
375 void BlenderSync::sync_view_layer(BL::SpaceView3D& /*b_v3d*/, BL::ViewLayer& b_view_layer)
378 uint layer_override = get_layer(b_engine.layer_override());
379 uint view_layers = layer_override ? layer_override : get_layer(b_scene.layers());
381 view_layer.name = b_view_layer.name();
383 view_layer.holdout_layer = 0;
384 view_layer.exclude_layer = 0;
386 view_layer.view_layer = view_layers & ~view_layer.exclude_layer;
387 view_layer.view_layer |= view_layer.exclude_layer & view_layer.holdout_layer;
389 view_layer.layer = (1 << 20) - 1;
390 view_layer.layer |= view_layer.holdout_layer;
392 view_layer.material_override = PointerRNA_NULL;
393 view_layer.use_background_shader = b_view_layer.use_sky();
394 view_layer.use_background_ao = b_view_layer.use_ao();
395 view_layer.use_surfaces = b_view_layer.use_solid();
396 view_layer.use_hair = b_view_layer.use_strand();
398 view_layer.bound_samples = false;
399 view_layer.samples = 0;
403 void BlenderSync::sync_images()
405 /* Sync is a convention for this API, but currently it frees unused buffers. */
407 const bool is_interface_locked = b_engine.render() &&
408 b_engine.render().use_lock_interface();
409 if(is_interface_locked == false && BlenderSession::headless == false) {
410 /* If interface is not locked, it's possible image is needed for
415 /* Free buffers used by images which are not needed for render. */
416 BL::BlendData::images_iterator b_image;
417 for(b_data.images.begin(b_image);
418 b_image != b_data.images.end();
421 /* TODO(sergey): Consider making it an utility function to check
422 * whether image is considered builtin.
424 const bool is_builtin = b_image->packed_file() ||
425 b_image->source() == BL::Image::source_GENERATED ||
426 b_image->source() == BL::Image::source_MOVIE ||
427 b_engine.is_preview();
428 if(is_builtin == false) {
429 b_image->buffers_free();
431 /* TODO(sergey): Free builtin images not used by any shader. */
436 PassType BlenderSync::get_pass_type(BL::RenderPass& b_pass)
438 string name = b_pass.name();
439 #define MAP_PASS(passname, passtype) if(name == passname) return passtype;
440 /* NOTE: Keep in sync with defined names from DNA_scene_types.h */
441 MAP_PASS("Combined", PASS_COMBINED);
442 MAP_PASS("Depth", PASS_DEPTH);
443 MAP_PASS("Mist", PASS_MIST);
444 MAP_PASS("Normal", PASS_NORMAL);
445 MAP_PASS("IndexOB", PASS_OBJECT_ID);
446 MAP_PASS("UV", PASS_UV);
447 MAP_PASS("Vector", PASS_MOTION);
448 MAP_PASS("IndexMA", PASS_MATERIAL_ID);
450 MAP_PASS("DiffDir", PASS_DIFFUSE_DIRECT);
451 MAP_PASS("GlossDir", PASS_GLOSSY_DIRECT);
452 MAP_PASS("TransDir", PASS_TRANSMISSION_DIRECT);
453 MAP_PASS("SubsurfaceDir", PASS_SUBSURFACE_DIRECT);
454 MAP_PASS("VolumeDir", PASS_VOLUME_DIRECT);
456 MAP_PASS("DiffInd", PASS_DIFFUSE_INDIRECT);
457 MAP_PASS("GlossInd", PASS_GLOSSY_INDIRECT);
458 MAP_PASS("TransInd", PASS_TRANSMISSION_INDIRECT);
459 MAP_PASS("SubsurfaceInd", PASS_SUBSURFACE_INDIRECT);
460 MAP_PASS("VolumeInd", PASS_VOLUME_INDIRECT);
462 MAP_PASS("DiffCol", PASS_DIFFUSE_COLOR);
463 MAP_PASS("GlossCol", PASS_GLOSSY_COLOR);
464 MAP_PASS("TransCol", PASS_TRANSMISSION_COLOR);
465 MAP_PASS("SubsurfaceCol", PASS_SUBSURFACE_COLOR);
467 MAP_PASS("Emit", PASS_EMISSION);
468 MAP_PASS("Env", PASS_BACKGROUND);
469 MAP_PASS("AO", PASS_AO);
470 MAP_PASS("Shadow", PASS_SHADOW);
472 #ifdef __KERNEL_DEBUG__
473 MAP_PASS("Debug BVH Traversed Nodes", PASS_BVH_TRAVERSED_NODES);
474 MAP_PASS("Debug BVH Traversed Instances", PASS_BVH_TRAVERSED_INSTANCES);
475 MAP_PASS("Debug BVH Intersections", PASS_BVH_INTERSECTIONS);
476 MAP_PASS("Debug Ray Bounces", PASS_RAY_BOUNCES);
478 MAP_PASS("Debug Render Time", PASS_RENDER_TIME);
484 int BlenderSync::get_denoising_pass(BL::RenderPass& b_pass)
486 string name = b_pass.name();
487 if(name.substr(0, 10) != "Denoising ") {
490 name = name.substr(10);
492 #define MAP_PASS(passname, offset) if(name == passname) return offset;
493 MAP_PASS("Normal", DENOISING_PASS_NORMAL);
494 MAP_PASS("Normal Variance", DENOISING_PASS_NORMAL_VAR);
495 MAP_PASS("Albedo", DENOISING_PASS_ALBEDO);
496 MAP_PASS("Albedo Variance", DENOISING_PASS_ALBEDO_VAR);
497 MAP_PASS("Depth", DENOISING_PASS_DEPTH);
498 MAP_PASS("Depth Variance", DENOISING_PASS_DEPTH_VAR);
499 MAP_PASS("Shadow A", DENOISING_PASS_SHADOW_A);
500 MAP_PASS("Shadow B", DENOISING_PASS_SHADOW_B);
501 MAP_PASS("Image", DENOISING_PASS_COLOR);
502 MAP_PASS("Image Variance", DENOISING_PASS_COLOR_VAR);
508 array<Pass> BlenderSync::sync_render_passes(BL::RenderLayer& b_rlay,
509 BL::ViewLayer& b_view_layer,
510 const SessionParams &session_params)
513 Pass::add(PASS_COMBINED, passes);
515 if(!session_params.device.advanced_shading) {
519 /* loop over passes */
520 BL::RenderLayer::passes_iterator b_pass_iter;
522 for(b_rlay.passes.begin(b_pass_iter); b_pass_iter != b_rlay.passes.end(); ++b_pass_iter) {
523 BL::RenderPass b_pass(*b_pass_iter);
524 PassType pass_type = get_pass_type(b_pass);
526 if(pass_type == PASS_MOTION && scene->integrator->motion_blur)
528 if(pass_type != PASS_NONE)
529 Pass::add(pass_type, passes);
532 PointerRNA crp = RNA_pointer_get(&b_view_layer.ptr, "cycles");
533 if(get_boolean(crp, "denoising_store_passes") &&
534 get_boolean(crp, "use_denoising"))
536 b_engine.add_pass("Denoising Normal", 3, "XYZ", b_view_layer.name().c_str());
537 b_engine.add_pass("Denoising Normal Variance", 3, "XYZ", b_view_layer.name().c_str());
538 b_engine.add_pass("Denoising Albedo", 3, "RGB", b_view_layer.name().c_str());
539 b_engine.add_pass("Denoising Albedo Variance", 3, "RGB", b_view_layer.name().c_str());
540 b_engine.add_pass("Denoising Depth", 1, "Z", b_view_layer.name().c_str());
541 b_engine.add_pass("Denoising Depth Variance", 1, "Z", b_view_layer.name().c_str());
542 b_engine.add_pass("Denoising Shadow A", 3, "XYV", b_view_layer.name().c_str());
543 b_engine.add_pass("Denoising Shadow B", 3, "XYV", b_view_layer.name().c_str());
544 b_engine.add_pass("Denoising Image", 3, "RGB", b_view_layer.name().c_str());
545 b_engine.add_pass("Denoising Image Variance", 3, "RGB", b_view_layer.name().c_str());
547 #ifdef __KERNEL_DEBUG__
548 if(get_boolean(crp, "pass_debug_bvh_traversed_nodes")) {
549 b_engine.add_pass("Debug BVH Traversed Nodes", 1, "X", b_view_layer.name().c_str());
550 Pass::add(PASS_BVH_TRAVERSED_NODES, passes);
552 if(get_boolean(crp, "pass_debug_bvh_traversed_instances")) {
553 b_engine.add_pass("Debug BVH Traversed Instances", 1, "X", b_view_layer.name().c_str());
554 Pass::add(PASS_BVH_TRAVERSED_INSTANCES, passes);
556 if(get_boolean(crp, "pass_debug_bvh_intersections")) {
557 b_engine.add_pass("Debug BVH Intersections", 1, "X", b_view_layer.name().c_str());
558 Pass::add(PASS_BVH_INTERSECTIONS, passes);
560 if(get_boolean(crp, "pass_debug_ray_bounces")) {
561 b_engine.add_pass("Debug Ray Bounces", 1, "X", b_view_layer.name().c_str());
562 Pass::add(PASS_RAY_BOUNCES, passes);
565 if(get_boolean(crp, "pass_debug_render_time")) {
566 b_engine.add_pass("Debug Render Time", 1, "X", b_view_layer.name().c_str());
567 Pass::add(PASS_RENDER_TIME, passes);
569 if(get_boolean(crp, "use_pass_volume_direct")) {
570 b_engine.add_pass("VolumeDir", 3, "RGB", b_view_layer.name().c_str());
571 Pass::add(PASS_VOLUME_DIRECT, passes);
573 if(get_boolean(crp, "use_pass_volume_indirect")) {
574 b_engine.add_pass("VolumeInd", 3, "RGB", b_view_layer.name().c_str());
575 Pass::add(PASS_VOLUME_INDIRECT, passes);
581 /* Scene Parameters */
583 SceneParams BlenderSync::get_scene_params(BL::Scene& b_scene,
586 BL::RenderSettings r = b_scene.render();
588 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
589 const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
591 if(shadingsystem == 0)
592 params.shadingsystem = SHADINGSYSTEM_SVM;
593 else if(shadingsystem == 1)
594 params.shadingsystem = SHADINGSYSTEM_OSL;
596 if(background || DebugFlags().viewport_static_bvh)
597 params.bvh_type = SceneParams::BVH_STATIC;
599 params.bvh_type = SceneParams::BVH_DYNAMIC;
601 params.use_bvh_spatial_split = RNA_boolean_get(&cscene, "debug_use_spatial_splits");
602 params.use_bvh_unaligned_nodes = RNA_boolean_get(&cscene, "debug_use_hair_bvh");
603 params.num_bvh_time_steps = RNA_int_get(&cscene, "debug_bvh_time_steps");
605 if(background && params.shadingsystem != SHADINGSYSTEM_OSL)
606 params.persistent_data = r.use_persistent_data();
608 params.persistent_data = false;
612 texture_limit = RNA_enum_get(&cscene, "texture_limit_render");
615 texture_limit = RNA_enum_get(&cscene, "texture_limit");
617 if(texture_limit > 0 && b_scene.render().use_simplify()) {
618 params.texture_limit = 1 << (texture_limit + 6);
621 params.texture_limit = 0;
624 params.bvh_layout = DebugFlags().cpu.bvh_layout;
629 /* Session Parameters */
631 bool BlenderSync::get_session_pause(BL::Scene& b_scene, bool background)
633 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
634 return (background)? false: get_boolean(cscene, "preview_pause");
637 SessionParams BlenderSync::get_session_params(BL::RenderEngine& b_engine,
638 BL::UserPreferences& b_userpref,
642 SessionParams params;
643 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
646 params.experimental = (get_enum(cscene, "feature_set") != 0);
649 BL::RenderSettings b_r = b_scene.render();
650 if(b_r.threads_mode() == BL::RenderSettings::threads_mode_FIXED)
651 params.threads = b_r.threads();
656 params.background = background;
659 vector<DeviceInfo>& devices = Device::available_devices();
661 /* device default CPU */
662 foreach(DeviceInfo& device, devices) {
663 if(device.type == DEVICE_CPU) {
664 params.device = device;
669 if(get_enum(cscene, "device") == 2) {
670 /* find network device */
671 foreach(DeviceInfo& info, devices)
672 if(info.type == DEVICE_NETWORK)
673 params.device = info;
675 else if(get_enum(cscene, "device") == 1) {
676 PointerRNA b_preferences;
678 BL::UserPreferences::addons_iterator b_addon_iter;
679 for(b_userpref.addons.begin(b_addon_iter); b_addon_iter != b_userpref.addons.end(); ++b_addon_iter) {
680 if(b_addon_iter->module() == "cycles") {
681 b_preferences = b_addon_iter->preferences().ptr;
687 COMPUTE_DEVICE_CPU = 0,
688 COMPUTE_DEVICE_CUDA = 1,
689 COMPUTE_DEVICE_OPENCL = 2,
690 COMPUTE_DEVICE_NUM = 3,
693 ComputeDevice compute_device = (ComputeDevice)get_enum(b_preferences,
694 "compute_device_type",
698 if(compute_device != COMPUTE_DEVICE_CPU) {
699 vector<DeviceInfo> used_devices;
700 RNA_BEGIN(&b_preferences, device, "devices") {
701 ComputeDevice device_type = (ComputeDevice)get_enum(device,
706 if(get_boolean(device, "use") &&
707 (device_type == compute_device || device_type == COMPUTE_DEVICE_CPU)) {
708 string id = get_string(device, "id");
709 foreach(DeviceInfo& info, devices) {
711 used_devices.push_back(info);
718 if(used_devices.size() == 1) {
719 params.device = used_devices[0];
721 else if(used_devices.size() > 1) {
722 params.device = Device::get_multi_device(used_devices,
726 /* Else keep using the CPU device that was set before. */
731 int samples = get_int(cscene, "samples");
732 int aa_samples = get_int(cscene, "aa_samples");
733 int preview_samples = get_int(cscene, "preview_samples");
734 int preview_aa_samples = get_int(cscene, "preview_aa_samples");
736 if(get_boolean(cscene, "use_square_samples")) {
737 aa_samples = aa_samples * aa_samples;
738 preview_aa_samples = preview_aa_samples * preview_aa_samples;
740 samples = samples * samples;
741 preview_samples = preview_samples * preview_samples;
744 if(get_enum(cscene, "progressive") == 0) {
746 params.samples = aa_samples;
749 params.samples = preview_aa_samples;
750 if(params.samples == 0)
751 params.samples = INT_MAX;
756 params.samples = samples;
759 params.samples = preview_samples;
760 if(params.samples == 0)
761 params.samples = INT_MAX;
766 if(params.device.type != DEVICE_CPU && !background) {
767 /* currently GPU could be much slower than CPU when using tiles,
768 * still need to be investigated, but meanwhile make it possible
769 * to work in viewport smoothly
771 int debug_tile_size = get_int(cscene, "debug_tile_size");
773 params.tile_size = make_int2(debug_tile_size, debug_tile_size);
776 int tile_x = b_engine.tile_x();
777 int tile_y = b_engine.tile_y();
779 params.tile_size = make_int2(tile_x, tile_y);
782 if((BlenderSession::headless == false) && background) {
783 params.tile_order = (TileOrder)get_enum(cscene, "tile_order");
786 params.tile_order = TILE_BOTTOM_TO_TOP;
789 /* other parameters */
790 params.start_resolution = get_int(cscene, "preview_start_resolution");
791 params.pixel_size = b_engine.get_preview_pixel_size(b_scene);
793 /* other parameters */
794 params.cancel_timeout = (double)get_float(cscene, "debug_cancel_timeout");
795 params.reset_timeout = (double)get_float(cscene, "debug_reset_timeout");
796 params.text_timeout = (double)get_float(cscene, "debug_text_timeout");
798 /* progressive refine */
799 params.progressive_refine = get_boolean(cscene, "use_progressive_refine") &&
800 !b_r.use_save_buffers();
802 if(params.progressive_refine) {
803 BL::Scene::view_layers_iterator b_view_layer;
804 for(b_scene.view_layers.begin(b_view_layer); b_view_layer != b_scene.view_layers.end(); ++b_view_layer) {
805 PointerRNA crl = RNA_pointer_get(&b_view_layer->ptr, "cycles");
806 if(get_boolean(crl, "use_denoising")) {
807 params.progressive_refine = false;
813 if(params.progressive_refine)
814 params.progressive = true;
816 params.progressive = false;
818 params.start_resolution = INT_MAX;
819 params.pixel_size = 1;
822 params.progressive = true;
824 /* shading system - scene level needs full refresh */
825 const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
827 if(shadingsystem == 0)
828 params.shadingsystem = SHADINGSYSTEM_SVM;
829 else if(shadingsystem == 1)
830 params.shadingsystem = SHADINGSYSTEM_OSL;
832 /* color managagement */
833 params.display_buffer_linear = GLEW_ARB_half_float_pixel &&
834 b_engine.support_display_space_shader(b_scene);
836 if(b_engine.is_preview()) {
837 /* For preview rendering we're using same timeout as
838 * blender's job update.
840 params.progressive_update_timeout = 0.1;