Blender V5.0
node_shader_attribute.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
5#include "node_shader_util.hh"
6
7#include "node_util.hh"
8
10#include "UI_resources.hh"
11
12#include "RNA_access.hh"
13
15
17{
18 b.add_output<decl::Color>("Color");
19 b.add_output<decl::Vector>("Vector");
20 b.add_output<decl::Float>("Factor", "Fac");
21 b.add_output<decl::Float>("Alpha");
22}
23
25{
26 layout->prop(ptr, "attribute_type", UI_ITEM_NONE, "", ICON_NONE);
27 layout->prop(ptr,
28 RNA_struct_find_property(ptr, "attribute_name"),
29 -1,
30 0,
32 "",
33 ICON_NONE,
34 IFACE_("Name"));
35}
36
37static void node_shader_init_attribute(bNodeTree * /*ntree*/, bNode *node)
38{
39 NodeShaderAttribute *attr = MEM_callocN<NodeShaderAttribute>("NodeShaderAttribute");
40 node->storage = attr;
41}
42
44 bNode *node,
45 bNodeExecData * /*execdata*/,
48{
49 NodeShaderAttribute *attr = static_cast<NodeShaderAttribute *>(node->storage);
50 bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY;
51 float attr_hash = 0.0f;
52
53 GPUNodeLink *cd_attr;
54
55 if (is_varying) {
56 cd_attr = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->name);
57
58 if (STREQ(attr->name, "color")) {
59 GPU_link(mat, "node_attribute_color", cd_attr, &cd_attr);
60 }
61 else if (STREQ(attr->name, "temperature")) {
62 GPU_link(mat, "node_attribute_temperature", cd_attr, &cd_attr);
63 }
64 }
65 else if (attr->type == SHD_ATTRIBUTE_VIEW_LAYER) {
66 cd_attr = GPU_layer_attribute(mat, attr->name);
67 }
68 else {
69 cd_attr = GPU_uniform_attribute(mat,
70 attr->name,
72 reinterpret_cast<uint32_t *>(&attr_hash));
73
74 GPU_link(mat, "node_attribute_uniform", cd_attr, GPU_constant(&attr_hash), &cd_attr);
75 }
76
77 GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
78
79 if (is_varying) {
80 int i;
81 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
82 node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
83 }
84 }
85
86 return 1;
87}
88
90#ifdef WITH_MATERIALX
91{
92 /* TODO: some outputs expected be implemented within the next iteration
93 * (see node-definition `<geompropvalue>`). */
94 return get_output_default(socket_out_->identifier, NodeItem::Type::Any);
95}
96#endif
98
99} // namespace blender::nodes::node_shader_attribute_cc
100
101/* node type definition */
103{
105
106 static blender::bke::bNodeType ntype;
107
108 sh_node_type_base(&ntype, "ShaderNodeAttribute", SH_NODE_ATTRIBUTE);
109 ntype.ui_name = "Attribute";
110 ntype.ui_description = "Retrieve attributes attached to objects or geometry";
111 ntype.enum_name_legacy = "ATTRIBUTE";
112 ntype.nclass = NODE_CLASS_INPUT;
113 ntype.declare = file_ns::node_declare;
114 ntype.draw_buttons = file_ns::node_shader_buts_attribute;
115 ntype.initfunc = file_ns::node_shader_init_attribute;
117 ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage);
118 ntype.gpu_fn = file_ns::node_shader_gpu_attribute;
119 ntype.materialx_fn = file_ns::node_shader_materialx;
120
122}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_ATTRIBUTE
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
#define STREQ(a, b)
#define IFACE_(msgid)
@ CD_AUTO_FROM_NAME
@ SHD_ATTRIBUTE_VIEW_LAYER
@ SHD_ATTRIBUTE_GEOMETRY
@ SHD_ATTRIBUTE_INSTANCER
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_layer_attribute(GPUMaterial *mat, const char *name)
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli, uint32_t *r_hash)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
bool GPU_link(GPUMaterial *mat, const char *name,...)
#define UI_ITEM_NONE
#define in
#define out
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5414
static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_attribute(bNodeTree *, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_attribute(uiLayout *layout, bContext *, PointerRNA *ptr)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_attribute()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void * storage
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
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
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)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238