Blender  V3.3
node_shader_uvmap.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 "BKE_context.h"
7 
8 #include "DNA_customdata_types.h"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
14 
16 {
17  b.add_output<decl::Vector>(N_("UV"));
18 }
19 
21 {
22  uiItemR(layout, ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
23 
24  if (!RNA_boolean_get(ptr, "from_instancer")) {
25  PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
26 
27  if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
28  PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
29  uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE);
30  }
31  }
32 }
33 
35 {
36  NodeShaderUVMap *attr = MEM_cnew<NodeShaderUVMap>("NodeShaderUVMap");
37  node->storage = attr;
38 }
39 
41  bNode *node,
42  bNodeExecData *UNUSED(execdata),
43  GPUNodeStack *in,
45 {
46  NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node->storage);
47 
48  /* NOTE: using CD_AUTO_FROM_NAME instead of CD_MTFACE as geometry nodes may overwrite data which
49  * will also change the eCustomDataType. This will also make EEVEE and Cycles consistent. See
50  * T93179. */
51  GPUNodeLink *mtface = GPU_attribute(mat, CD_AUTO_FROM_NAME, attr->uv_map);
52 
53  GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
54 
55  node_shader_gpu_bump_tex_coord(mat, node, &out[0].link);
56 
57  return 1;
58 }
59 
60 } // namespace blender::nodes::node_shader_uvmap_cc
61 
62 /* node type definition */
64 {
65  namespace file_ns = blender::nodes::node_shader_uvmap_cc;
66 
67  static bNodeType ntype;
68 
75  &ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage);
77 
78  nodeRegisterType(&ntype);
79 }
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Definition: context.c:462
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define SH_NODE_UVMAP
Definition: BKE_node.h:1158
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
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
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:366
#define UNUSED(x)
@ CD_AUTO_FROM_NAME
@ OB_MESH
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define C
Definition: RandGen.cpp:25
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
OperationNode * node
bNodeTree * ntree
static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_uvmap(bNodeTree *UNUSED(ntree), bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
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 register_node_type_sh_uvmap()
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
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5167
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
void * data
Definition: RNA_types.h:38
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