Blender  V2.93
COM_DefocusNode.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_DefocusNode.h"
22 #include "COM_ExecutionSystem.h"
25 #include "COM_MathBaseOperation.h"
26 #include "COM_SetValueOperation.h"
28 #include "DNA_camera_types.h"
29 #include "DNA_node_types.h"
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 
33 namespace blender::compositor {
34 
35 DefocusNode::DefocusNode(bNode *editorNode) : Node(editorNode)
36 {
37  /* pass */
38 }
39 
41  const CompositorContext &context) const
42 {
43  bNode *node = this->getbNode();
44  NodeDefocus *data = (NodeDefocus *)node->storage;
45  Scene *scene = node->id ? (Scene *)node->id : context.getScene();
46  Object *camob = scene ? scene->camera : nullptr;
47 
48  NodeOperation *radiusOperation;
49  if (data->no_zbuf) {
51  SetValueOperation *multiplier = new SetValueOperation();
52  multiplier->setValue(data->scale);
53  SetValueOperation *maxRadius = new SetValueOperation();
54  maxRadius->setValue(data->maxblur);
56 
57  converter.addOperation(multiply);
58  converter.addOperation(multiplier);
59  converter.addOperation(maxRadius);
60  converter.addOperation(minimize);
61 
62  converter.mapInputSocket(getInputSocket(1), multiply->getInputSocket(0));
63  converter.addLink(multiplier->getOutputSocket(), multiply->getInputSocket(1));
64  converter.addLink(multiply->getOutputSocket(), minimize->getInputSocket(0));
65  converter.addLink(maxRadius->getOutputSocket(), minimize->getInputSocket(1));
66 
67  radiusOperation = minimize;
68  }
69  else {
71  radius_op->setCameraObject(camob);
72  radius_op->setfStop(data->fstop);
73  radius_op->setMaxRadius(data->maxblur);
74  converter.addOperation(radius_op);
75 
76  converter.mapInputSocket(getInputSocket(1), radius_op->getInputSocket(0));
77 
79  /* maintain close pixels so far Z values don't bleed into the foreground */
81  converter.addOperation(blur);
82 
83  converter.addLink(radius_op->getOutputSocket(0), blur->getInputSocket(0));
84  radius_op->setPostBlur(blur);
85 
86  radiusOperation = blur;
87  }
88 
89  NodeBokehImage *bokehdata = new NodeBokehImage();
90  bokehdata->angle = data->rotation;
91  bokehdata->rounding = 0.0f;
92  bokehdata->flaps = data->bktype;
93  if (data->bktype < 3) {
94  bokehdata->flaps = 5;
95  bokehdata->rounding = 1.0f;
96  }
97  bokehdata->catadioptric = 0.0f;
98  bokehdata->lensshift = 0.0f;
99 
101  bokeh->setData(bokehdata);
102  bokeh->deleteDataOnFinish();
103  converter.addOperation(bokeh);
104 
105 #ifdef COM_DEFOCUS_SEARCH
106  InverseSearchRadiusOperation *search = new InverseSearchRadiusOperation();
107  search->setMaxBlur(data->maxblur);
108  converter.addOperation(search);
109 
110  converter.addLink(radiusOperation->getOutputSocket(0), search->getInputSocket(0));
111 #endif
112 
114  if (data->preview) {
116  }
117  else {
118  operation->setQuality(context.getQuality());
119  }
120  operation->setMaxBlur(data->maxblur);
121  operation->setThreshold(data->bthresh);
122  converter.addOperation(operation);
123 
124  converter.addLink(bokeh->getOutputSocket(), operation->getInputSocket(1));
125  converter.addLink(radiusOperation->getOutputSocket(), operation->getInputSocket(2));
126 #ifdef COM_DEFOCUS_SEARCH
127  converter.addLink(search->getOutputSocket(), operation->getInputSocket(3));
128 #endif
129 
130  if (data->gamco) {
132  converter.addOperation(correct);
134  converter.addOperation(inverse);
135 
136  converter.mapInputSocket(getInputSocket(0), correct->getInputSocket(0));
137  converter.addLink(correct->getOutputSocket(), operation->getInputSocket(0));
138  converter.addLink(operation->getOutputSocket(), inverse->getInputSocket(0));
139  converter.mapOutputSocket(getOutputSocket(), inverse->getOutputSocket());
140  }
141  else {
142  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
143  converter.mapOutputSocket(getOutputSocket(), operation->getOutputSocket());
144  }
145 }
146 
147 } // namespace blender::compositor
struct NodeBokehImage NodeBokehImage
Object is a sort of wrapper for general info.
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btTransform.h:182
The BokehImageOperation class is an operation that creates an image useful to mimic the internals of ...
void setData(NodeBokehImage *data)
set the node data
Overall context of the compositor.
void setPostBlur(FastGaussianBlurValueOperation *operation)
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
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)
OperationNode * node
Scene scene
static void minimize(float rvalue[3], float mp[3], const float pts[12][3], const float norms[12][3], const int parity[12])
Definition: octree.cpp:2236
struct Object * camera