compositor: bokeh blur size input can now be an image, in this case it uses VariableS...
[blender-staging.git] / source / blender / compositor / nodes / COM_BokehBlurNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #include "COM_BokehBlurNode.h"
24 #include "DNA_camera_types.h"
25 #include "DNA_object_types.h"
26 #include "DNA_node_types.h"
27 #include "COM_ExecutionSystem.h"
28 #include "COM_BokehBlurOperation.h"
29 #include "COM_VariableSizeBokehBlurOperation.h"
30 #include "COM_ConvertDepthToRadiusOperation.h"
31
32 BokehBlurNode::BokehBlurNode(bNode *editorNode) : Node(editorNode)
33 {
34         /* pass */
35 }
36
37 void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
38 {
39         InputSocket *inputSizeSocket = this->getInputSocket(2);
40         bool connectedSizeSocket = inputSizeSocket->isConnected();
41
42         if (connectedSizeSocket) {
43                 VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation();
44
45                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
46                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
47                 this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph);
48                 operation->setQuality(context->getQuality());
49                 operation->setbNode(this->getbNode());
50                 graph->addOperation(operation);
51                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
52
53                 operation->setThreshold(0.0f);
54
55                 /* TODO, we need to know the max input pixel of the input, this value is arbitrary! */
56                 operation->setMaxBlur(100.0f);
57                 operation->setDoScaleSize(true);
58         }
59         else {
60                 BokehBlurOperation *operation = new BokehBlurOperation();
61
62                 const bNodeSocket *sock = this->getInputSocket(2)->getbNodeSocket();
63                 const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value;
64
65                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
66                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
67                 this->getInputSocket(2)->relinkConnections(operation->getInputSocket(3), 2, graph);
68                 this->getInputSocket(3)->relinkConnections(operation->getInputSocket(2), 3, graph);
69                 //operation->setSize(((bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value);
70                 operation->setQuality(context->getQuality());
71                 operation->setbNode(this->getbNode());
72                 graph->addOperation(operation);
73                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
74
75                 operation->setSize(size);
76         }
77 }