Blender V4.5
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
8
11
12#include "RNA_enum_types.hh"
13
14#include "GPU_material.hh"
15
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
44using namespace blender::compositor;
45
47{
48 return static_cast<NodeMathOperation>(node.custom1);
49}
50
51static const char *get_shader_function_name(const bNode &node)
52{
54}
55
56static bool get_should_clamp(const bNode &node)
57{
58 return node.custom2 & SHD_MATH_CLAMP;
59}
60
61static int node_gpu_material(GPUMaterial *material,
62 bNode *node,
63 bNodeExecData * /*execdata*/,
66{
67 const bool is_valid = GPU_stack_link(
68 material, node, get_shader_function_name(*node), inputs, outputs);
69
70 if (!is_valid || !get_should_clamp(*node)) {
71 return is_valid;
72 }
73
74 const float min = 0.0f;
75 const float max = 1.0f;
76 return GPU_link(material,
77 "clamp_value",
78 get_shader_node_output(*node, outputs, "Value").link,
81 &get_shader_node_output(*node, outputs, "Value").link);
82}
83
84} // namespace blender::nodes::node_composite_math_cc
85
87{
89
90 static blender::bke::bNodeType ntype;
91
92 cmp_node_type_base(&ntype, "CompositorNodeMath", CMP_NODE_MATH);
93 ntype.ui_name = "Math";
94 ntype.ui_description = "Perform math operations";
95 ntype.enum_name_legacy = "MATH";
97 ntype.declare = file_ns::cmp_node_math_declare;
100 ntype.gpu_fn = file_ns::node_gpu_material;
102 ntype.gather_link_search_ops = nullptr;
103
105}
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:439
#define CMP_NODE_MATH
@ SHD_MATH_CLAMP
NodeMathOperation
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,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr const char * c_str() const
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
GPUNodeStack & get_shader_node_output(const bNode &node, GPUNodeStack outputs[], StringRef identifier)
static const char * get_shader_function_name(const bNode &node)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static NodeMathOperation get_operation(const bNode &node)
static bool get_should_clamp(const bNode &node)
static void cmp_node_math_declare(NodeDeclarationBuilder &b)
void node_math_build_multi_function(NodeMultiFunctionBuilder &builder)
const FloatMathOperationInfo * get_float_math_operation_info(const int operation)
static void register_node_type_cmp_math()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
void node_math_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:201
void node_math_update(bNodeTree *ntree, bNode *node)
Definition node_util.cc:85
#define min(a, b)
Definition sort.cc:36
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:258
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:344
const char * enum_name_legacy
Definition BKE_node.hh:235
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:371
NodeDeclareFunction declare
Definition BKE_node.hh:355
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:269
max
Definition text_draw.cc:251