Fix T38340 and T38473: fixed Scene pointers in Composite and Defocus nodes don't get updated based on context.

As discussed in T38340 the solution is to use the current scene from
context whenever feasible.

Composite does not use node->id at all now, the scene which owns the
compositing node tree is retrieved from context instead.

Defocus node->id is made editable by the user. By default it is not set,
which also will make it use the contextual scene and camera info.
The node->id pointer in Defocus is **not** cleared in older blend files.
This is done for backward compatibility: the node will then behave as
before in untouched scenes.

File Output nodes also don't store scene in node->id. This is only needed
when creating a new node for initializing the file format.

Reviewers: brecht, jbakker, mdewanchand

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D290
This commit is contained in:
Lukas Tönne 2014-02-05 13:51:51 +01:00
parent e9fda259da
commit 1687023776
Notes: blender-bot 2023-09-13 08:48:34 +02:00
Referenced by issue #43180, Values in depth channel saved incorrectly on .blend file re-open
Referenced by issue #38340, When used inside a node group in multiple scenes, the defocus node does not refresh active camera data.
21 changed files with 65 additions and 67 deletions

View File

@ -931,7 +931,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMateria
/* API */
struct CompBuf;
void ntreeCompositExecTree(struct bNodeTree *ntree, struct RenderData *rd, int rendering, int do_previews,
void ntreeCompositExecTree(struct Scene *scene, struct bNodeTree *ntree, struct RenderData *rd, int rendering, int do_previews,
const struct ColorManagedViewSettings *view_settings, const struct ColorManagedDisplaySettings *display_settings);
void ntreeCompositTagRender(struct Scene *sce);
int ntreeCompositTagAnimated(struct bNodeTree *ntree);
@ -999,6 +999,4 @@ int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target,
void init_nodesystem(void);
void free_nodesystem(void);
void clear_scene_in_nodes(struct Main *bmain, struct Scene *sce);
#endif

View File

@ -3658,31 +3658,6 @@ void free_nodesystem(void)
}
}
/* called from BKE_scene_unlink, when deleting a scene goes over all scenes
* other than the input, checks if they have render layer nodes referencing
* the to-be-deleted scene, and resets them to NULL. */
/* XXX needs to get current scene then! */
void clear_scene_in_nodes(Main *bmain, Scene *sce)
{
Scene *sce1;
bNode *node;
for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next) {
if (sce1 != sce) {
if (sce1->nodetree) {
for (node = sce1->nodetree->nodes.first; node; node = node->next) {
if (node->type == CMP_NODE_R_LAYERS) {
Scene *nodesce = (Scene *)node->id;
if (nodesce == sce) node->id = NULL;
}
}
}
}
}
}
/* -------------------------------------------------------------------- */
/* NodeTree Iterator Helpers (FOREACH_NODETREE) */

View File

@ -727,8 +727,17 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce)
if (sce1->set == sce)
sce1->set = NULL;
/* check render layer nodes in other scenes */
clear_scene_in_nodes(bmain, sce);
for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next) {
bNode *node;
if (sce1 == sce || !sce1->nodetree)
continue;
for (node = sce1->nodetree->nodes.first; node; node = node->next) {
if (node->id == &sce->id)
node->id = NULL;
}
}
/* al screens */
for (sc = bmain->screen.first; sc; sc = sc->id.next)

View File

@ -5061,7 +5061,7 @@ static void composite_patch(bNodeTree *ntree, Scene *scene)
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->id==NULL && ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE))
if (node->id==NULL && node->type == CMP_NODE_R_LAYERS)
node->id = &scene->id;
}
}

View File

@ -2686,4 +2686,18 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
{
/* nodes don't use fixed node->id any more, clean up */
FOREACH_NODETREE(main, ntree, id) {
if (ntree->type == NTREE_COMPOSIT) {
bNode *node;
for (node = ntree->nodes.first; node; node = node->next) {
if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
node->id = NULL;
}
}
}
} FOREACH_NODETREE_END
}
}

View File

