Blender  V2.93
COM_CompositorNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_CompositorNode.h"
21 #include "COM_ExecutionSystem.h"
22 
23 namespace blender::compositor {
24 
25 CompositorNode::CompositorNode(bNode *editorNode) : Node(editorNode)
26 {
27  /* pass */
28 }
29 
31  const CompositorContext &context) const
32 {
33  bNode *editorNode = this->getbNode();
34  bool is_active = (editorNode->flag & NODE_DO_OUTPUT_RECALC) || context.isRendering();
35  bool ignore_alpha = (editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA) != 0;
36 
37  NodeInput *imageSocket = this->getInputSocket(0);
38  NodeInput *alphaSocket = this->getInputSocket(1);
39  NodeInput *depthSocket = this->getInputSocket(2);
40 
41  CompositorOperation *compositorOperation = new CompositorOperation();
42  compositorOperation->setScene(context.getScene());
43  compositorOperation->setSceneName(context.getScene()->id.name);
44  compositorOperation->setRenderData(context.getRenderData());
45  compositorOperation->setViewName(context.getViewName());
46  compositorOperation->setbNodeTree(context.getbNodeTree());
47  /* alpha socket gives either 1 or a custom alpha value if "use alpha" is enabled */
48  compositorOperation->setUseAlphaInput(ignore_alpha || alphaSocket->isLinked());
49  compositorOperation->setActive(is_active);
50 
51  converter.addOperation(compositorOperation);
52  converter.mapInputSocket(imageSocket, compositorOperation->getInputSocket(0));
53  /* only use alpha link if "use alpha" is enabled */
54  if (ignore_alpha) {
55  converter.addInputValue(compositorOperation->getInputSocket(1), 1.0f);
56  }
57  else {
58  converter.mapInputSocket(alphaSocket, compositorOperation->getInputSocket(1));
59  }
60  converter.mapInputSocket(depthSocket, compositorOperation->getInputSocket(2));
61 
62  converter.addNodeInputPreview(imageSocket);
63 }
64 
65 } // namespace blender::compositor
#define NODE_DO_OUTPUT_RECALC
#define CMP_NODE_OUTPUT_IGNORE_ALPHA
Overall context of the compositor.
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void setScene(const struct Scene *scene)
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addNodeInputPreview(NodeInput *input)
void addInputValue(NodeOperationInput *input, float value)
void addOperation(NodeOperation *operation)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
void setbNodeTree(const bNodeTree *tree)
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
short custom2