c65adc862b1b63abee356dfe1760fd107696d08b
[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_BokehBlurOperation.h"
27 #include "COM_GlareThresholdOperation.h"
28 #include "COM_GlareSimpleStarOperation.h"
29 #include "COM_GlareStreaksOperation.h"
30 #include "COM_SetValueOperation.h"
31 #include "COM_MixBlendOperation.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                         FogGlowImageOperation * kerneloperation = new FogGlowImageOperation();
74                         BokehBlurOperation * bluroperation = new BokehBlurOperation();
75                         SetValueOperation * valueoperation = new SetValueOperation();
76                         SetValueOperation * mixvalueoperation = new SetValueOperation();
77                         MixBlendOperation * mixoperation = new MixBlendOperation();
78                         mixoperation->setResolutionInputSocketIndex(1);
79                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
80                         addLink(system, thresholdOperation->getOutputSocket(), bluroperation->getInputSocket(0));
81                         addLink(system, kerneloperation->getOutputSocket(), bluroperation->getInputSocket(1));
82                         addLink(system, valueoperation->getOutputSocket(), bluroperation->getInputSocket(2));
83                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
84                         addLink(system, bluroperation->getOutputSocket(), mixoperation->getInputSocket(2));
85                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
86         
87                         thresholdOperation->setThreshold(glare->threshold);
88                         bluroperation->setSize(0.003f*glare->size);
89                         bluroperation->setQuality(context->getQuality());
90                         valueoperation->setValue(1.0f);
91                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
92                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
93         
94                         system->addOperation(bluroperation);
95                         system->addOperation(kerneloperation);
96                         system->addOperation(thresholdOperation);
97                         system->addOperation(mixvalueoperation);
98                         system->addOperation(valueoperation);
99                         system->addOperation(mixoperation);
100                 }
101                 break;
102                 
103         case 0: // simple star
104                 {
105                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
106                         GlareSimpleStarOperation * glareoperation = new GlareSimpleStarOperation();
107                         SetValueOperation * mixvalueoperation = new SetValueOperation();
108                         MixBlendOperation * mixoperation = new MixBlendOperation();
109
110                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
111                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
112                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
113                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
114                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
115                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
116
117                         thresholdOperation->setThreshold(glare->threshold);
118                         glareoperation->setGlareSettings(glare);
119                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
120                         mixoperation->setResolutionInputSocketIndex(1);
121
122
123                         system->addOperation(glareoperation);
124                         system->addOperation(thresholdOperation);
125                         system->addOperation(mixvalueoperation);
126                         system->addOperation(mixoperation);
127                 }
128                 break;
129         }
130 }