Blender V4.3
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
9#include "UI_interface.hh"
10#include "UI_resources.hh"
11
13
15{
16 b.add_output<decl::Color>("Color");
17 b.add_output<decl::Vector>("Vector");
18 b.add_output<decl::Float>("Fac");
19 b.add_output<decl::Float>("Alpha");
20}
21
23{
24 uiItemR(layout, ptr, "attribute_type", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Type"), ICON_NONE);
25 uiItemR(layout, ptr, "attribute_name", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Name"), ICON_NONE);
26}
27
28static void node_shader_init_attribute(bNodeTree * /*ntree*/, bNode *node)
29{
30 NodeShaderAttribute *attr = MEM_cnew<NodeShaderAttribute>("NodeShaderAttribute");
31 node->storage = attr;
32}
33
35 bNode *node,
36 bNodeExecData * /*execdata*/,
37 GPUNodeStack *in,
38 GPUNodeStack *out)
39{
40 NodeShaderAttribute *attr = static_cast<NodeShaderAttribute *>(node->storage);
41 bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY;
42 float attr_hash = 0.0f;
43
44 GPUNodeLink *cd_attr;
45
46 if (is_varying) {
47 cd_attr = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->name);
48
49 if (STREQ(attr->name, "color")) {
50 GPU_link(mat, "node_attribute_color", cd_attr, &cd_attr);
51 }
52 else if (STREQ(attr->name, "temperature")) {
53 GPU_link(mat, "node_attribute_temperature", cd_attr, &cd_attr);
54 }
55 }
56 else if (attr->type == SHD_ATTRIBUTE_VIEW_LAYER) {
57 cd_attr = GPU_layer_attribute(mat, attr->name);
58 }
59 else {
60 cd_attr = GPU_uniform_attribute(mat,
61 attr->name,
63 reinterpret_cast<uint32_t *>(&attr_hash));
64
65 GPU_link(mat, "node_attribute_uniform", cd_attr, GPU_constant(&attr_hash), &cd_attr);
66 }
67
68 GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
69
70 if (is_varying) {
71 int i;
72 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
73 node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
74 }
75 }
76
77 return 1;
78}
79
81#ifdef WITH_MATERIALX
82{
83 /* TODO: some outputs expected be implemented within the next iteration
84 * (see node-definition `<geompropvalue>`). */
85 return get_output_default(socket_out_->name, NodeItem::Type::Any);
86}
87#endif
89
90} // namespace blender::nodes::node_shader_attribute_cc
91
92/* node type definition */
94{
96
97 static blender::bke::bNodeType ntype;
98
99 sh_node_type_base(&ntype, SH_NODE_ATTRIBUTE, "Attribute", NODE_CLASS_INPUT);
100 ntype.declare = file_ns::node_declare;
101 ntype.draw_buttons = file_ns::node_shader_buts_attribute;
102 ntype.initfunc = file_ns::node_shader_init_attribute;
104 &ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage);
105 ntype.gpu_fn = file_ns::node_shader_gpu_attribute;
106 ntype.materialx_fn = file_ns::node_shader_materialx;
107
109}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#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,...)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
local_group_size(16, 16) .push_constant(Type b
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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, int type, const char *name, short nclass)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
unsigned int uint32_t
Definition stdint.h:80
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126