From fd3ca68b5edb36532b840c31c5d49e43326f48cc Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Fri, 9 May 2025 14:15:14 +0200 Subject: [PATCH] Compositor: Turn Bokeh Blur options to inputs This patch turns the options of the Bokeh Blur node into inputs. Reference #137223. Pull Request: https://projects.blender.org/blender/blender/pulls/138664 --- .../blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenkernel/intern/node.cc | 4 ++ .../blenloader/intern/versioning_450.cc | 66 +++++++++++++++++++ .../blender/makesrna/intern/rna_nodetree.cc | 14 +++- .../nodes/node_composite_bokehblur.cc | 26 ++------ 5 files changed, 88 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index b0d8ee87bdf..f37c5da8bd2 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -27,7 +27,7 @@ /* Blender file format version. */ #define BLENDER_FILE_VERSION BLENDER_VERSION -#define BLENDER_FILE_SUBVERSION 68 +#define BLENDER_FILE_SUBVERSION 69 /* Minimum Blender version that supports reading file written with the current * version. Older Blender versions will test this and cancel loading the file, showing a warning to diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 6e9742206d3..8e588da91e1 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1022,6 +1022,10 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree) if (node->type_legacy == CMP_NODE_ALPHAOVER) { write_input_to_property_bool_short("Straight Alpha", node->custom1); } + + if (node->type_legacy == CMP_NODE_BOKEHBLUR) { + write_input_to_property_bool_int16_flag("Extend Bounds", node->custom1, (1 << 1)); + } } } diff --git a/source/blender/blenloader/intern/versioning_450.cc b/source/blender/blenloader/intern/versioning_450.cc index fc317bd3e27..9fc928a34f6 100644 --- a/source/blender/blenloader/intern/versioning_450.cc +++ b/source/blender/blenloader/intern/versioning_450.cc @@ -3286,6 +3286,46 @@ static void do_version_alpha_over_node_options_to_inputs_animation(bNodeTree *no }); } +/* The options were converted into inputs. */ +static void do_version_bokeh_blur_node_options_to_inputs(bNodeTree *node_tree, bNode *node) +{ + if (!blender::bke::node_find_socket(*node, SOCK_IN, "Extend Bounds")) { + bNodeSocket *input = blender::bke::node_add_static_socket( + *node_tree, *node, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "Extend Bounds", "Extend Bounds"); + input->default_value_typed()->value = bool(node->custom1); + } +} + +/* The options were converted into inputs. */ +static void do_version_bokeh_blur_node_options_to_inputs_animation(bNodeTree *node_tree, + bNode *node) +{ + /* Compute the RNA path of the node. */ + char escaped_node_name[sizeof(node->name) * 2 + 1]; + BLI_str_escape(escaped_node_name, node->name, sizeof(escaped_node_name)); + const std::string node_rna_path = fmt::format("nodes[\"{}\"]", escaped_node_name); + + BKE_fcurves_id_cb(&node_tree->id, [&](ID * /*id*/, FCurve *fcurve) { + /* The FCurve does not belong to the node since its RNA path doesn't start with the node's RNA + * path. */ + if (!blender::StringRef(fcurve->rna_path).startswith(node_rna_path)) { + return; + } + + /* Change the RNA path of the FCurve from the old properties to the new inputs, adjusting the + * values of the FCurves frames when needed. */ + char *old_rna_path = fcurve->rna_path; + if (BLI_str_endswith(fcurve->rna_path, "use_extended_bounds")) { + fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[4].default_value"); + } + + /* The RNA path was changed, free the old path. */ + if (fcurve->rna_path != old_rna_path) { + MEM_freeN(old_rna_path); + } + }); +} + /* Turns all instances of "{" and "}" in a string into "{{" and "}}", escaping * them for strings that are processed with templates so that they don't * erroneously get interepreted as template expressions. */ @@ -3889,6 +3929,19 @@ void do_versions_after_linking_450(FileData * /*fd*/, Main *bmain) FOREACH_NODETREE_END; } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 69)) { + FOREACH_NODETREE_BEGIN (bmain, node_tree, id) { + if (node_tree->type == NTREE_COMPOSIT) { + LISTBASE_FOREACH (bNode *, node, &node_tree->nodes) { + if (node->type_legacy == CMP_NODE_BOKEHBLUR) { + do_version_bokeh_blur_node_options_to_inputs_animation(node_tree, node); + } + } + } + } + FOREACH_NODETREE_END; + } + /** * Always bump subversion in BKE_blender_version.h when adding versioning * code here, and wrap it inside a MAIN_VERSION_FILE_ATLEAST check. @@ -4936,6 +4989,19 @@ void blo_do_versions_450(FileData * /*fd*/, Library * /*lib*/, Main *bmain) } } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 69)) { + FOREACH_NODETREE_BEGIN (bmain, node_tree, id) { + if (node_tree->type == NTREE_COMPOSIT) { + LISTBASE_FOREACH (bNode *, node, &node_tree->nodes) { + if (node->type_legacy == CMP_NODE_BOKEHBLUR) { + do_version_bokeh_blur_node_options_to_inputs(node_tree, node); + } + } + } + } + FOREACH_NODETREE_END; + } + /* Always run this versioning (keep at the bottom of the function). Meshes are written with the * legacy format which always needs to be converted to the new format on file load. To be moved * to a subversion check in 5.0. */ diff --git a/source/blender/makesrna/intern/rna_nodetree.cc b/source/blender/makesrna/intern/rna_nodetree.cc index 663ec245973..566e16c8028 100644 --- a/source/blender/makesrna/intern/rna_nodetree.cc +++ b/source/blender/makesrna/intern/rna_nodetree.cc @@ -4227,6 +4227,9 @@ static const char node_input_translation_direction[] = "Translation Direction"; /* Alpha Over node. */ static const char node_input_straight_alpha[] = "Straight Alpha"; +/* Bokeh Blur node. */ +static const char node_input_extend_bounds[] = "Extend Bounds"; + /* -------------------------------------------------------------------- * White Balance Node. */ @@ -9712,9 +9715,14 @@ static void def_cmp_bokehblur(BlenderRNA * /*brna*/, StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "use_extended_bounds", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, nullptr, "custom1", CMP_NODEFLAG_BLUR_EXTEND_BOUNDS); - RNA_def_property_ui_text( - prop, "Extend Bounds", "Extend bounds of the input image to fully fit blurred image"); + RNA_def_property_boolean_funcs( + prop, + "rna_node_property_to_input_getter", + "rna_node_property_to_input_setter"); + RNA_def_property_ui_text(prop, + "Extend Bounds", + "Extend bounds of the input image to fully fit blurred image. " + "(Deprecated: Use Extend Bounds input instead.)"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "blur_max", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc b/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc index 28fcd606881..0111c1ed297 100644 --- a/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc +++ b/source/blender/nodes/composite/nodes/node_composite_bokehblur.cc @@ -24,28 +24,15 @@ namespace blender::nodes::node_composite_bokehblur_cc { static void cmp_node_bokehblur_declare(NodeDeclarationBuilder &b) { - b.add_input("Image") - .default_value({0.8f, 0.8f, 0.8f, 1.0f}) - .compositor_domain_priority(0); + b.add_input("Image").default_value({0.8f, 0.8f, 0.8f, 1.0f}); b.add_input("Bokeh") .default_value({1.0f, 1.0f, 1.0f, 1.0f}) .compositor_realization_mode(CompositorInputRealizationMode::Transforms); - b.add_input("Size") - .default_value(1.0f) - .min(0.0f) - .max(10.0f) - .compositor_domain_priority(1); - b.add_input("Bounding box") - .default_value(1.0f) - .min(0.0f) - .max(1.0f) - .compositor_domain_priority(2); - b.add_output("Image"); -} + b.add_input("Size").default_value(1.0f).min(0.0f).max(10.0f); + b.add_input("Bounding box").default_value(1.0f).min(0.0f).max(1.0f); + b.add_input("Extend Bounds").default_value(false).compositor_expects_single_value(); -static void node_composit_buts_bokehblur(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) -{ - layout->prop(ptr, "use_extended_bounds", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE); + b.add_output("Image"); } using namespace blender::compositor; @@ -378,7 +365,7 @@ class BokehBlurOperation : public NodeOperation { bool get_extend_bounds() { - return bnode().custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS; + return this->get_input("Extend Bounds").get_single_value_default(false); } }; @@ -403,7 +390,6 @@ void register_node_type_cmp_bokehblur() ntype.enum_name_legacy = "BOKEHBLUR"; ntype.nclass = NODE_CLASS_OP_FILTER; ntype.declare = file_ns::cmp_node_bokehblur_declare; - ntype.draw_buttons = file_ns::node_composit_buts_bokehblur; ntype.get_compositor_operation = file_ns::get_compositor_operation; blender::bke::node_register_type(ntype);