Blender V5.0
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
20
22{
23 b.add_output<decl::Float>("Value").custom_draw([](CustomSocketDrawParams &params) {
24 params.layout.alignment_set(ui::LayoutAlign::Expand);
25 uiLayout &row = params.layout.row(true);
26 row.prop(&params.socket_ptr, "default_value", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
28 row.prop(&params.socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
29 }
30 });
31}
32
34 bNode *node,
35 bNodeExecData * /*execdata*/,
36 GPUNodeStack * /*in*/,
38{
39 const bNodeSocket *socket = static_cast<bNodeSocket *>(node->outputs.first);
40 float value = static_cast<bNodeSocketValueFloat *>(socket->default_value)->value;
41 return GPU_link(mat, "set_value", GPU_uniform(&value), &out->link);
42}
43
45{
46 const bNodeSocket *bsocket = (bNodeSocket *)builder.node().outputs.first;
47 const bNodeSocketValueFloat *value = (const bNodeSocketValueFloat *)bsocket->default_value;
48 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float>>(value->value);
49}
50
52#ifdef WITH_MATERIALX
53{
54 NodeItem value = get_output_default("Value", NodeItem::Type::Float);
55 return create_node("constant", NodeItem::Type::Float, {{"value", value}});
56}
57#endif
59
60} // namespace blender::nodes::node_shader_value_cc
61
63{
64 namespace file_ns = blender::nodes::node_shader_value_cc;
65
66 static blender::bke::bNodeType ntype;
67
68 common_node_type_base(&ntype, "ShaderNodeValue", SH_NODE_VALUE);
69 ntype.ui_name = "Value";
70 ntype.ui_description = "Input numerical values to other nodes in the tree";
71 ntype.enum_name_legacy = "VALUE";
73 ntype.declare = file_ns::sh_node_value_declare;
74 ntype.gpu_fn = file_ns::gpu_shader_value;
75 ntype.build_multi_function = file_ns::sh_node_value_build_multi_function;
76 ntype.materialx_fn = file_ns::node_shader_materialx;
77
79}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_VALUE
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_uniform(const float *num)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define UI_ITEM_NONE
#define out
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void common_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_value()
void * first
void * default_value
ListBase outputs
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)