Blender  V2.93
COM_MixNode.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_MixNode.h"
20 
21 #include "COM_MixOperation.h"
22 
23 #include "COM_ExecutionSystem.h"
24 #include "COM_SetValueOperation.h"
25 #include "DNA_material_types.h" /* the ramp types */
26 
27 namespace blender::compositor {
28 
29 MixNode::MixNode(bNode *editorNode) : Node(editorNode)
30 {
31  /* pass */
32 }
33 
35  const CompositorContext & /*context*/) const
36 {
37  NodeInput *valueSocket = this->getInputSocket(0);
38  NodeInput *color1Socket = this->getInputSocket(1);
39  NodeInput *color2Socket = this->getInputSocket(2);
40  NodeOutput *outputSocket = this->getOutputSocket(0);
41  bNode *editorNode = this->getbNode();
42  bool useAlphaPremultiply = (this->getbNode()->custom2 & 1) != 0;
43  bool useClamp = (this->getbNode()->custom2 & 2) != 0;
44 
45  MixBaseOperation *convertProg;
46  switch (editorNode->custom1) {
47  case MA_RAMP_ADD:
48  convertProg = new MixAddOperation();
49  break;
50  case MA_RAMP_MULT:
51  convertProg = new MixMultiplyOperation();
52  break;
53  case MA_RAMP_LIGHT:
54  convertProg = new MixLightenOperation();
55  break;
56  case MA_RAMP_BURN:
57  convertProg = new MixColorBurnOperation();
58  break;
59  case MA_RAMP_HUE:
60  convertProg = new MixHueOperation();
61  break;
62  case MA_RAMP_COLOR:
63  convertProg = new MixColorOperation();
64  break;
65  case MA_RAMP_SOFT:
66  convertProg = new MixSoftLightOperation();
67  break;
68  case MA_RAMP_SCREEN:
69  convertProg = new MixScreenOperation();
70  break;
71  case MA_RAMP_LINEAR:
72  convertProg = new MixLinearLightOperation();
73  break;
74  case MA_RAMP_DIFF:
75  convertProg = new MixDifferenceOperation();
76  break;
77  case MA_RAMP_SAT:
78  convertProg = new MixSaturationOperation();
79  break;
80  case MA_RAMP_DIV:
81  convertProg = new MixDivideOperation();
82  break;
83  case MA_RAMP_SUB:
84  convertProg = new MixSubtractOperation();
85  break;
86  case MA_RAMP_DARK:
87  convertProg = new MixDarkenOperation();
88  break;
89  case MA_RAMP_OVERLAY:
90  convertProg = new MixOverlayOperation();
91  break;
92  case MA_RAMP_VAL:
93  convertProg = new MixValueOperation();
94  break;
95  case MA_RAMP_DODGE:
96  convertProg = new MixDodgeOperation();
97  break;
98 
99  case MA_RAMP_BLEND:
100  default:
101  convertProg = new MixBlendOperation();
102  break;
103  }
104  convertProg->setUseValueAlphaMultiply(useAlphaPremultiply);
105  convertProg->setUseClamp(useClamp);
106  converter.addOperation(convertProg);
107 
108  converter.mapInputSocket(valueSocket, convertProg->getInputSocket(0));
109  converter.mapInputSocket(color1Socket, convertProg->getInputSocket(1));
110  converter.mapInputSocket(color2Socket, convertProg->getInputSocket(2));
111  converter.mapOutputSocket(outputSocket, convertProg->getOutputSocket(0));
112 
113  converter.addPreview(convertProg->getOutputSocket(0));
114 }
115 
116 } // namespace blender::compositor
#define MA_RAMP_SUB
#define MA_RAMP_VAL
#define MA_RAMP_DIFF
#define MA_RAMP_DARK
#define MA_RAMP_BURN
#define MA_RAMP_LIGHT
#define MA_RAMP_SOFT
#define MA_RAMP_LINEAR
#define MA_RAMP_OVERLAY
#define MA_RAMP_MULT
#define MA_RAMP_SAT
#define MA_RAMP_DIV
#define MA_RAMP_DODGE
#define MA_RAMP_SCREEN
#define MA_RAMP_HUE
#define MA_RAMP_BLEND
#define MA_RAMP_ADD
#define MA_RAMP_COLOR
Overall context of the compositor.
void setUseValueAlphaMultiply(const bool value)
MixNode(bNode *editorNode)
Definition: COM_MixNode.cc:29
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Definition: COM_MixNode.cc:34
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
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
short custom1
short custom2