Blender  V3.3
node_shader_attribute.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
4 #include "node_shader_util.hh"
5 
6 #include "UI_interface.h"
7 #include "UI_resources.h"
8 
10 
12 {
13  b.add_output<decl::Color>(N_("Color"));
14  b.add_output<decl::Vector>(N_("Vector"));
15  b.add_output<decl::Float>(N_("Fac"));
16  b.add_output<decl::Float>(N_("Alpha"));
17 }
18 
20 {
21  uiItemR(layout, ptr, "attribute_type", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Type"), ICON_NONE);
22  uiItemR(layout, ptr, "attribute_name", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Name"), ICON_NONE);
23 }
24 
26 {
27  NodeShaderAttribute *attr = MEM_cnew<NodeShaderAttribute>("NodeShaderAttribute");
28  node->storage = attr;
29 }
30 
32  bNode *node,
33  bNodeExecData *UNUSED(execdata),
34  GPUNodeStack *in,
36 {
37  NodeShaderAttribute *attr = static_cast<NodeShaderAttribute *>(node->storage);
38  bool is_varying = attr->type == SHD_ATTRIBUTE_GEOMETRY;
39 
40  GPUNodeLink *cd_attr;
41 
42  if (is_varying) {
43  cd_attr = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->name);
44  }
45  else {
46  cd_attr = GPU_uniform_attribute(mat, attr->name, attr->type == SHD_ATTRIBUTE_INSTANCER);
47  }
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  GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
57 
58  int i;
59  LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &node->outputs, i) {
60  node_shader_gpu_bump_tex_coord(mat, node, &out[i].link);
61  }
62 
63  return 1;
64 }
65 
66 } // namespace blender::nodes::node_shader_attribute_cc
67 
68 /* node type definition */
70 {
71  namespace file_ns = blender::nodes::node_shader_attribute_cc;
72 
73  static bNodeType ntype;
74 
80  &ntype, "NodeShaderAttribute", node_free_standard_storage, node_copy_standard_storage);
82 
83  nodeRegisterType(&ntype);
84 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define SH_NODE_ATTRIBUTE
Definition: BKE_node.h:1106
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition: BLI_listbase.h:344
#define UNUSED(x)
#define STREQ(a, b)
#define IFACE_(msgid)
@ CD_AUTO_FROM_NAME
@ SHD_ATTRIBUTE_GEOMETRY
@ SHD_ATTRIBUTE_INSTANCER
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_uniform_attribute(GPUMaterial *mat, const char *name, bool use_dupli)
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
bNodeTree * ntree
static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node)
static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_attribute()
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeLink **link)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480