Blender V4.3
node_shader_uvmap.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#include "node_util.hh"
7
8#include "BKE_context.hh"
9
11
13
14#include "RNA_access.hh"
15
16#include "UI_interface.hh"
17#include "UI_resources.hh"
18
20
22{
23 b.add_output<decl::Vector>("UV");
24}
25
27{
28 uiItemR(layout, ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
29
30 if (!RNA_boolean_get(ptr, "from_instancer")) {
31 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
32
33 if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
34 PointerRNA eval_obptr;
35
37
38 if (depsgraph) {
39 DEG_get_evaluated_rna_pointer(depsgraph, &obptr, &eval_obptr);
40 PointerRNA dataptr = RNA_pointer_get(&eval_obptr, "data");
41 uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_GROUP_UVS);
42 return;
43 }
44 }
45
46 uiItemR(layout, ptr, "uv_map", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_GROUP_UVS);
47 }
48}
49
50static void node_shader_init_uvmap(bNodeTree * /*ntree*/, bNode *node)
51{
52 NodeShaderUVMap *attr = MEM_cnew<NodeShaderUVMap>("NodeShaderUVMap");
53 node->storage = attr;
54}
55
57 bNode *node,
58 bNodeExecData * /*execdata*/,
59 GPUNodeStack *in,
60 GPUNodeStack *out)
61{
62 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node->storage);
63
64 /* NOTE: using CD_AUTO_FROM_NAME instead of CD_MTFACE as geometry nodes may overwrite data which
65 * will also change the eCustomDataType. This will also make EEVEE and Cycles consistent. See
66 * #93179. */
68
69 GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
70
71 node_shader_gpu_bump_tex_coord(mat, node, &out[0].link);
72
73 return 1;
74}
75
77#ifdef WITH_MATERIALX
78{
79 /* NODE: "From Instances" not implemented */
80 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node_->storage);
81 NodeItem res = texcoord_node(NodeItem::Type::Vector2, attr->uv_map);
82 return res;
83}
84#endif
86
87} // namespace blender::nodes::node_shader_uvmap_cc
88
89/* node type definition */
91{
92 namespace file_ns = blender::nodes::node_shader_uvmap_cc;
93
94 static blender::bke::bNodeType ntype;
95
97 ntype.declare = file_ns::node_declare;
98 ntype.draw_buttons = file_ns::node_shader_buts_uvmap;
100 ntype.initfunc = file_ns::node_shader_init_uvmap;
102 &ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage);
103 ntype.gpu_fn = file_ns::node_shader_gpu_uvmap;
104 ntype.materialx_fn = file_ns::node_shader_materialx;
105
107}
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
#define SH_NODE_UVMAP
Definition BKE_node.hh:970
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
void DEG_get_evaluated_rna_pointer(const Depsgraph *depsgraph, PointerRNA *ptr, PointerRNA *r_ptr_eval)
@ CD_AUTO_FROM_NAME
@ OB_MESH
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
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
const Depsgraph * depsgraph
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
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 void node_shader_init_uvmap(bNodeTree *, bNode *node)
static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
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 register_node_type_sh_uvmap()
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
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void * data
Definition RNA_types.hh:42
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