diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-03-16 09:37:30 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-03-16 09:43:17 +0300 |
commit | d49e7b82da67885aac5933e094ee217ff777ac03 (patch) | |
tree | 6ef994837bc165e76bd17aacb1f5296033f31c09 /source/blender/editors/space_node | |
parent | 269536d47ec5684a1c6018353120559be0ba2961 (diff) |
Compositor: Redesign Cryptomatte node for better usability
In the current implementation, cryptomatte passes are connected to the node
and elements are picked by using the eyedropper tool on a special pick channel.
This design has two disadvantages - both connecting all passes individually
and always having to switch to the picker channel are tedious.
With the new design, the user selects the RenderLayer or Image from which the
Cryptomatte layers are directly loaded (the type of pass is determined by an
enum). This allows the node to automatically detect all relevant passes.
Then, when using the eyedropper tool, the operator looks up the selected
coordinates from the picked Image, Node backdrop or Clip and reads the picked
object directly from the Renderlayer/Image, therefore allowing to pick in any
context (e.g. by clicking on the Combined pass in the Image Viewer). The
sampled color is looked up in the metadata and the actual name is stored
in the cryptomatte node. This also allows to remove a hash by just removing
the name from the matte id.
Technically there is some loss of flexibility because the Cryptomatte pass
inputs can no longer be connected to other nodes, but since any compositing
done on them is likely to break the Cryptomatte system anyways, this isn't
really a concern in practise.
In the future, this would also allow to automatically translate values to names
by looking up the value in the associated metadata of the input, or to get a
better visualization of overlapping areas in the Pick output since we could
blend colors now that the output doesn't have to contain the exact value.
Idea + Original patch: Lucas Stockner
Reviewed By: Brecht van Lommel
Differential Revision: https://developer.blender.org/D3959
Diffstat (limited to 'source/blender/editors/space_node')
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 81 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 26 |
3 files changed, 95 insertions, 22 deletions
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 75ea5b9a1bf..0f2b2b435bc 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -643,7 +643,8 @@ static void node_buts_image_user(uiLayout *layout, PointerRNA *ptr, PointerRNA *imaptr, PointerRNA *iuserptr, - bool compositor) + const bool show_layer_selection, + const bool show_color_management) { if (!imaptr->data) { return; @@ -677,20 +678,22 @@ static void node_buts_image_user(uiLayout *layout, uiItemR(col, ptr, "use_auto_refresh", DEFAULT_FLAGS, NULL, ICON_NONE); } - if (compositor && RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER && + if (show_layer_selection && RNA_enum_get(imaptr, "type") == IMA_TYPE_MULTILAYER && RNA_boolean_get(ptr, "has_layers")) { col = uiLayoutColumn(layout, false); uiItemR(col, ptr, "layer", DEFAULT_FLAGS, NULL, ICON_NONE); } - uiLayout *split = uiLayoutSplit(layout, 0.5f, true); - PointerRNA colorspace_settings_ptr = RNA_pointer_get(imaptr, "colorspace_settings"); - uiItemL(split, IFACE_("Color Space"), ICON_NONE); - uiItemR(split, &colorspace_settings_ptr, "name", DEFAULT_FLAGS, "", ICON_NONE); + if (show_color_management) { + uiLayout *split = uiLayoutSplit(layout, 0.5f, true); + PointerRNA colorspace_settings_ptr = RNA_pointer_get(imaptr, "colorspace_settings"); + uiItemL(split, IFACE_("Color Space"), ICON_NONE); + uiItemR(split, &colorspace_settings_ptr, "name", DEFAULT_FLAGS, "", ICON_NONE); - /* Avoid losing changes image is painted. */ - if (BKE_image_is_dirty(imaptr->data)) { - uiLayoutSetEnabled(split, false); + /* Avoid losing changes image is painted. */ + if (BKE_image_is_dirty(imaptr->data)) { + uiLayoutSetEnabled(split, false); + } } } @@ -756,7 +759,7 @@ static void node_shader_buts_tex_image(uiLayout *layout, bContext *C, PointerRNA /* note: image user properties used directly here, unlike compositor image node, * which redefines them in the node struct RNA to get proper updates. */ - node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); + node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false, true); } static void node_shader_buts_tex_image_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -785,7 +788,7 @@ static void node_shader_buts_tex_environment(uiLayout *layout, bContext *C, Poin uiItemR(layout, ptr, "interpolation", DEFAULT_FLAGS, "", ICON_NONE); uiItemR(layout, ptr, "projection", DEFAULT_FLAGS, "", ICON_NONE); - node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false); + node_buts_image_user(layout, C, &iuserptr, &imaptr, &iuserptr, false, true); } static void node_shader_buts_tex_environment_ex(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -1374,7 +1377,7 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA * PointerRNA imaptr = RNA_pointer_get(ptr, "image"); - node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true); + node_buts_image_user(layout, C, ptr, &imaptr, &iuserptr, true, true); node_buts_image_views(layout, C, ptr, &imaptr); } @@ -2665,27 +2668,64 @@ static void node_composit_buts_sunbeams(uiLayout *layout, bContext *UNUSED(C), P uiItemR(layout, ptr, "ray_length", DEFAULT_FLAGS | UI_ITEM_R_SLIDER, NULL, ICON_NONE); } -static void node_composit_buts_cryptomatte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +static void node_composit_buts_cryptomatte_legacy(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) { uiLayout *col = uiLayoutColumn(layout, true); uiItemL(col, IFACE_("Matte Objects:"), ICON_NONE); uiLayout *row = uiLayoutRow(col, true); - uiTemplateCryptoPicker(row, ptr, "add"); - uiTemplateCryptoPicker(row, ptr, "remove"); + uiTemplateCryptoPicker(row, ptr, "add", ICON_ADD); + uiTemplateCryptoPicker(row, ptr, "remove", ICON_REMOVE); uiItemR(col, ptr, "matte_id", DEFAULT_FLAGS, "", ICON_NONE); } -static void node_composit_buts_cryptomatte_ex(uiLayout *layout, - bContext *UNUSED(C), - PointerRNA *UNUSED(ptr)) +static void node_composit_buts_cryptomatte_legacy_ex(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *UNUSED(ptr)) { uiItemO(layout, IFACE_("Add Crypto Layer"), ICON_ADD, "NODE_OT_cryptomatte_layer_add"); uiItemO(layout, IFACE_("Remove Crypto Layer"), ICON_REMOVE, "NODE_OT_cryptomatte_layer_remove"); } +static void node_composit_buts_cryptomatte(uiLayout *layout, bContext *C, PointerRNA *ptr) +{ + bNode *node = ptr->data; + + uiLayout *row = uiLayoutRow(layout, true); + uiItemR(row, ptr, "source", DEFAULT_FLAGS | UI_ITEM_R_EXPAND, NULL, ICON_NONE); + + uiLayout *col = uiLayoutColumn(layout, false); + if (node->custom1 == CMP_CRYPTOMATTE_SRC_RENDER) { + uiTemplateID(col, C, ptr, "scene", NULL, NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL, false, NULL); + } + else { + uiTemplateID( + col, C, ptr, "image", NULL, "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false, NULL); + + NodeCryptomatte *crypto = (NodeCryptomatte *)node->storage; + PointerRNA imaptr = RNA_pointer_get(ptr, "image"); + PointerRNA iuserptr; + RNA_pointer_create((ID *)ptr->owner_id, &RNA_ImageUser, &crypto->iuser, &iuserptr); + uiLayoutSetContextPointer(layout, "image_user", &iuserptr); + + node_buts_image_user(col, C, ptr, &imaptr, &iuserptr, false, false); + node_buts_image_views(col, C, ptr, &imaptr); + } + + col = uiLayoutColumn(layout, true); + uiItemR(col, ptr, "layer_name", 0, "", ICON_NONE); + uiItemL(col, IFACE_("Matte ID:"), ICON_NONE); + + row = uiLayoutRow(col, true); + uiItemR(row, ptr, "matte_id", DEFAULT_FLAGS, "", ICON_NONE); + uiTemplateCryptoPicker(row, ptr, "add", ICON_ADD); + uiTemplateCryptoPicker(row, ptr, "remove", ICON_REMOVE); +} + static void node_composit_buts_brightcontrast(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) @@ -2938,7 +2978,10 @@ static void node_composit_set_butfunc(bNodeType *ntype) break; case CMP_NODE_CRYPTOMATTE: ntype->draw_buttons = node_composit_buts_cryptomatte; - ntype->draw_buttons_ex = node_composit_buts_cryptomatte_ex; + break; + case CMP_NODE_CRYPTOMATTE_LEGACY: + ntype->draw_buttons = node_composit_buts_cryptomatte_legacy; + ntype->draw_buttons_ex = node_composit_buts_cryptomatte_legacy_ex; break; case CMP_NODE_BRIGHTCONTRAST: ntype->draw_buttons = node_composit_buts_brightcontrast; diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index afdc9efb78b..b72a6503749 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -1404,8 +1404,12 @@ static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op)) } LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) { - if (node->type == CMP_NODE_R_LAYERS) { + if ((node->type == CMP_NODE_R_LAYERS) || + (node->type == CMP_NODE_CRYPTOMATTE && node->custom1 == CMP_CRYPTOMATTE_SRC_RENDER)) { ID *id = node->id; + if (id == NULL) { + continue; + } if (id->tag & LIB_TAG_DOIT) { RE_ReadRenderResult(curscene, (Scene *)id); ntreeCompositTagRender((Scene *)id); @@ -2742,7 +2746,7 @@ static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator *UNUSED(op)) node = nodeGetActive(snode->edittree); } - if (!node || node->type != CMP_NODE_CRYPTOMATTE) { + if (!node || node->type != CMP_NODE_CRYPTOMATTE_LEGACY) { return OPERATOR_CANCELLED; } @@ -2786,7 +2790,7 @@ static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator *UNUSED(o node = nodeGetActive(snode->edittree); } - if (!node || node->type != CMP_NODE_CRYPTOMATTE) { + if (!node || node->type != CMP_NODE_CRYPTOMATTE_LEGACY) { return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 8f1dc3c8c3e..8ecab92aa26 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -443,6 +443,32 @@ static void sample_draw(const bContext *C, ARegion *region, void *arg_info) } } +/* Returns mouse position in image space. */ +bool ED_space_node_get_position( + Main *bmain, SpaceNode *snode, struct ARegion *ar, const int mval[2], float fpos[2]) +{ + if (!ED_node_is_compositor(snode) || (snode->flag & SNODE_BACKDRAW) == 0) { + return false; + } + + void *lock; + Image *ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_COMPOSITE, "Viewer Node"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (!ibuf) { + BKE_image_release_ibuf(ima, ibuf, lock); + return false; + } + + /* map the mouse coords to the backdrop image space */ + float bufx = ibuf->x * snode->zoom; + float bufy = ibuf->y * snode->zoom; + fpos[0] = (bufx > 0.0f ? ((float)mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + fpos[1] = (bufy > 0.0f ? ((float)mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + + BKE_image_release_ibuf(ima, ibuf, lock); + return true; +} + /* Returns color in linear space, matching ED_space_image_color_sample(). * And here we've got recursion in the comments tips... */ |