Blender  V2.93
COM_ZCombineNode.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_ZCombineNode.h"
20 
21 #include "COM_ZCombineOperation.h"
22 
23 #include "COM_AntiAliasOperation.h"
24 #include "COM_ExecutionSystem.h"
25 #include "COM_MathBaseOperation.h"
26 #include "COM_MixOperation.h"
27 #include "COM_SetValueOperation.h"
28 
29 #include "DNA_material_types.h" /* the ramp types */
30 
31 namespace blender::compositor {
32 
34  const CompositorContext &context) const
35 {
36  if ((context.getRenderData()->scemode & R_FULL_SAMPLE) || this->getbNode()->custom2) {
37  ZCombineOperation *operation = nullptr;
38  if (this->getbNode()->custom1) {
39  operation = new ZCombineAlphaOperation();
40  }
41  else {
42  operation = new ZCombineOperation();
43  }
44  converter.addOperation(operation);
45 
46  converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
47  converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
48  converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(2));
49  converter.mapInputSocket(getInputSocket(3), operation->getInputSocket(3));
50  converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
51 
52  MathMinimumOperation *zoperation = new MathMinimumOperation();
53  converter.addOperation(zoperation);
54 
55  converter.mapInputSocket(getInputSocket(1), zoperation->getInputSocket(0));
56  converter.mapInputSocket(getInputSocket(3), zoperation->getInputSocket(1));
57  converter.mapOutputSocket(getOutputSocket(1), zoperation->getOutputSocket());
58  }
59  else {
60  /* XXX custom1 is "use_alpha", what on earth is this supposed to do here?!? */
61  // not full anti alias, use masking for Z combine. be aware it uses anti aliasing.
62  // step 1 create mask
63  NodeOperation *maskoperation;
64  if (this->getbNode()->custom1) {
65  maskoperation = new MathGreaterThanOperation();
66  converter.addOperation(maskoperation);
67 
68  converter.mapInputSocket(getInputSocket(1), maskoperation->getInputSocket(0));
69  converter.mapInputSocket(getInputSocket(3), maskoperation->getInputSocket(1));
70  }
71  else {
72  maskoperation = new MathLessThanOperation();
73  converter.addOperation(maskoperation);
74 
75  converter.mapInputSocket(getInputSocket(1), maskoperation->getInputSocket(0));
76  converter.mapInputSocket(getInputSocket(3), maskoperation->getInputSocket(1));
77  }
78 
79  // step 2 anti alias mask bit of an expensive operation, but does the trick
80  AntiAliasOperation *antialiasoperation = new AntiAliasOperation();
81  converter.addOperation(antialiasoperation);
82 
83  converter.addLink(maskoperation->getOutputSocket(), antialiasoperation->getInputSocket(0));
84 
85  // use mask to blend between the input colors.
86  ZCombineMaskOperation *zcombineoperation = this->getbNode()->custom1 ?
89  converter.addOperation(zcombineoperation);
90 
91  converter.addLink(antialiasoperation->getOutputSocket(), zcombineoperation->getInputSocket(0));
92  converter.mapInputSocket(getInputSocket(0), zcombineoperation->getInputSocket(1));
93  converter.mapInputSocket(getInputSocket(2), zcombineoperation->getInputSocket(2));
94  converter.mapOutputSocket(getOutputSocket(0), zcombineoperation->getOutputSocket());
95 
96  MathMinimumOperation *zoperation = new MathMinimumOperation();
97  converter.addOperation(zoperation);
98 
99  converter.mapInputSocket(getInputSocket(1), zoperation->getInputSocket(0));
100  converter.mapInputSocket(getInputSocket(3), zoperation->getInputSocket(1));
101  converter.mapOutputSocket(getOutputSocket(1), zoperation->getOutputSocket());
102  }
103 }
104 
105 } // namespace blender::compositor
#define R_FULL_SAMPLE
AntiAlias operations it only supports anti aliasing on BW buffers.
Overall context of the compositor.
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeOperation contains calculation logic.
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
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
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
short custom1