Blender V4.5
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
16#include "UI_interface.hh"
17#include "UI_resources.hh"
18
20
22{
23 b.add_output<decl::Float>("Value").custom_draw([](CustomSocketDrawParams &params) {
24 uiLayout &row = params.layout.row(true);
25 row.prop(&params.socket_ptr, "default_value", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
27 row.prop(&params.socket_ptr, "pin_gizmo", UI_ITEM_NONE, "", ICON_GIZMO);
28 }
29 });
30}
31
33 bNode *node,
34 bNodeExecData * /*execdata*/,
35 GPUNodeStack * /*in*/,
37{
38 const bNodeSocket *socket = static_cast<bNodeSocket *>(node->outputs.first);
39 float value = static_cast<bNodeSocketValueFloat *>(socket->default_value)->value;
40 return GPU_link(mat, "set_value", GPU_uniform(&value), &out->link);
41}
42
44{
45 const bNodeSocket *bsocket = (bNodeSocket *)builder.node().outputs.first;
46 const bNodeSocketValueFloat *value = (const bNodeSocketValueFloat *)bsocket->default_value;
47 builder.construct_and_set_matching_fn<mf::CustomMF_Constant<float>>(value->value);
48}
49
51#ifdef WITH_MATERIALX
52{
53 NodeItem value = get_output_default("Value", NodeItem::Type::Float);
54 return create_node("constant", NodeItem::Type::Float, {{"value", value}});
55}
56#endif
58
59} // namespace blender::nodes::node_shader_value_cc
60
62{
63 namespace file_ns = blender::nodes::node_shader_value_cc;
64
65 static blender::bke::bNodeType ntype;
66
67 common_node_type_base(&ntype, "ShaderNodeValue", SH_NODE_VALUE);
68 ntype.ui_name = "Value";
69 ntype.ui_description = "Input numerical values to other nodes in the tree";
70 ntype.enum_name_legacy = "VALUE";
72 ntype.declare = file_ns::sh_node_value_declare;
73 ntype.gpu_fn = file_ns::gpu_shader_value;
74 ntype.build_multi_function = file_ns::sh_node_value_build_multi_function;
75 ntype.materialx_fn = file_ns::node_shader_materialx;
76
78}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#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:2748
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:226
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:332
std::string ui_description
Definition BKE_node.hh:232
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
NodeDeclareFunction declare
Definition BKE_node.hh:355
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)