Blender  V2.93
COM_BlurNode.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_BlurNode.h"
20 #include "COM_ExecutionSystem.h"
28 #include "COM_MathBaseOperation.h"
29 #include "COM_SetValueOperation.h"
30 #include "DNA_node_types.h"
31 
32 namespace blender::compositor {
33 
34 BlurNode::BlurNode(bNode *editorNode) : Node(editorNode)
35 {
36  /* pass */
37 }
38 
40  const CompositorContext &context) const
41 {
42  bNode *editorNode = this->getbNode();
43  NodeBlurData *data = (NodeBlurData *)editorNode->storage;
44  NodeInput *inputSizeSocket = this->getInputSocket(1);
45  bool connectedSizeSocket = inputSizeSocket->isLinked();
46 
47  const float size = this->getInputSocket(1)->getEditorValueFloat();
48  const bool extend_bounds = (editorNode->custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS) != 0;
49 
50  eCompositorQuality quality = context.getQuality();
51  NodeOperation *input_operation = nullptr, *output_operation = nullptr;
52 
53  if (data->filtertype == R_FILTER_FAST_GAUSS) {
55  operationfgb->setData(data);
56  operationfgb->setExtendBounds(extend_bounds);
57  converter.addOperation(operationfgb);
58 
59  converter.mapInputSocket(getInputSocket(1), operationfgb->getInputSocket(1));
60 
61  input_operation = operationfgb;
62  output_operation = operationfgb;
63  }
64  else if (editorNode->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) {
67  zero->setValue(0.0f);
68  clamp->setUseClamp(true);
69 
70  converter.addOperation(clamp);
71  converter.addOperation(zero);
72  converter.mapInputSocket(getInputSocket(1), clamp->getInputSocket(0));
73  converter.addLink(zero->getOutputSocket(), clamp->getInputSocket(1));
74 
76  operationx->setData(data);
77  operationx->setQuality(quality);
78  operationx->setSize(1.0f);
79  operationx->setFalloff(PROP_SMOOTH);
80  operationx->setSubtract(false);
81  operationx->setExtendBounds(extend_bounds);
82 
83  converter.addOperation(operationx);
84  converter.addLink(clamp->getOutputSocket(), operationx->getInputSocket(0));
85 
87  operationy->setData(data);
88  operationy->setQuality(quality);
89  operationy->setSize(1.0f);
90  operationy->setFalloff(PROP_SMOOTH);
91  operationy->setSubtract(false);
92  operationy->setExtendBounds(extend_bounds);
93 
94  converter.addOperation(operationy);
95  converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0));
96 
98  operation->setData(data);
99  operation->setQuality(quality);
100  operation->setExtendBounds(extend_bounds);
101 
102  converter.addOperation(operation);
103  converter.addLink(operationy->getOutputSocket(), operation->getInputSocket(1));
104 
105  output_operation = operation;
106  input_operation = operation;
107  }
108  else if (!data->bokeh) {
110  operationx->setData(data);
111  operationx->setQuality(quality);
112  operationx->checkOpenCL();
113  operationx->setExtendBounds(extend_bounds);
114 
115  converter.addOperation(operationx);
116  converter.mapInputSocket(getInputSocket(1), operationx->getInputSocket(1));
117 
119  operationy->setData(data);
120  operationy->setQuality(quality);
121  operationy->checkOpenCL();
122  operationy->setExtendBounds(extend_bounds);
123 
124  converter.addOperation(operationy);
125  converter.mapInputSocket(getInputSocket(1), operationy->getInputSocket(1));
126  converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0));
127 
128  if (!connectedSizeSocket) {
129  operationx->setSize(size);
130  operationy->setSize(size);
131  }
132 
133  input_operation = operationx;
134  output_operation = operationy;
135  }
136  else {
138  operation->setData(data);
139  operation->setQuality(quality);
140  operation->setExtendBounds(extend_bounds);
141 
142  converter.addOperation(operation);
143  converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
144 
145  if (!connectedSizeSocket) {
146  operation->setSize(size);
147  }
148 
149  input_operation = operation;
150  output_operation = operation;
151  }
152 
153  if (data->gamma) {
156  converter.addOperation(correct);
157  converter.addOperation(inverse);
158 
159  converter.mapInputSocket(getInputSocket(0), correct->getInputSocket(0));
160  converter.addLink(correct->getOutputSocket(), input_operation->getInputSocket(0));
161  converter.addLink(output_operation->getOutputSocket(), inverse->getInputSocket(0));
162  converter.mapOutputSocket(getOutputSocket(), inverse->getOutputSocket());
163 
164  converter.addPreview(inverse->getOutputSocket());
165  }
166  else {
167  converter.mapInputSocket(getInputSocket(0), input_operation->getInputSocket(0));
168  converter.mapOutputSocket(getOutputSocket(), output_operation->getOutputSocket());
169 
170  converter.addPreview(output_operation->getOutputSocket());
171  }
172 }
173 
174 } // namespace blender::compositor
@ CMP_NODEFLAG_BLUR_VARIABLE_SIZE
@ CMP_NODEFLAG_BLUR_EXTEND_BOUNDS
#define PROP_SMOOTH
#define R_FILTER_FAST_GAUSS
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btTransform.h:182
void setData(const NodeBlurData *data)
BlurNode(bNode *editorNode)
Definition: COM_BlurNode.cc:34
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Definition: COM_BlurNode.cc:39
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
float getEditorValueFloat() const
Definition: COM_Node.cc:159
NodeOperation contains calculation logic.
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)
eCompositorQuality
Possible quality settings.
Definition: COM_Enums.h:32
short custom1
void * storage
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283