Blender V4.3
node_composite_math.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "GPU_material.hh"
10
11#include "COM_shader_node.hh"
12
13#include "NOD_math_functions.hh"
15
16#include "RNA_enum_types.hh"
17
19
20/* **************** SCALAR MATH ******************** */
21
23
25{
26 b.add_input<decl::Float>("Value")
27 .default_value(0.5f)
28 .min(-10000.0f)
29 .max(10000.0f)
31 b.add_input<decl::Float>("Value", "Value_001")
32 .default_value(0.5f)
33 .min(-10000.0f)
34 .max(10000.0f)
36 b.add_input<decl::Float>("Value", "Value_002")
37 .default_value(0.5f)
38 .min(-10000.0f)
39 .max(10000.0f)
41 b.add_output<decl::Float>("Value");
42}
43
45 public:
46 std::string socket_name;
49 {
50 bNode &node = params.add_node("CompositorNodeMath");
51 node.custom1 = mode;
52 params.update_and_connect_available_socket(node, socket_name);
53 }
54};
55
57{
58 const int weight = ELEM(params.other_socket().type, SOCK_FLOAT) ? 0 : -1;
59
60 for (const EnumPropertyItem *item = rna_enum_node_math_items; item->identifier != nullptr;
61 item++)
62 {
63 if (item->name != nullptr && item->identifier[0] != '\0') {
64 params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
65 SocketSearchOp{"Value", (NodeMathOperation)item->value},
66 weight);
67 }
68 }
69}
70
71using namespace blender::realtime_compositor;
72
73class MathShaderNode : public ShaderNode {
74 public:
76
77 void compile(GPUMaterial *material) override
78 {
81
82 GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
83
84 if (!get_should_clamp()) {
85 return;
86 }
87
88 const float min = 0.0f;
89 const float max = 1.0f;
90 GPU_link(material,
91 "clamp_value",
92 get_output("Value").link,
94 GPU_constant(&max),
95 &get_output("Value").link);
96 }
97
102
107
109 {
110 return bnode().custom2 & SHD_MATH_CLAMP;
111 }
112};
113
115{
116 return new MathShaderNode(node);
117}
118
119} // namespace blender::nodes::node_composite_math_cc
120
122{
123 namespace file_ns = blender::nodes::node_composite_math_cc;
124
125 static blender::bke::bNodeType ntype;
126
127 cmp_node_type_base(&ntype, CMP_NODE_MATH, "Math", NODE_CLASS_CONVERTER);
128 ntype.declare = file_ns::cmp_node_math_declare;
131 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
132 ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
133
135}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:410
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_NODETREE
#define CTX_IFACE_(context, msgid)
NodeMathOperation
@ NODE_MATH_ADD
@ SHD_MATH_CLAMP
@ SOCK_FLOAT
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
constexpr const char * c_str() const
GPUNodeStack & get_output(StringRef identifier)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static ShaderNode * get_compositor_shader_node(DNode node)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void cmp_node_math_declare(NodeDeclarationBuilder &b)
const FloatMathOperationInfo * get_float_math_operation_info(const int operation)
void register_node_type_cmp_math()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_math_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:203
void node_math_update(bNodeTree *ntree, bNode *node)
Definition node_util.cc:89
const EnumPropertyItem rna_enum_node_math_items[]
#define min(a, b)
Definition sort.c:32
const char * identifier
Definition RNA_types.hh:506
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328