52 Shader *synced_shader = (id) ? shader_map.
find(
id) :
nullptr;
53 Shader *shader = (synced_shader) ? synced_shader : default_shader;
81 if (value >= num_values) {
89 const int value = b_mat.displacement_method;
95 const int value = b_node.interpolation;
102 const int value = b_node.extension;
108 const int value = b_image.alpha_mode;
141 return ustring(name);
147 const string_view sname(name);
174 return ustring(default_value.value);
182 return make_float3(default_value.value[0], default_value.value[1], default_value.value[2]);
190 return default_value.
value;
198 return make_float3(default_value.value[0], default_value.value[1], default_value.value[2]);
203 switch (b_socket.
type) {
232 switch (input->
type()) {
235 node->set(socket, default_value.value);
240 const auto &default_value =
244 node->set(socket, default_value.value ? 1 : 0);
248 node->set(socket, default_value.value);
254 const float *value = default_value.
value;
262 const float *value = default_value.
value;
269 (ustring)blender_absolute_path(b_data, &b_id, default_value.value).c_str());
283 mapping->set_tex_mapping_translation(
285 mapping->set_tex_mapping_rotation(
287 mapping->set_tex_mapping_scale(
316 LOG_DFATAL <<
"Unhandled data type " << int(data_type);
329 const std::optional<RaycastNode::AttributeOutputType> attribute_output_type =
331 if (!attribute_output_type) {
335 const string input_identifier(
336 RaycastSampleAttributeItemsAccessor::input_socket_identifier_for_item(item));
337 const ustring output_identifier(
338 RaycastSampleAttributeItemsAccessor::output_socket_identifier_for_item(item));
342 raycast->add_output_attribute_socket(
343 attribute_name, *attribute_output_type, output_identifier);
348 const ustring alpha_output_identifier(
349 RaycastSampleAttributeItemsAccessor::output_socket_identifier_for_item_alpha(item));
350 raycast->add_output_attribute_socket(
364 using blender::operator
""_ustr;
368 if (b_node.is_type(
"ShaderNodeRGBCurve"_ustr)) {
374 curvemapping_color_to_array(mapping, curve_mapping_curves,
RAMP_TABLE_SIZE,
true);
375 curvemapping_minmax(mapping, 4, &min_x, &max_x);
378 curves->set_curves(curve_mapping_curves);
382 if (b_node.is_type(
"ShaderNodeVectorCurve"_ustr)) {
388 curvemapping_color_to_array(mapping, curve_mapping_curves,
RAMP_TABLE_SIZE,
false);
389 curvemapping_minmax(mapping, 3, &min_x, &max_x);
392 curves->set_curves(curve_mapping_curves);
396 else if (b_node.is_type(
"ShaderNodeFloatCurve"_ustr)) {
402 curvemapping_float_to_array(mapping, curve_mapping_curve,
RAMP_TABLE_SIZE);
403 curvemapping_minmax(mapping, 1, &min_x, &max_x);
404 curve->set_min_x(min_x);
405 curve->set_max_x(max_x);
406 curve->set_curve(curve_mapping_curve);
410 else if (b_node.is_type(
"ShaderNodeValToRGB"_ustr)) {
415 colorramp_to_array(b_color_ramp, ramp_values, ramp_alpha,
RAMP_TABLE_SIZE);
416 ramp->set_ramp(ramp_values);
417 ramp->set_ramp_alpha(ramp_alpha);
421 else if (b_node.is_type(
"ShaderNodeRGB"_ustr)) {
426 else if (b_node.is_type(
"FunctionNodeInputVector"_ustr)) {
432 else if (b_node.is_type(
"ShaderNodeValue"_ustr)) {
437 else if (b_node.is_type(
"FunctionNodeInputBool"_ustr)) {
443 else if (b_node.is_type(
"FunctionNodeInputInt"_ustr)) {
449 else if (b_node.is_type(
"ShaderNodeCameraData"_ustr)) {
452 else if (b_node.is_type(
"ShaderNodeInvert"_ustr)) {
455 else if (b_node.is_type(
"ShaderNodeGamma"_ustr)) {
458 else if (b_node.is_type(
"ShaderNodeBrightContrast"_ustr)) {
461 else if (b_node.is_type(
"ShaderNodeMixRGB"_ustr)) {
467 else if (b_node.is_type(
"ShaderNodeMix"_ustr)) {
472 mix_node->set_use_clamp(
storage.clamp_factor);
477 mix_node->set_use_clamp(
storage.clamp_factor);
484 mix_node->set_use_clamp(
storage.clamp_factor);
485 mix_node->set_use_clamp_result(
storage.clamp_result);
490 mix_node->set_use_clamp(
storage.clamp_factor);
494 else if (b_node.is_type(
"ShaderNodeSeparateColor"_ustr)) {
498 node = separate_node;
500 else if (b_node.is_type(
"ShaderNodeCombineColor"_ustr)) {
506 else if (b_node.is_type(
"ShaderNodeSeparateXYZ"_ustr)) {
509 else if (b_node.is_type(
"FunctionNodeGetVectorComponent"_ustr)) {
512 else if (b_node.is_type(
"ShaderNodeCombineXYZ"_ustr)) {
515 else if (b_node.is_type(
"ShaderNodeHueSaturation"_ustr)) {
518 else if (b_node.is_type(
"ShaderNodeRGBToBW"_ustr)) {
521 else if (b_node.is_type(
"ShaderNodeMapRange"_ustr)) {
525 vector_map_range_node->set_use_clamp(
storage.clamp);
527 node = vector_map_range_node;
531 map_range_node->set_clamp(
storage.clamp);
533 node = map_range_node;
536 else if (b_node.is_type(
"ShaderNodeClamp"_ustr)) {
541 else if (b_node.is_type(
"ShaderNodeMath"_ustr)) {
544 math_node->set_use_clamp(b_node.
custom2);
547 else if (b_node.is_type(
"FunctionNodeBooleanMath"_ustr)) {
550 node = boolean_math_node;
552 else if (b_node.is_type(
"FunctionNodeIntegerMath"_ustr)) {
555 node = integer_math_node;
557 else if (b_node.is_type(
"ShaderNodeVectorMath"_ustr)) {
560 node = vector_math_node;
562 else if (b_node.is_type(
"ShaderNodeVectorRotate"_ustr)) {
565 vector_rotate_node->set_invert(b_node.
custom2);
566 node = vector_rotate_node;
568 else if (b_node.is_type(
"ShaderNodeVectorTransform"_ustr)) {
576 else if (b_node.is_type(
"ShaderNodeNormal"_ustr)) {
581 else if (b_node.is_type(
"ShaderNodeMapping"_ustr)) {
586 else if (b_node.is_type(
"ShaderNodeFresnel"_ustr)) {
589 else if (b_node.is_type(
"ShaderNodeLayerWeight"_ustr)) {
592 else if (b_node.is_type(
"ShaderNodeAddShader"_ustr)) {
595 else if (b_node.is_type(
"ShaderNodeMixShader"_ustr)) {
598 else if (b_node.is_type(
"ShaderNodeAttribute"_ustr)) {
604 else if (b_node.is_type(
"ShaderNodeBackground"_ustr)) {
607 else if (b_node.is_type(
"ShaderNodeHoldout"_ustr)) {
610 else if (b_node.is_type(
"ShaderNodeBsdfDiffuse"_ustr)) {
613 else if (b_node.is_type(
"ShaderNodeSubsurfaceScattering"_ustr)) {
633 else if (b_node.is_type(
"ShaderNodeBsdfMetallic"_ustr)) {
658 else if (b_node.is_type(
"ShaderNodeBsdfAnisotropic"_ustr)) {
677 else if (b_node.is_type(
"ShaderNodeBsdfGlass"_ustr)) {
692 else if (b_node.is_type(
"ShaderNodeBsdfRefraction"_ustr)) {
704 else if (b_node.is_type(
"ShaderNodeBsdfToon"_ustr)) {
716 else if (b_node.is_type(
"ShaderNodeBsdfHair"_ustr)) {
728 else if (b_node.is_type(
"ShaderNodeBsdfHairPrincipled"_ustr)) {
737 node = principled_hair;
739 else if (b_node.is_type(
"ShaderNodeBsdfPrincipled"_ustr)) {
765 else if (b_node.is_type(
"ShaderNodeBsdfTranslucent"_ustr)) {
768 else if (b_node.is_type(
"ShaderNodeBsdfTransparent"_ustr)) {
771 else if (b_node.is_type(
"ShaderNodeBsdfRayPortal"_ustr)) {
774 else if (b_node.is_type(
"ShaderNodeBsdfSheen"_ustr)) {
786 else if (b_node.is_type(
"ShaderNodeEmission"_ustr)) {
789 else if (b_node.is_type(
"ShaderNodeAmbientOcclusion"_ustr)) {
791 ao->set_samples(b_node.
custom1);
796 else if (b_node.is_type(
"ShaderNodeVolumeScatter"_ustr)) {
817 else if (b_node.is_type(
"ShaderNodeVolumeAbsorption"_ustr)) {
820 else if (b_node.is_type(
"ShaderNodeVolumeCoefficients"_ustr)) {
841 else if (b_node.is_type(
"ShaderNodeVolumePrincipled"_ustr)) {
845 else if (b_node.is_type(
"ShaderNodeNewGeometry"_ustr)) {
848 else if (b_node.is_type(
"ShaderNodeWireframe"_ustr)) {
850 wire->set_use_pixel_size(b_node.
custom1);
853 else if (b_node.is_type(
"ShaderNodeWavelength"_ustr)) {
856 else if (b_node.is_type(
"ShaderNodeBlackbody"_ustr)) {
859 else if (b_node.is_type(
"ShaderNodeLightPath"_ustr)) {
862 else if (b_node.is_type(
"ShaderNodeLightFalloff"_ustr)) {
865 else if (b_node.is_type(
"ShaderNodeObjectInfo"_ustr)) {
868 else if (b_node.is_type(
"ShaderNodeParticleInfo"_ustr)) {
871 else if (b_node.is_type(
"ShaderNodeHairInfo"_ustr)) {
874 else if (b_node.is_type(
"ShaderNodePointInfo"_ustr)) {
877 else if (b_node.is_type(
"ShaderNodeVolumeInfo"_ustr)) {
880 else if (b_node.is_type(
"ShaderNodeVertexColor"_ustr)) {
883 vertex_color_node->set_layer_name(ustring(
storage.layer_name));
884 node = vertex_color_node;
886 else if (b_node.is_type(
"ShaderNodeBump"_ustr)) {
888 bump->set_invert(b_node.
custom1);
891 else if (b_node.is_type(
"ShaderNodeScript"_ustr)) {
895 const string bytecode_hash =
storage.bytecode_hash;
896 if (!bytecode_hash.empty()) {
897 node = OSLShaderManager::osl_node(graph, scene,
"", bytecode_hash,
storage.bytecode);
900 const string absolute_filepath = blender_absolute_path(
902 node = OSLShaderManager::osl_node(graph, scene, absolute_filepath,
"");
910 else if (b_node.is_type(
"ShaderNodeTexImage"_ustr)) {
926 image->set_colorspace(ustring(b_image->colorspace_settings.name));
941 const bool is_builtin = image_is_builtin(*b_image, b_engine);
950 const int scene_frame = b_scene.
r.
cfra;
951 const int image_frame = image_user_frame_number(b_image_user, *b_image, scene_frame);
954 make_unique<BlenderImageLoader>(b_image,
959 image->image_params());
963 loaders.reserve(
image->get_tiles().size());
964 for (
const int tile_number :
image->get_tiles()) {
965 loaders.push_back(make_unique<BlenderImageLoader>(
974 image->image_params());
978 const ustring filename = ustring(
979 image_user_file_path(b_data, b_image_user, *b_image, b_scene.
r.
cfra));
980 image->set_filename(filename);
985 else if (b_node.is_type(
"ShaderNodeTexEnvironment"_ustr)) {
999 env->set_colorspace(ustring(b_image->colorspace_settings.name));
1003 const bool is_builtin = image_is_builtin(*b_image, b_engine);
1006 const int scene_frame = b_scene.
r.
cfra;
1007 const int image_frame = image_user_frame_number(b_image_user, *b_image, scene_frame);
1009 make_unique<BlenderImageLoader>(b_image,
1018 ustring(image_user_file_path(b_data, b_image_user, *b_image, b_scene.
r.
cfra)));
1023 else if (b_node.is_type(
"ShaderNodeTexGradient"_ustr)) {
1031 else if (b_node.is_type(
"ShaderNodeTexVoronoi"_ustr)) {
1034 voronoi->set_dimensions(
storage.dimensions);
1037 voronoi->set_use_normalize(
storage.normalize);
1042 else if (b_node.is_type(
"ShaderNodeTexMagic"_ustr)) {
1045 magic->set_depth(
storage.depth);
1050 else if (b_node.is_type(
"ShaderNodeTexWave"_ustr)) {
1061 else if (b_node.is_type(
"ShaderNodeTexChecker"_ustr)) {
1068 else if (b_node.is_type(
"ShaderNodeTexBrick"_ustr)) {
1071 brick->set_offset(
storage.offset);
1072 brick->set_offset_frequency(
storage.offset_freq);
1073 brick->set_squash(
storage.squash);
1074 brick->set_squash_frequency(
storage.squash_freq);
1079 else if (b_node.is_type(
"ShaderNodeTexNoise"_ustr)) {
1089 else if (b_node.is_type(
"ShaderNodeTexGabor"_ustr)) {
1097 else if (b_node.is_type(
"ShaderNodeTexCoord"_ustr)) {
1099 tex_coord->set_from_dupli(b_node.
custom1);
1101 tex_coord->set_use_transform(
true);
1102 tex_coord->set_ob_tfm(
1103 get_transform(blender::id_cast<const blender::Object *>(b_object)->object_to_world()));
1107 else if (b_node.is_type(
"ShaderNodeTexSky"_ustr)) {
1113 sky->set_turbidity(
storage.turbidity);
1114 sky->set_ground_albedo(
storage.ground_albedo);
1115 sky->set_sun_disc(
storage.sun_disc);
1116 sky->set_sun_size(
storage.sun_size);
1117 sky->set_sun_intensity(
storage.sun_intensity);
1118 sky->set_sun_elevation(
storage.sun_elevation);
1119 sky->set_sun_rotation(
storage.sun_rotation);
1120 sky->set_altitude(
storage.altitude);
1121 sky->set_air_density(
storage.air_density);
1122 sky->set_aerosol_density(
storage.aerosol_density);
1123 sky->set_ozone_density(
storage.ozone_density);
1128 else if (b_node.is_type(
"ShaderNodeTexIES"_ustr)) {
1133 ies->set_filename(ustring(blender_absolute_path(b_data, &b_ntree.
id,
storage.filepath)));
1136 ustring ies_content = ustring(get_text_datablock_content(b_node.
id));
1137 ies->set_ies(ies_content);
1142 else if (b_node.is_type(
"ShaderNodeTexWhiteNoise"_ustr)) {
1144 white_noise_node->set_dimensions(b_node.
custom1);
1145 node = white_noise_node;
1147 else if (b_node.is_type(
"ShaderNodeNormalMap"_ustr)) {
1151 nmap->set_attribute(ustring(
storage.uv_map));
1156 else if (b_node.is_type(
"ShaderNodeRadialTiling"_ustr)) {
1159 radial_tiling->set_use_normalize(
storage.normalize);
1160 node = radial_tiling;
1162 else if (b_node.is_type(
"ShaderNodeTangent"_ustr)) {
1167 tangent->set_attribute(ustring(
storage.uv_map));
1170 else if (b_node.is_type(
"ShaderNodeUVMap"_ustr)) {
1173 uvm->set_attribute(ustring(
storage.uv_map));
1174 uvm->set_from_dupli(b_node.
custom1);
1177 else if (b_node.is_type(
"ShaderNodeBevel"_ustr)) {
1179 bevel->set_samples(b_node.
custom1);
1182 else if (b_node.is_type(
"ShaderNodeDisplacement"_ustr)) {
1187 else if (b_node.is_type(
"ShaderNodeVectorDisplacement"_ustr)) {
1190 disp->set_attribute(ustring(
""));
1193 else if (b_node.is_type(
"ShaderNodeOutputAOV"_ustr)) {
1196 aov->set_name(ustring(
storage.name));
1199 else if (b_node.is_type(
"ShaderNodeRaycast"_ustr)) {
1201 raycast->set_only_local(b_node.
custom1);
1205 else if (b_node.is_type(
"GeometryNodeInputSceneTime"_ustr)) {
1229 using blender::operator
""_ustr;
1240 if (b_node.is_type(
"ShaderNodeMix"_ustr)) {
1267 input =
node->input(name.c_str());
1289 input =
node->input(name.c_str());
1300 using blender::operator
""_ustr;
1306 if (name ==
"Shader") {
1311 if (b_node.is_type(
"ShaderNodeMix"_ustr)) {
1325 else if (b_node.is_type(
"FunctionNodeInputVector"_ustr)) {
1328 if (name ==
"Vector") {
1342 blender::Depsgraph &b_depsgraph,
1352 blender::Depsgraph &b_depsgraph,
1358 using blender::operator
""_ustr;
1368 if (b_node->is_muted() || b_node->is_reroute()) {
1381 input_map.emplace(b_link.
in, proxy->
inputs[0]);
1385 else if (b_node->is_group()) {
1386 blender::bNodeTree *b_group_ntree = blender::id_cast<blender::bNodeTree *>(b_node->id);
1404 group_proxy_input_map[b_input->identifier] = proxy;
1406 input_map.emplace(b_input, proxy->
inputs[0]);
1419 group_proxy_output_map[b_output->identifier] = proxy;
1421 output_map[b_output] = proxy->
outputs[0];
1424 if (b_group_ntree) {
1432 group_proxy_input_map,
1433 group_proxy_output_map);
1436 else if (b_node->is_type(
"NodeGroupInput"_ustr)) {
1439 const ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output->identifier);
1440 if (proxy_it != proxy_input_map.end()) {
1443 output_map[b_output] = proxy->
outputs[0];
1447 else if (b_node->is_type(
"NodeGroupOutput"_ustr)) {
1452 const ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input->identifier);
1453 if (proxy_it != proxy_output_map.end()) {
1456 input_map.emplace(b_input, proxy->
inputs[0]);
1467 if (b_node == output_node) {
1471 node =
add_node(scene, b_engine, b_data, b_scene, graph, b_ntree, *b_node);
1477 if (!b_input->is_available()) {
1486 input_map.emplace(b_input, input);
1491 if (!b_output->is_available()) {
1500 output_map[b_output] =
output;
1511 b_link->tosock->is_available()) ||
1521 const PtrOutputMap::iterator output_it = output_map.find(b_from_sock);
1522 if (output_it != output_map.end()) {
1523 output = output_it->second;
1530 auto inputs = input_map.equal_range(b_to_sock);
1531 for (PtrInputMap::iterator input_it = inputs.first; input_it != inputs.second; ++input_it) {
1533 if (input !=
nullptr) {
1542 blender::Depsgraph &b_depsgraph,
1545 if (!DEG_is_active(&b_depsgraph)) {
1551 std::lock_guard
lock(tree_orig->runtime->shader_node_errors_mutex);
1552 tree_orig->runtime->shader_node_errors.lookup_or_add_default(error.node->identifier)
1553 .add({error.type, error.message});
1562 blender::Depsgraph &b_depsgraph,
1587 BKE_id_free(
nullptr, &localtree->
id);
1594 blender::Depsgraph &b_depsgraph,
1598 static const ProxyMap empty_proxy_map;
1611void BlenderSync::resolve_view_layer_attributes(
Shader *shader,
1613 blender::Depsgraph &b_depsgraph)
1615 bool updated =
false;
1618 if (
node->is_a(AttributeNode::get_node_type())) {
1619 AttributeNode *attr_node =
static_cast<AttributeNode *
>(
node);
1621 std::string real_name;
1633 const float val_avg = (value.
x + value.
y + value.
z) / 3.0f;
1640 val_float = (
output->name() ==
"Alpha") ? value.
w : val_avg;
1644 val_float = val_avg;
1648 for (ShaderInput *sock :
output->links) {
1650 sock->
set(val_float);
1653 sock->
set(val_float3);
1663 attr_node->set_attribute(ustring());
1670 shader_map.set_flag(shader, SHADER_WITH_LAYER_ATTRS);
1673 shader_map.clear_flag(shader, SHADER_WITH_LAYER_ATTRS);
1677bool BlenderSync::scene_attr_needs_recalc(
Shader *shader, blender::Depsgraph &b_depsgraph)
1679 if (shader && shader_map.test_flag(shader, SHADER_WITH_LAYER_ATTRS)) {
1682 return shader_map.check_recalc(&scene->id) ||
1683 shader_map.check_recalc(
reinterpret_cast<blender::ID *
>(scene->world)) ||
1684 shader_map.check_recalc(
reinterpret_cast<blender::ID *
>(scene->camera));
1692void BlenderSync::sync_materials(blender::Depsgraph &b_depsgraph,
1696 shader_map.set_default(scene->default_surface);
1699 set<Shader *> updated_shaders;
1713 for (blender::ViewLayerAOV &b_aov : b_view_layer->
aovs) {
1719 const bool aovs_changed_between_view_layers = new_shader_view_layer_aovs !=
1720 shader_view_layer_aovs;
1722 blender::DEGIDIterData
data{};
1723 data.graph = &b_depsgraph;
1739 if (shader_map.add_or_update(&shader, &b_mat.id) || update_all ||
1740 scene_attr_needs_recalc(shader, b_depsgraph) || aovs_changed_between_view_layers ||
1743 unique_ptr<ShaderGraph> graph = make_unique<ShaderGraph>();
1746 shader->set_pass_id(b_mat.index);
1749 if (b_mat.nodetree) {
1750 add_nodes(scene, *b_engine, *b_data, *b_scene, b_depsgraph, graph.get(), *b_mat.nodetree);
1753 DiffuseBsdfNode *diffuse = graph->create_node<DiffuseBsdfNode>();
1754 diffuse->set_color(
make_float3(b_mat.r, b_mat.g, b_mat.b));
1756 ShaderNode *
out = graph->output();
1757 graph->connect(diffuse->
output(
"BSDF"),
out->input(
"Surface"));
1760 resolve_view_layer_attributes(shader, graph.get(), b_depsgraph);
1767 shader->set_use_bump_map_correction(get_boolean(cmat,
"use_bump_map_correction"));
1770 shader->set_volume_step_rate(get_float(cmat,
"volume_step_rate"));
1785 pool.
push([graph = shader->
graph.get(), scene = scene] { graph->simplify(scene); });
1789 updated_shaders.insert(shader);
1804 shader_view_layer_aovs = std::move(new_shader_view_layer_aovs);
1806 for (Shader *shader : updated_shaders) {
1813void BlenderSync::sync_world(blender::Depsgraph &b_depsgraph,
1820 Integrator *integrator = scene->integrator;
1822 blender::PointerRNA cscene =
RNA_pointer_get(&scene_rna_ptr,
"cycles");
1824 blender::World *b_world = view_layer.world_override ? view_layer.world_override : b_scene->world;
1826 const BlenderViewportParameters new_viewport_parameters(b_screen, b_v3d, use_developer_ui);
1828 Shader *shader = scene->default_background;
1830 if (world_recalc || update_all || b_world != world_map ||
1831 viewport_parameters.shader_modified(new_viewport_parameters) ||
1832 scene_attr_needs_recalc(shader, b_depsgraph) || (shader->
has_time_dependency && update_time))
1834 unique_ptr<ShaderGraph> graph = make_unique<ShaderGraph>();
1837 if (new_viewport_parameters.use_scene_world && b_world && b_world->nodetree) {
1838 add_nodes(scene, *b_engine, *b_data, *b_scene, b_depsgraph, graph.get(), *b_world->nodetree);
1842 blender::PointerRNA cworld =
RNA_pointer_get(&world_rna_ptr,
"cycles");
1845 shader->set_volume_step_rate(get_float(cworld,
"volume_step_size"));
1847 else if (new_viewport_parameters.use_scene_world && b_world) {
1848 BackgroundNode *background = graph->create_node<BackgroundNode>();
1849 background->set_color(
make_float3(b_world->horr, b_world->horg, b_world->horb));
1851 ShaderNode *
out = graph->output();
1852 graph->connect(background->
output(
"Background"),
out->input(
"Surface"));
1854 else if (!new_viewport_parameters.use_scene_world) {
1857 world_color =
make_float3(b_world->horr, b_world->horg, b_world->horb);
1863 BackgroundNode *background = graph->create_node<BackgroundNode>();
1864 LightPathNode *light_path = graph->create_node<LightPathNode>();
1866 MixNode *mix_scene_with_background = graph->create_node<MixNode>();
1867 mix_scene_with_background->set_color2(world_color);
1869 EnvironmentTextureNode *texture_environment = graph->create_node<EnvironmentTextureNode>();
1871 float3 rotation_z = texture_environment->get_tex_mapping_rotation();
1872 rotation_z[2] = new_viewport_parameters.studiolight_rotate_z;
1873 texture_environment->set_tex_mapping_rotation(rotation_z);
1874 texture_environment->set_filename(new_viewport_parameters.studiolight_path);
1876 MixNode *mix_intensity = graph->create_node<MixNode>();
1878 mix_intensity->set_fac(1.0f);
1879 mix_intensity->set_color2(
make_float3(new_viewport_parameters.studiolight_intensity,
1880 new_viewport_parameters.studiolight_intensity,
1881 new_viewport_parameters.studiolight_intensity));
1883 TextureCoordinateNode *texture_coordinate = graph->create_node<TextureCoordinateNode>();
1885 MixNode *mix_background_with_environment = graph->create_node<MixNode>();
1886 mix_background_with_environment->set_fac(
1887 new_viewport_parameters.studiolight_background_alpha);
1888 mix_background_with_environment->set_color1(world_color);
1890 ShaderNode *
out = graph->output();
1892 graph->connect(texture_coordinate->
output(
"Generated"),
1893 texture_environment->
input(
"Vector"));
1894 graph->connect(texture_environment->
output(
"Color"), mix_intensity->
input(
"Color1"));
1895 graph->connect(light_path->output(
"Is Camera Ray"), mix_scene_with_background->input(
"Fac"));
1896 graph->connect(mix_intensity->
output(
"Color"), mix_scene_with_background->input(
"Color1"));
1897 graph->connect(mix_intensity->
output(
"Color"),
1898 mix_background_with_environment->input(
"Color2"));
1899 graph->connect(mix_background_with_environment->output(
"Color"),
1900 mix_scene_with_background->input(
"Color2"));
1901 graph->connect(mix_scene_with_background->output(
"Color"), background->
input(
"Color"));
1902 graph->connect(background->
output(
"Background"),
out->input(
"Surface"));
1908 blender::PointerRNA cvisibility =
RNA_pointer_get(&world_rna_ptr,
"cycles_visibility");
1922 background->set_visibility(visibility);
1925 resolve_view_layer_attributes(shader, graph.get(), b_depsgraph);
1933 enum { FAST_GI_METHOD_REPLACE = 0, FAST_GI_METHOD_ADD = 1, FAST_GI_METHOD_NUM };
1935 const bool use_fast_gi = get_boolean(cscene,
"use_fast_gi");
1937 const int fast_gi_method = get_enum(
1938 cscene,
"fast_gi_method", FAST_GI_METHOD_NUM, FAST_GI_METHOD_REPLACE);
1939 integrator->set_ao_factor((fast_gi_method == FAST_GI_METHOD_REPLACE) ? b_world->aoenergy :
1941 integrator->set_ao_additive_factor(
1942 (fast_gi_method == FAST_GI_METHOD_ADD) ? b_world->aoenergy : 0.0f);
1945 integrator->set_ao_factor(0.0f);
1946 integrator->set_ao_additive_factor(0.0f);
1949 integrator->set_ao_distance(b_world->aodist);
1952 integrator->set_ao_factor(0.0f);
1953 integrator->set_ao_additive_factor(0.0f);
1954 integrator->set_ao_distance(10.0f);
1959 if (background->get_transparent()) {
1960 background->set_transparent_glass(get_boolean(cscene,
"film_transparent_glass"));
1961 background->set_transparent_roughness_threshold(
1962 get_float(cscene,
"film_transparent_roughness"));
1965 background->set_transparent_glass(
false);
1966 background->set_transparent_roughness_threshold(0.0f);
1969 background->set_use_shader(view_layer.use_background_shader ||
1970 viewport_parameters.use_custom_shader());
1972 background->set_lightgroup(
1973 ustring((b_world && b_world->lightgroup) ? b_world->lightgroup->name :
""));
1975 background->tag_update(scene);
1980void BlenderSync::sync_lights(blender::Depsgraph &b_depsgraph,
bool update_all,
bool update_time)
1982 shader_map.set_default(scene->default_light);
1984 blender::DEGIDIterData
data{};
1985 data.graph = &b_depsgraph;
1997 blender::Light &b_light = blender::id_cast<blender::Light &>(*b_id);
2001 if (shader_map.add_or_update(&shader, &b_light.id) || update_all ||
2002 scene_attr_needs_recalc(shader, b_depsgraph) ||
2005 unique_ptr<ShaderGraph> graph = make_unique<ShaderGraph>();
2008 if (b_light.nodetree) {
2012 scene, *b_engine, *b_data, *b_scene, b_depsgraph, graph.get(), *b_light.nodetree);
2015 EmissionNode *emission = graph->create_node<EmissionNode>();
2017 emission->set_strength(1.0f);
2019 ShaderNode *
out = graph->output();
2020 graph->connect(emission->
output(
"Emission"),
out->input(
"Surface"));
2023 resolve_view_layer_attributes(shader, graph.get(), b_depsgraph);
2032void BlenderSync::sync_shaders(blender::Depsgraph &b_depsgraph,
2038 shader_map.pre_sync();
2040 sync_world(b_depsgraph, b_screen, b_v3d, update_all, update_time);
2041 sync_lights(b_depsgraph, update_all, update_time);
2042 sync_materials(b_depsgraph, update_all, update_time);
#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance)
#define SHD_SHEEN_ASHIKHMIN
#define SHD_SHEEN_MICROFIBER
static void store_shader_node_errors(blender::Depsgraph &b_depsgraph, const blender::Span< blender::nodes::InlineShaderNodeTreeParams::ErrorMessage > errors)
int blender_attribute_name_split_type(ustring name, string *r_real_name)
static const string_view view_layer_attr_prefix("\x01layer:")
static ustring get_node_input_string(const blender::bNode &b_node, const string &name)
static int validate_enum_value(const int value, const int num_values, const int default_value)
static ShaderInput * node_find_input_by_name(const blender::bNode &b_node, ShaderNode *node, blender::bNodeSocket &b_socket)
static void get_tex_mapping(TextureNode *mapping, const blender::TexMapping *b_mapping)
static void add_nodes_inlined(Scene *scene, blender::RenderEngine &b_engine, blender::Main &b_data, blender::Scene &b_scene, blender::Depsgraph &b_depsgraph, ShaderGraph *graph, blender::bNodeTree &b_ntree, const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map)
static bool node_use_modified_socket_name(ShaderNode *node)
static void raycast_add_output_attribute_sockets(RaycastNode *raycast, const blender::bNode &b_node)
static float3 get_node_output_rgba(blender::bNode &b_node, const string &name)
static VolumeInterpolation get_volume_interpolation(blender::PointerRNA &ptr)
static VolumeSampling get_volume_sampling(blender::PointerRNA &ptr)
static ShaderNode * add_node(Scene *scene, blender::RenderEngine &b_engine, blender::Main &b_data, blender::Scene &b_scene, ShaderGraph *graph, blender::bNodeTree &b_ntree, blender::bNode &b_node)
static EmissionSampling get_emission_sampling(blender::PointerRNA &ptr)
static float get_node_output_value(blender::bNode &b_node, const string &name)
static bool is_image_animated(blender::eImageSource b_image_source, blender::ImageUser &b_image_user)
static ImageAlphaType get_image_alpha_type(blender::Image &b_image)
static const string_view instancer_attr_prefix("\x01instancer:")
map< string, ConvertNode * > ProxyMap
static float3 get_node_output_vector(blender::bNode &b_node, const string &name)
static std::optional< RaycastNode::AttributeOutputType > raycast_get_attribute_output_type(const blender::eCustomDataType data_type)
static void set_default_value(ShaderInput *input, blender::bNodeSocket &b_sock, blender::Main &b_data, blender::ID &b_id)
static ShaderOutput * node_find_output_by_name(blender::bNode &b_node, ShaderNode *node, blender::bNodeSocket &b_socket)
static ustring blender_attribute_name_add_type(const string &name, int type)
static void add_nodes(Scene *scene, blender::RenderEngine &b_engine, blender::Main &b_data, blender::Scene &b_scene, blender::Depsgraph &b_depsgraph, ShaderGraph *graph, blender::bNodeTree &b_ntree, const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map)
static SocketType::Type convert_socket_type(const blender::bNodeSocket &b_socket)
unordered_multimap< void *, ShaderInput * > PtrInputMap
static DisplacementMethod get_displacement_method(blender::Material &b_mat)
static ExtensionType get_image_extension(NodeType &b_node)
static const string_view object_attr_prefix("\x01object:")
static InterpolationType get_image_interpolation(NodeType &b_node)
map< void *, ShaderOutput * > PtrOutputMap
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
ImageParams image_params() const
@ ATTR_OUTPUT_FLOAT_ALPHA
unique_ptr< ShaderManager > shader_manager
unique_ptr< ImageManager > image_manager
unique_ptr_vector< ShaderNode > nodes
T * create_node(Args &&...args)
void disconnect(ShaderOutput *from)
void connect(ShaderOutput *from, ShaderInput *to)
const SocketType & socket_type
SocketType::Type type() const
ShaderInput * input(const char *name)
unique_ptr_vector< ShaderInput > inputs
ShaderOutput * output(const char *name)
unique_ptr_vector< ShaderOutput > outputs
void set_graph(unique_ptr< ShaderGraph > &&graph)
void tag_update(Scene *scene)
NODE_DECLARE unique_ptr< ShaderGraph > graph
void tag_used(Scene *scene)
void push(TaskRunFunction &&task)
void wait_work(Summary *stats=nullptr)
void push_back_slow(const T &t)
void append(const T &value)
#define CCL_NAMESPACE_END
#define storage(slot, qualifiers)
#define image(slot, qualifiers, format)
VecBase< float, D > normalize(VecOp< float, D >) RET
VecBase< float, 4 > float4
VecBase< float, 3 > float3
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
@ CLOSURE_VOLUME_RAYLEIGH_ID
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID
@ CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_BSDF_DIFFUSE_TOON_ID
@ CLOSURE_VOLUME_DRAINE_ID
@ CLOSURE_BSDF_MICROFACET_GGX_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID
@ CLOSURE_BSDF_HAIR_TRANSMISSION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
@ CLOSURE_VOLUME_FOURNIER_FORAND_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
@ CLOSURE_BSDF_PHYSICAL_CONDUCTOR
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID
@ CLOSURE_BSDF_F82_CONDUCTOR
@ CLOSURE_BSSRDF_RANDOM_WALK_LEGACY_ID
@ CLOSURE_BSDF_GLOSSY_TOON_ID
@ CLOSURE_BSDF_HAIR_REFLECTION_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_SKIN_ID
@ CLOSURE_BSDF_ASHIKHMIN_VELVET_ID
NodeEnvironmentProjection
@ NODE_PRINCIPLED_HAIR_MODEL_NUM
@ NODE_PRINCIPLED_HAIR_HUANG
NodeVoronoiDistanceMetric
NodePrincipledHairParametrization
@ NODE_PRINCIPLED_HAIR_REFLECTANCE
@ NODE_PRINCIPLED_HAIR_PARAMETRIZATION_NUM
NodeVectorTransformConvertSpace
uint32_t PathRayVisibility
@ PATH_RAY_VISIBILITY_VOLUME_SCATTER
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_TRANSMIT
@ PATH_RAY_VISIBILITY_DIFFUSE
@ PATH_RAY_VISIBILITY_NONE
@ PATH_RAY_VISIBILITY_GLOSSY
ccl_device_inline float3 one_float3()
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
bNodeTree * node_tree_add_tree(Main *bmain, StringRef name, StringRef idname)
bool inline_shader_node_tree(const bNodeTree &src_tree, bNodeTree &dst_tree, InlineShaderNodeTreeParams ¶ms)
@ SHD_PHASE_HENYEY_GREENSTEIN
@ SHD_PHASE_FOURNIER_FORAND
void DEG_iterator_ids_end(BLI_Iterator *iter)
PointerRNA RNA_id_pointer_create(ID *id)
@ SHD_ATTRIBUTE_INSTANCER
@ SHD_ATTRIBUTE_VIEW_LAYER
@ MA_BL_TRANSPARENT_SHADOW
const char * BKE_id_name(const ID &id)
bool BKE_view_layer_find_rgba_attribute(const Scene *scene, const ViewLayer *layer, const char *name, float r_value[4])
BMesh const char void * data
void DEG_iterator_ids_next(BLI_Iterator *iter)
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
@ SHD_SUBSURFACE_RANDOM_WALK_SKIN
@ SHD_SUBSURFACE_RANDOM_WALK
@ SHD_SUBSURFACE_RANDOM_WALK_LEGACY
void DEG_iterator_ids_begin(BLI_Iterator *iter, DEGIDIterData *data)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
@ SHD_GLOSSY_ASHIKHMIN_SHIRLEY
@ COLBAND_INTERP_CONSTANT
@ CUMA_EXTEND_EXTRAPOLATE
void visibility(Visibility &srt, const ViewCulling &culling, const uint3 global_id, const uint3 local_id, const uint3 workgroup_id)
closure color scatter(string phase, float Anisotropy, float IOR, float Backscatter, float Alpha, float Diameter)
@ VOLUME_NUM_INTERPOLATION
@ VOLUME_INTERPOLATION_LINEAR
@ VOLUME_SAMPLING_DISTANCE
@ SHADER_SPECIAL_TYPE_OSL
closure color sheen(normal N, float roughness)
bool string_startswith(const string_view s, const string_view start)
void string_replace(string &haystack, const string &needle, const string &other)
bool string_endswith(const string_view s, const string_view end)
void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
static bool is_float3(Type type)
ListBaseT< ViewLayerAOV > aovs
bool allow_preserving_repeat_zones
Vector< ErrorMessage > r_error_messages
NodeShaderOutputTarget target_engine_
@ INTERPOLATION_NUM_TYPES