@ -315,7 +315,7 @@ extern "C" {
* should be checked further, probably it'll be also needed for preview
* generation in display space
*/
void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rendering,
const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings);
/**

View File

@ -26,6 +26,7 @@
CompositorContext::CompositorContext()
{
this->m_scene = NULL;
this->m_rd = NULL;
this->m_quality = COM_QUALITY_HIGH;
this->m_hasActiveOpenCLDevices = false;

View File

@ -51,6 +51,8 @@ private:
*/
CompositorQuality m_quality;
Scene *m_scene;
/**
* @brief Reference to the render data that is being composited.
* This field is initialized in ExecutionSystem and must only be read from that point on.
@ -120,6 +122,9 @@ public:
* @brief get the scene of the context
*/
const RenderData *getRenderData() const { return this->m_rd; }
void setScene(Scene *scene) { m_scene = scene; }
Scene *getScene() const { return m_scene; }
/**
* @brief set the preview image hash table

View File

@ -46,9 +46,10 @@ extern "C" {
#include "MEM_guardedalloc.h"
#endif
ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation,
ExecutionSystem::ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editingtree, bool rendering, bool fastcalculation,
const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings)
{
this->m_context.setScene(scene);
this->m_context.setbNodeTree(editingtree);
this->m_context.setPreviewHash(editingtree->previews);
this->m_context.setFastCalculation(fastcalculation);

View File

@ -167,7 +167,7 @@ public:
* @param editingtree [bNodeTree *]
* @param rendering [true false]
*/
ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation,
ExecutionSystem(RenderData *rd, Scene *scene, bNodeTree *editingtree, bool rendering, bool fastcalculation,
const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings);
/**

View File

@ -43,7 +43,7 @@ static void intern_freeCompositorCaches()
deintializeDistortionCache();
}
void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rendering,
const ColorManagedViewSettings *viewSettings,
const ColorManagedDisplaySettings *displaySettings)
{
@ -81,7 +81,7 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
bool twopass = (editingtree->flag & NTREE_TWO_PASS) > 0 && !rendering;
/* initialize execution system */
if (twopass) {
ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass, viewSettings, displaySettings);
ExecutionSystem *system = new ExecutionSystem(rd, scene, editingtree, rendering, twopass, viewSettings, displaySettings);
system->execute();
delete system;
@ -93,7 +93,7 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering,
}
}
ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false,
ExecutionSystem *system = new ExecutionSystem(rd, scene, editingtree, rendering, false,
viewSettings, displaySettings);
system->execute();
delete system;

View File

@ -40,7 +40,7 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte
InputSocket *depthSocket = this->getInputSocket(2);
CompositorOperation *compositorOperation = new CompositorOperation();
compositorOperation->setSceneName(editorNode->id->name);
compositorOperation->setSceneName(context->getScene()->id.name);
compositorOperation->setRenderData(context->getRenderData());
compositorOperation->setbNodeTree(context->getbNodeTree());
compositorOperation->setIgnoreAlpha(editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA);

View File

