Blender V5.3
node_shader_value.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10
12
14#include "NOD_multi_function.hh"
15
17#include "UI_resources.hh"
18
19namespace blender {
20
22
24{
25 b.add_output<decl::Float>("Value"_ustr).custom_draw([](CustomSocketDrawParams &params) {
27 ui::Layout &row = params.layout.row(true);
28 row.prop(&params.socket_ptr, "default_value", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
29 if (gizmos::value_node_has_gizmo(params.tree, params.node)) {
30 row.prop(&params.socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
31 }
32 });
33}
34
36 bNode *node,
37 bNodeExecData * /*execdata*/,
38 GPUNodeStack * /*in*/,
40{
41 const bNodeSocket *socket = node->outputs.first();
42 float value = static_cast<bNodeSocketValueFloat *>(socket->default_value)->value;
43 return GPU_link(mat, "set_value", GPU_uniform(&value), &out->link);
44}
45
47{
48 const bNodeSocket *bsocket = builder.node().outputs.first();
49 const bNodeSocketValueFloat *value = static_cast<const bNodeSocketValueFloat *>(
50 bsocket->default_value);
51 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float>>(value->value);
52}
53
55#ifdef WITH_MATERIALX
56{
57 NodeItem value = get_output_default("Value", NodeItem::Type::Float);
58 return create_node("constant", NodeItem::Type::Float, {{"value", value}});
59}
60#endif
62
63} // namespace nodes::node_shader_value_cc
64
66{
67 namespace file_ns = nodes::node_shader_value_cc;
68
69 static bke::bNodeType ntype;
70
71 common_node_type_base(&ntype, "ShaderNodeValue"_ustr, SH_NODE_VALUE);
72 ntype.ui_name = "Value";
73 ntype.ui_description = "Input numerical values to other nodes in the tree";
74 ntype.enum_name_legacy = "VALUE";
76 ntype.declare = file_ns::sh_node_value_declare;
77 ntype.gpu_fn = file_ns::gpu_shader_value;
78 ntype.build_multi_function = file_ns::sh_node_value_build_multi_function;
79 ntype.materialx_fn = file_ns::node_shader_materialx;
80
82}
83
84} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_VALUE
#define UI_ITEM_NONE
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
bool value_node_has_gizmo(const bNodeTree &tree, const bNode &node)
static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *, GPUNodeStack *out)
static void sh_node_value_declare(NodeDeclarationBuilder &b)
static void sh_node_value_build_multi_function(NodeMultiFunctionBuilder &builder)
BMesh Iterators.
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void register_node_type_sh_value()
void common_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
ListBaseT< bNodeSocket > outputs
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:382
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void alignment_set(LayoutAlign alignment)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & row(bool align)