Blender  V2.93
COM_BokehBlurNode.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_BokehBlurNode.h"
20 #include "COM_BokehBlurOperation.h"
22 #include "COM_ExecutionSystem.h"
24 #include "DNA_camera_types.h"
25 #include "DNA_node_types.h"
26 #include "DNA_object_types.h"
27 
28 namespace blender::compositor {
29 
30 BokehBlurNode::BokehBlurNode(bNode *editorNode) : Node(editorNode)
31 {
32  /* pass */
33 }
34 
36  const CompositorContext &context) const
37 {
38  bNode *b_node = this->getbNode();
39 
40  NodeInput *inputSizeSocket = this->getInputSocket(2);
41 
42  bool connectedSizeSocket = inputSizeSocket->isLinked();
43  const bool extend_bounds = (b_node->custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS) != 0;
44 
45  if ((b_node->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) && connectedSizeSocket) {
47  operation->setQuality(context.getQuality());
48  operation->setThreshold(0.0f);
49  operation->setMaxBlur(b_node->custom4);
50  operation->setDoScaleSize(true);
51 
52  converter.addOperation(operation);
53  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
54  converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
55  converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(2));
56  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
57  }
58  else {
59  BokehBlurOperation *operation = new BokehBlurOperation();
60  operation->setQuality(context.getQuality());
61  operation->setExtendBounds(extend_bounds);
62 
63  converter.addOperation(operation);
64  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
65  converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
66 
67  // NOTE: on the bokeh blur operation the sockets are switched.
68  // for this reason the next two lines are correct.
69  // Fix for T43771
70  converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(3));
71  converter.mapInputSocket(getInputSocket(3), operation->getInputSocket(2));
72 
73  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
74 
75  if (!connectedSizeSocket) {
76  operation->setSize(this->getInputSocket(2)->getEditorValueFloat());
77  }
78  }
79 }
80 
81 } // namespace blender::compositor
@ CMP_NODEFLAG_BLUR_VARIABLE_SIZE
@ CMP_NODEFLAG_BLUR_EXTEND_BOUNDS
Object is a sort of wrapper for general info.
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
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
void setQuality(eCompositorQuality quality)
short custom1
float custom4