Files
test/source/blender/nodes/NOD_composite.hh
Omar Emara 931c188ce5 Compositor: Refactor File Output node
This patches refactors the compositor File Output mechanism and
implements the file output node for the Realtime Compositor. The
refactor was done for the following reasons:

1. The existing file output mechanism relied on a global EXR image
   resource where the result of each compositor execution for each
   view was accumulated and stored in the global resource, until the
   last view is executed, when the EXR is finally saved. Aside from
   relying on global resources, this can cause effective memory leaks
   since the compositor can be interrupted before the EXR is written and
   closed.
2. We need common code to share between all compositors since we now
   have multiple compositor implementations.
3. We needed to take the opportunity to fix some of the issues with the
   existing implementation, like lossy compression of data passes,
   and inability to save single values passes.

The refactor first introduced a new structure called the Compositor
Render Context. This context stores compositor information related to
the render pipeline and is persistent across all compositor executions
of all views. Its extended lifetime relative to a single compositor
execution lends itself well to store data that is accumulated across
views. The context currently has a map of File Output objects. Those
objects wrap a Render Result structure and can be used to construct
multi-view images which can then be saved after all views are executed
using the existing BKE_image_render_write function.

Minor adjustments were made to the BKE and RE modules to allow saving
using the BKE_image_render_write function. Namely, the function now
allows the use of a source image format for saving as well as the
ability to not save the render result as a render by introducing two new
default arguments. Further, for multi-layer EXR saving, the existent of
a single unnamed render layer will omit the layer name from the EXR
channel full name, and only the pass, view, and channel ID will remain.
Finally, the Render Result to Image Buffer conversion now take he number
of channels into account, instead of always assuming color channels.

The patch implements the File Output node in the Realtime Compositor
using the aforementioned mechanisms, replaces the implementation of the
CPU compositor using the same Realtime Compositor implementation, and
setup the necessary logic in the render pipeline code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113982
2023-12-13 11:08:03 +01:00

103 lines
4.0 KiB
C++

/* SPDX-FileCopyrightText: 2005 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup nodes
*/
#pragma once
#include "BKE_node.h"
namespace blender::realtime_compositor {
class RenderContext;
}
struct bNodeTreeType;
struct CryptomatteSession;
struct Scene;
struct RenderData;
struct Render;
struct ViewLayer;
extern bNodeTreeType *ntreeType_Composite;
void node_cmp_rlayers_outputs(bNodeTree *ntree, bNode *node);
void node_cmp_rlayers_register_pass(bNodeTree *ntree,
bNode *node,
Scene *scene,
ViewLayer *view_layer,
const char *name,
eNodeSocketDatatype type);
const char *node_cmp_rlayers_sock_to_pass(int sock_index);
void register_node_type_cmp_custom_group(bNodeType *ntype);
void ntreeCompositExecTree(Render *render,
Scene *scene,
bNodeTree *ntree,
RenderData *rd,
bool rendering,
int do_previews,
const char *view_name,
blender::realtime_compositor::RenderContext *render_context);
/**
* Called from render pipeline, to tag render input and output.
* need to do all scenes, to prevent errors when you re-render 1 scene.
*/
void ntreeCompositTagRender(Scene *scene);
void ntreeCompositTagNeedExec(bNode *node);
/**
* Update the outputs of the render layer nodes.
* Since the outputs depend on the render engine, this part is a bit complex:
* - #ntreeCompositUpdateRLayers is called and loops over all render layer nodes.
* - Each render layer node calls the update function of the
* render engine that's used for its scene.
* - The render engine calls RE_engine_register_pass for each pass.
* - #RE_engine_register_pass calls #node_cmp_rlayers_register_pass.
*/
void ntreeCompositUpdateRLayers(bNodeTree *ntree);
void ntreeCompositClearTags(bNodeTree *ntree);
bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree,
bNode *node,
const char *name,
const ImageFormatData *im_format);
int ntreeCompositOutputFileRemoveActiveSocket(bNodeTree *ntree, bNode *node);
void ntreeCompositOutputFileSetPath(bNode *node, bNodeSocket *sock, const char *name);
void ntreeCompositOutputFileSetLayer(bNode *node, bNodeSocket *sock, const char *name);
/* needed in do_versions */
void ntreeCompositOutputFileUniquePath(ListBase *list,
bNodeSocket *sock,
const char defname[],
char delim);
void ntreeCompositOutputFileUniqueLayer(ListBase *list,
bNodeSocket *sock,
const char defname[],
char delim);
void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node);
void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
void ntreeCompositCryptomatteSyncFromAdd(const Scene *scene, bNode *node);
void ntreeCompositCryptomatteSyncFromRemove(bNode *node);
bNodeSocket *ntreeCompositCryptomatteAddSocket(bNodeTree *ntree, bNode *node);
int ntreeCompositCryptomatteRemoveSocket(bNodeTree *ntree, bNode *node);
void ntreeCompositCryptomatteLayerPrefix(const Scene *scene,
const bNode *node,
char *r_prefix,
size_t prefix_maxncpy);
/**
* Update the runtime layer names with the crypto-matte layer names of the references render layer
* or image.
*/
void ntreeCompositCryptomatteUpdateLayerNames(const Scene *scene, bNode *node);
CryptomatteSession *ntreeCompositCryptomatteSession(const Scene *scene, bNode *node);