@ -42,9 +42,9 @@ DefocusNode::DefocusNode(bNode *editorNode) : Node(editorNode)
void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
bNode *node = this->getbNode();
Scene *scene = (Scene *)node->id;
Object *camob = (scene) ? scene->camera : NULL;
NodeDefocus *data = (NodeDefocus *)node->storage;
Scene *scene = node->id ? (Scene *)node->id : context->getScene();
Object *camob = scene ? scene->camera : NULL;
NodeOperation *radiusOperation;
if (data->no_zbuf) {

View File

@ -1242,7 +1242,7 @@ static void node_composit_buts_bilateralblur(uiLayout *layout, bContext *UNUSED(
uiItemR(col, ptr, "sigma_space", 0, NULL, ICON_NONE);
}
static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_composit_buts_defocus(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
uiLayout *sub, *col;
@ -1262,7 +1262,9 @@ static void node_composit_buts_defocus(uiLayout *layout, bContext *UNUSED(C), Po
col = uiLayoutColumn(layout, FALSE);
uiItemR(col, ptr, "use_preview", 0, NULL, ICON_NONE);
uiTemplateID(layout, C, ptr, "scene", NULL, NULL, NULL);
col = uiLayoutColumn(layout, FALSE);
uiItemR(col, ptr, "use_zbuffer", 0, NULL, ICON_NONE);
sub = uiLayoutColumn(col, FALSE);

View File

@ -259,7 +259,7 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog
// XXX BIF_store_spare();
/* 1 is do_previews */
ntreeCompositExecTree(ntree, &cj->scene->r, FALSE, TRUE, &scene->view_settings, &scene->display_settings);
ntreeCompositExecTree(cj->scene, ntree, &cj->scene->r, FALSE, TRUE, &scene->view_settings, &scene->display_settings);
ntree->test_break = NULL;
ntree->stats_draw = NULL;

View File

@ -4841,7 +4841,7 @@ static void def_cmp_map_uv(StructRNA *srna)
static void def_cmp_defocus(StructRNA *srna)
{
PropertyRNA *prop;
static EnumPropertyItem bokeh_items[] = {
{8, "OCTAGON", 0, "Octagonal", "8 sides"},
{7, "HEPTAGON", 0, "Heptagonal", "7 sides"},
@ -4852,9 +4852,17 @@ static void def_cmp_defocus(StructRNA *srna)
{0, "CIRCLE", 0, "Circular", ""},
{0, NULL, 0, NULL, NULL}
};
prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_pointer_funcs(prop, NULL, "rna_Node_scene_set", NULL, NULL);
RNA_def_property_struct_type(prop, "Scene");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Scene", "Scene from which to select the active camera (render scene if undefined)");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_struct_sdna_from(srna, "NodeDefocus", "storage");
prop = RNA_def_property(srna, "bokeh", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "bktype");
RNA_def_property_enum_items(prop, bokeh_items);

View File

@ -257,12 +257,12 @@ void register_node_tree_type_cmp(void)
void *COM_linker_hack = NULL;
void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int rendering, int do_preview,
void ntreeCompositExecTree(Scene *scene, bNodeTree *ntree, RenderData *rd, int rendering, int do_preview,
const ColorManagedViewSettings *view_settings,
const ColorManagedDisplaySettings *display_settings)
{
#ifdef WITH_COMPOSITOR
COM_execute(rd, ntree, rendering, view_settings, display_settings);
COM_execute(rd, scene, ntree, rendering, view_settings, display_settings);
#else
(void)ntree, (void)rd, (void)rendering, (void)do_preview;
(void)view_settings, (void)display_settings;

View File

@ -43,21 +43,12 @@ static bNodeSocketTemplate cmp_node_composite_in[] = {
{ -1, 0, "" }
};
static void init(const bContext *C, PointerRNA *ptr)
{
Scene *scene = CTX_data_scene(C);
bNode *node = ptr->data;
node->id = &scene->id;
}
void register_node_type_cmp_composite(void)
{
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_COMPOSITE, "Composite", NODE_CLASS_OUTPUT, NODE_PREVIEW);
node_type_socket_templates(&ntype, cmp_node_composite_in, NULL);
ntype.initfunc_api = init;
/* Do not allow muting for this node. */
node_type_internal_links(&ntype, NULL);

View File

@ -48,10 +48,8 @@ static bNodeSocketTemplate cmp_node_defocus_out[] = {
{ -1, 0, "" }
};
static void node_composit_init_defocus(const bContext *C, PointerRNA *ptr)
static void node_composit_init_defocus(bNodeTree *UNUSED(ntree), bNode *node)
{
Scene *scene = CTX_data_scene(C);
bNode *node = ptr->data;
/* qdn: defocus node */
NodeDefocus *nbd = MEM_callocN(sizeof(NodeDefocus), "node defocus data");
nbd->bktype = 0;
@ -65,8 +63,6 @@ static void node_composit_init_defocus(const bContext *C, PointerRNA *ptr)
nbd->scale = 1.f;
nbd->no_zbuf = 1;
node->storage = nbd;
node->id = &scene->id;
}
void register_node_type_cmp_defocus(void)
@ -75,7 +71,7 @@ void register_node_type_cmp_defocus(void)
cmp_node_type_base(&ntype, CMP_NODE_DEFOCUS, "Defocus", NODE_CLASS_OP_FILTER, 0);
node_type_socket_templates(&ntype, cmp_node_defocus_in, cmp_node_defocus_out);
ntype.initfunc_api = node_composit_init_defocus;
node_type_init(&ntype, node_composit_init_defocus);
node_type_storage(&ntype, "NodeDefocus", node_free_standard_storage, node_copy_standard_storage);
nodeRegisterType(&ntype);

View File

@ -179,8 +179,6 @@ static void init_output_file(const bContext *C, PointerRNA *ptr)
ImageFormatData *format = NULL;
node->storage = nimf;
node->id = &scene->id;
if (scene) {
RenderData *rd = &scene->r;

View File

@ -1940,7 +1940,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
ntreeCompositTagRender(re->scene);
ntreeCompositTagAnimated(ntree);
ntreeCompositExecTree(ntree, &re->r, TRUE, G.background == 0, &re->scene->view_settings, &re->scene->display_settings);
ntreeCompositExecTree(re->scene, ntree, &re->r, TRUE, G.background == 0, &re->scene->view_settings, &re->scene->display_settings);
}
/* ensure we get either composited result or the active layer */
@ -2136,7 +2136,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
if (re->r.scemode & R_FULL_SAMPLE)
do_merge_fullsample(re, ntree);
else {
ntreeCompositExecTree(ntree, &re->r, TRUE, G.background == 0, &re->scene->view_settings, &re->scene->display_settings);
ntreeCompositExecTree(re->scene, ntree, &re->r, TRUE, G.background == 0, &re->scene->view_settings, &re->scene->display_settings);
}
ntree->stats_draw = NULL;