Matched FogGlow with old implementation
[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_GlareThresholdOperation.h"
26 #include "COM_GlareSimpleStarOperation.h"
27 #include "COM_GlareStreaksOperation.h"
28 #include "COM_SetValueOperation.h"
29 #include "COM_MixBlendOperation.h"
30 #include "COM_FastGaussianBlurOperation.h"
31 #include "COM_GlareGhostOperation.h"
32 #include "COM_GlareFogGlowOperation.h"
33
34 GlareNode::GlareNode(bNode *editorNode): Node(editorNode)
35 {
36 }
37
38 void GlareNode::convertToOperations(ExecutionSystem *system, CompositorContext * context)\
39 {
40         bNode *node = this->getbNode();
41         NodeGlare *glare = (NodeGlare*)node->storage;
42         
43         switch (glare->type) {
44         
45         default:
46         case 3:
47                 {
48                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
49                         GlareGhostOperation * glareoperation = new GlareGhostOperation();
50                         SetValueOperation * mixvalueoperation = new SetValueOperation();
51                         MixBlendOperation * mixoperation = new MixBlendOperation();
52         
53                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), 0, system);
54                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
55                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
56                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
57                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
58                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
59         
60                         thresholdOperation->setThreshold(glare->threshold);
61                         glareoperation->setGlareSettings(glare);
62                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
63                         mixoperation->setResolutionInputSocketIndex(1);
64         
65                         system->addOperation(glareoperation);
66                         system->addOperation(thresholdOperation);
67                         system->addOperation(mixvalueoperation);
68                         system->addOperation(mixoperation);
69                 }
70         case 2: // streaks
71                 {
72                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
73                         GlareStreaksOperation * glareoperation = new GlareStreaksOperation();
74                         SetValueOperation * mixvalueoperation = new SetValueOperation();
75                         MixBlendOperation * mixoperation = new MixBlendOperation();
76         
77                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), 0, system);
78                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
79                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
80                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
81                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
82                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
83         
84                         thresholdOperation->setThreshold(glare->threshold);
85                         glareoperation->setGlareSettings(glare);
86                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
87                         mixoperation->setResolutionInputSocketIndex(1);
88         
89                         system->addOperation(glareoperation);
90                         system->addOperation(thresholdOperation);
91                         system->addOperation(mixvalueoperation);
92                         system->addOperation(mixoperation);
93                 }       
94                 break;
95         case 1: // fog glow
96                 {
97                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
98                         GlareFogGlowOperation * glareoperation = new GlareFogGlowOperation();
99                         SetValueOperation * mixvalueoperation = new SetValueOperation();
100                         MixBlendOperation * mixoperation = new MixBlendOperation();
101         
102                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), 0, system);
103                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
104                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
105                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
106                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
107                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
108         
109                         thresholdOperation->setThreshold(glare->threshold);
110                         glareoperation->setGlareSettings(glare);
111                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
112                         mixoperation->setResolutionInputSocketIndex(1);
113         
114                         system->addOperation(glareoperation);
115                         system->addOperation(thresholdOperation);
116                         system->addOperation(mixvalueoperation);
117                         system->addOperation(mixoperation);
118                 }
119                 break;
120                 
121         case 0: // simple star
122                 {
123                         GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
124                         GlareSimpleStarOperation * glareoperation = new GlareSimpleStarOperation();
125                         SetValueOperation * mixvalueoperation = new SetValueOperation();
126                         MixBlendOperation * mixoperation = new MixBlendOperation();
127
128                         this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), 0, system);
129                         addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
130                         addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
131                         addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
132                         addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
133                         this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
134
135                         thresholdOperation->setThreshold(glare->threshold);
136                         glareoperation->setGlareSettings(glare);
137                         mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
138                         mixoperation->setResolutionInputSocketIndex(1);
139
140
141                         system->addOperation(glareoperation);
142                         system->addOperation(thresholdOperation);
143                         system->addOperation(mixvalueoperation);
144                         system->addOperation(mixoperation);
145                 }
146                 break;
147         }
148 }