Compositor: Turn Denoise node options into inputs
This patch turns the options of the Denoise node into inputs. Reference #137223. Pull Request: https://projects.blender.org/blender/blender/pulls/137669
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 34
|
||||
#define BLENDER_FILE_SUBVERSION 35
|
||||
|
||||
/* 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
|
||||
|
||||
@@ -794,6 +794,11 @@ static void write_compositor_legacy_properties(bNodeTree &node_tree)
|
||||
write_input_to_property_float("Color Threshold", node->custom3);
|
||||
write_input_to_property_float("Neighbor Threshold", node->custom4);
|
||||
}
|
||||
|
||||
if (node->type_legacy == CMP_NODE_DENOISE) {
|
||||
NodeDenoise *storage = static_cast<NodeDenoise *>(node->storage);
|
||||
write_input_to_property_bool_char("HDR", storage->hdr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2574,6 +2574,51 @@ static void do_version_despeckle_node_options_to_inputs_animation(bNodeTree *nod
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_denoise_node_options_to_inputs(bNodeTree *node_tree, bNode *node)
|
||||
{
|
||||
NodeDenoise *storage = static_cast<NodeDenoise *>(node->storage);
|
||||
if (!storage) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!blender::bke::node_find_socket(*node, SOCK_IN, "HDR")) {
|
||||
bNodeSocket *input = blender::bke::node_add_static_socket(
|
||||
*node_tree, *node, SOCK_IN, SOCK_BOOLEAN, PROP_NONE, "HDR", "HDR");
|
||||
input->default_value_typed<bNodeSocketValueBoolean>()->value = storage->hdr;
|
||||
}
|
||||
}
|
||||
|
||||
/* The options were converted into inputs. */
|
||||
static void do_version_denoise_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_hdr")) {
|
||||
fcurve->rna_path = BLI_sprintfN("%s.%s", node_rna_path.c_str(), "inputs[3].default_value");
|
||||
}
|
||||
|
||||
/* The RNA path was changed, free the old path. */
|
||||
if (fcurve->rna_path != old_rna_path) {
|
||||
MEM_freeN(old_rna_path);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static void do_version_viewer_shortcut(bNodeTree *node_tree)
|
||||
{
|
||||
LISTBASE_FOREACH_MUTABLE (bNode *, node, &node_tree->nodes) {
|
||||
@@ -3184,6 +3229,19 @@ void do_versions_after_linking_400(FileData *fd, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 35)) {
|
||||
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_DENOISE) {
|
||||
do_version_denoise_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.
|
||||
@@ -7912,6 +7970,19 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
|
||||
FOREACH_NODETREE_END;
|
||||
}
|
||||
|
||||
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 405, 35)) {
|
||||
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_DENOISE) {
|
||||
do_version_denoise_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. */
|
||||
|
||||
@@ -1619,7 +1619,7 @@ typedef struct NodeCryptomatte {
|
||||
} NodeCryptomatte;
|
||||
|
||||
typedef struct NodeDenoise {
|
||||
char hdr;
|
||||
char hdr DNA_DEPRECATED;
|
||||
char prefilter;
|
||||
char quality;
|
||||
char _pad[1];
|
||||
|
||||
@@ -3912,6 +3912,9 @@ static const char node_input_eccentricity[] = "Eccentricity";
|
||||
static const char node_input_color_threshold[] = "Color Threshold";
|
||||
static const char node_input_neighbor_threshold[] = "Neighbor Threshold";
|
||||
|
||||
/* Denoise node. */
|
||||
static const char node_input_hdr[] = "HDR";
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* White Balance Node.
|
||||
*/
|
||||
@@ -10017,7 +10020,9 @@ static void def_cmp_denoise(BlenderRNA * /*brna*/, StructRNA *srna)
|
||||
RNA_def_struct_sdna_from(srna, "NodeDenoise", "storage");
|
||||
|
||||
prop = RNA_def_property(srna, "use_hdr", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, nullptr, "hdr", 0);
|
||||
RNA_def_property_boolean_funcs(prop,
|
||||
"rna_node_property_to_input_getter<bool, node_input_hdr>",
|
||||
"rna_node_property_to_input_setter<bool, node_input_hdr>");
|
||||
RNA_def_property_boolean_default(prop, true);
|
||||
RNA_def_property_ui_text(prop, "HDR", "Process HDR images");
|
||||
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
|
||||
|
||||
@@ -53,13 +53,14 @@ static void cmp_node_denoise_declare(NodeDeclarationBuilder &b)
|
||||
.default_value({1.0f, 1.0f, 1.0f, 1.0f})
|
||||
.hide_value()
|
||||
.compositor_domain_priority(1);
|
||||
b.add_input<decl::Bool>("HDR").default_value(true).compositor_expects_single_value();
|
||||
|
||||
b.add_output<decl::Color>("Image");
|
||||
}
|
||||
|
||||
static void node_composit_init_denonise(bNodeTree * /*ntree*/, bNode *node)
|
||||
{
|
||||
NodeDenoise *ndg = MEM_callocN<NodeDenoise>(__func__);
|
||||
ndg->hdr = true;
|
||||
ndg->prefilter = CMP_NODE_DENOISE_PREFILTER_ACCURATE;
|
||||
ndg->quality = CMP_NODE_DENOISE_QUALITY_SCENE;
|
||||
node->storage = ndg;
|
||||
@@ -96,7 +97,6 @@ static void node_composit_buts_denoise(uiLayout *layout, bContext * /*C*/, Point
|
||||
uiItemR(layout, ptr, "prefilter", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
uiItemL(layout, IFACE_("Quality:"), ICON_NONE);
|
||||
uiItemR(layout, ptr, "quality", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
uiItemR(layout, ptr, "use_hdr", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
|
||||
}
|
||||
|
||||
using namespace blender::compositor;
|
||||
@@ -287,7 +287,7 @@ class DenoiseOperation : public NodeOperation {
|
||||
|
||||
bool use_hdr()
|
||||
{
|
||||
return node_storage(bnode()).hdr;
|
||||
return this->get_input("HDR").get_single_value_default(true);
|
||||
}
|
||||
|
||||
CMPNodeDenoisePrefilter get_prefilter_mode()
|
||||
|
||||
Reference in New Issue
Block a user