Blender  V3.3
COM_BlurNode.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_BlurNode.h"
12 #include "COM_MathBaseOperation.h"
13 #include "COM_SetValueOperation.h"
14 
15 namespace blender::compositor {
16 
17 BlurNode::BlurNode(bNode *editor_node) : Node(editor_node)
18 {
19  /* pass */
20 }
21 
23  const CompositorContext &context) const
24 {
25  bNode *editor_node = this->get_bnode();
26  NodeBlurData *data = (NodeBlurData *)editor_node->storage;
27  NodeInput *input_size_socket = this->get_input_socket(1);
28  bool connected_size_socket = input_size_socket->is_linked();
29 
30  const float size = this->get_input_socket(1)->get_editor_value_float();
31  const bool extend_bounds = (editor_node->custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS) != 0;
32 
33  eCompositorQuality quality = context.get_quality();
34  NodeOperation *input_operation = nullptr, *output_operation = nullptr;
35 
36  if (data->filtertype == R_FILTER_FAST_GAUSS) {
38  operationfgb->set_data(data);
39  operationfgb->set_extend_bounds(extend_bounds);
40  converter.add_operation(operationfgb);
41 
42  converter.map_input_socket(get_input_socket(1), operationfgb->get_input_socket(1));
43 
44  input_operation = operationfgb;
45  output_operation = operationfgb;
46  }
47  else if (editor_node->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) {
50  zero->set_value(0.0f);
51  clamp->set_use_clamp(true);
52 
53  converter.add_operation(clamp);
54  converter.add_operation(zero);
55  converter.map_input_socket(get_input_socket(1), clamp->get_input_socket(0));
56  converter.add_link(zero->get_output_socket(), clamp->get_input_socket(1));
57 
59  operationx->set_data(data);
60  operationx->set_quality(quality);
61  operationx->set_size(1.0f);
62  operationx->set_falloff(PROP_SMOOTH);
63  operationx->set_subtract(false);
64  operationx->set_extend_bounds(extend_bounds);
65 
66  converter.add_operation(operationx);
67  converter.add_link(clamp->get_output_socket(), operationx->get_input_socket(0));
68 
70  operationy->set_data(data);
71  operationy->set_quality(quality);
72  operationy->set_size(1.0f);
73  operationy->set_falloff(PROP_SMOOTH);
74  operationy->set_subtract(false);
75  operationy->set_extend_bounds(extend_bounds);
76 
77  converter.add_operation(operationy);
78  converter.add_link(operationx->get_output_socket(), operationy->get_input_socket(0));
79 
81  operation->set_data(data);
82  operation->set_quality(quality);
83  operation->set_extend_bounds(extend_bounds);
84 
85  converter.add_operation(operation);
86  converter.add_link(operationy->get_output_socket(), operation->get_input_socket(1));
87 
88  output_operation = operation;
89  input_operation = operation;
90  }
91  else if (!data->bokeh) {
93  operationx->set_data(data);
94  operationx->set_quality(quality);
95  operationx->check_opencl();
96  operationx->set_extend_bounds(extend_bounds);
97 
98  converter.add_operation(operationx);
99  converter.map_input_socket(get_input_socket(1), operationx->get_input_socket(1));
100 
102  operationy->set_data(data);
103  operationy->set_quality(quality);
104  operationy->check_opencl();
105  operationy->set_extend_bounds(extend_bounds);
106 
107  converter.add_operation(operationy);
108  converter.map_input_socket(get_input_socket(1), operationy->get_input_socket(1));
109  converter.add_link(operationx->get_output_socket(), operationy->get_input_socket(0));
110 
111  if (!connected_size_socket) {
112  operationx->set_size(size);
113  operationy->set_size(size);
114  }
115 
116  input_operation = operationx;
117  output_operation = operationy;
118  }
119  else {
121  operation->set_data(data);
122  operation->set_quality(quality);
123  operation->set_extend_bounds(extend_bounds);
124 
125  converter.add_operation(operation);
126  converter.map_input_socket(get_input_socket(1), operation->get_input_socket(1));
127 
128  if (!connected_size_socket) {
129  operation->set_size(size);
130  }
131 
132  input_operation = operation;
133  output_operation = operation;
134  }
135 
136  if (data->gamma) {
139  converter.add_operation(correct);
140  converter.add_operation(inverse);
141 
142  converter.map_input_socket(get_input_socket(0), correct->get_input_socket(0));
143  converter.add_link(correct->get_output_socket(), input_operation->get_input_socket(0));
144  converter.add_link(output_operation->get_output_socket(), inverse->get_input_socket(0));
145  converter.map_output_socket(get_output_socket(), inverse->get_output_socket());
146 
147  converter.add_preview(inverse->get_output_socket());
148  }
149  else {
150  converter.map_input_socket(get_input_socket(0), input_operation->get_input_socket(0));
151  converter.map_output_socket(get_output_socket(), output_operation->get_output_socket());
152 
153  converter.add_preview(output_operation->get_output_socket());
154  }
155 }
156 
157 } // namespace blender::compositor
@ CMP_NODEFLAG_BLUR_VARIABLE_SIZE
@ CMP_NODEFLAG_BLUR_EXTEND_BOUNDS
#define PROP_SMOOTH
#define R_FILTER_FAST_GAUSS
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
btMatrix3x3 inverse() const
Return the inverse of the matrix.
Definition: btTransform.h:182
void set_data(const NodeBlurData *data)
BlurNode(bNode *editor_node)
Definition: COM_BlurNode.cc:17
void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
Definition: COM_BlurNode.cc:22
Overall context of the compositor.
void add_link(NodeOperationOutput *from, NodeOperationInput *to)
void map_output_socket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void add_preview(NodeOperationOutput *output)
void add_operation(NodeOperation *operation)
void map_input_socket(NodeInput *node_socket, NodeOperationInput *operation_socket)
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:190
float get_editor_value_float() const
Definition: COM_Node.cc:135
NodeOperation contains calculation logic.
NodeOperationOutput * get_output_socket(unsigned int index=0)
NodeOperationInput * get_input_socket(unsigned int index)
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89
void set_quality(eCompositorQuality quality)
eCompositorQuality
Possible quality settings.
Definition: COM_Enums.h:19
T clamp(const T &a, const T &min, const T &max)
short custom1
void * storage