Added switch in dilate/erode between old (Step) and new (Distance)
[blender.git] / source / blender / compositor / nodes / COM_GlareNode.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_GlareNode.h"
24 #include "DNA_node_types.h"
25 #include "COM_FogGlowImageOperation.h"
26 #include "COM_GlareThresholdOperation.h"
27 #include "COM_GlareSimpleStarOperation.h"
28 #include "COM_GlareStreaksOperation.h"
29 #include "COM_SetValueOperation.h"
30 #include "COM_MixBlendOperation.h"
31 #include "COM_FastGaussianBlurOperation.h"
32
33 GlareNode::GlareNode(bNode *editorNode): Node(editorNode)
34 {
35 }
36
37 void GlareNode::convertToOperations(ExecutionSystem *system, CompositorContext * context)\
38 {
39         bNode *node = this->getbNode();
40         NodeGlare *glare = (NodeGlare*)node->storage;
41         
42         switch (glare->type) {
43         
44         default:
45         case 2: // streaks
46                 {
47                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
48                         GlareStreaksOperation * glareoperation = new GlareStreaksOperation();
49                         SetValueOperation * mixvalueoperation = new SetValueOperation();
50                         MixBlendOperation * mixoperation = new MixBlendOperation();
51         
52                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
53                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
54                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
55                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
56                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
57                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
58         
59                         thresholdOperation->setThreshold(glare->threshold);
60                         glareoperation->setGlareSettings(glare);
61                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
62                         mixoperation->setResolutionInputSocketIndex(1);
63         
64                         system->addOperation(glareoperation);
65                         system->addOperation(thresholdOperation);
66                         system->addOperation(mixvalueoperation);
67                         system->addOperation(mixoperation);
68                 }       
69                 break;
70         case 1: // fog glow
71                 {
72                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
73                         FastGaussianBlurOperation* bluroperation = new FastGaussianBlurOperation();
74                         SetValueOperation * valueoperation = new SetValueOperation();
75                         SetValueOperation * mixvalueoperation = new SetValueOperation();
76                         MixBlendOperation * mixoperation = new MixBlendOperation();
77                         mixoperation->setResolutionInputSocketIndex(1);
78                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
79                         addLink(system, thresholdOperation->getOutputSocket(), bluroperation->getInputSocket(0));
80                         addLink(system, valueoperation->getOutputSocket(), bluroperation->getInputSocket(1));
81                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
82                         addLink(system, bluroperation->getOutputSocket(), mixoperation->getInputSocket(2));
83                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
84         
85                         thresholdOperation->setThreshold(glare->threshold);
86                         NodeBlurData * data = new NodeBlurData();
87                         data->relative = 0;
88                         data->sizex = glare->size;
89                         data->sizey = glare->size;
90                         bluroperation->setData(data);
91                         bluroperation->deleteDataWhenFinished();
92                         bluroperation->setQuality(context->getQuality());
93                         valueoperation->setValue(1.0f);
94                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
95                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
96         
97                         system->addOperation(bluroperation);
98                         system->addOperation(thresholdOperation);
99                         system->addOperation(mixvalueoperation);
100                         system->addOperation(valueoperation);
101                         system->addOperation(mixoperation);
102                 }
103                 break;
104                 
105         case 0: // simple star
106                 {
107                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
108                         GlareSimpleStarOperation * glareoperation = new GlareSimpleStarOperation();
109                         SetValueOperation * mixvalueoperation = new SetValueOperation();
110                         MixBlendOperation * mixoperation = new MixBlendOperation();
111
112                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
113                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
114                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
115                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
116                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
117                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
118
119                         thresholdOperation->setThreshold(glare->threshold);
120                         glareoperation->setGlareSettings(glare);
121                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
122                         mixoperation->setResolutionInputSocketIndex(1);
123
124
125                         system->addOperation(glareoperation);
126                         system->addOperation(thresholdOperation);
127                         system->addOperation(mixvalueoperation);
128                         system->addOperation(mixoperation);
129                 }
130                 break;
131         }
132 }