Blender  V3.3
node_shader_tangent.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 "UI_interface.h"
9 #include "UI_resources.h"
10 
12 
14 {
15  b.add_output<decl::Vector>(N_("Tangent"));
16 }
17 
19 {
20  uiLayout *split, *row;
21 
22  split = uiLayoutSplit(layout, 0.0f, false);
23 
24  uiItemR(split, ptr, "direction_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", 0);
25 
26  row = uiLayoutRow(split, false);
27 
28  if (RNA_enum_get(ptr, "direction_type") == SHD_TANGENT_UVMAP) {
29  PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
30 
31  if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
32  PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
33  uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE);
34  }
35  else {
36  uiItemR(row, ptr, "uv_map", UI_ITEM_R_SPLIT_EMPTY_NAME, "", 0);
37  }
38  }
39  else {
40  uiItemR(row, ptr, "axis", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, nullptr, 0);
41  }
42 }
43 
45 {
46  NodeShaderTangent *attr = MEM_cnew<NodeShaderTangent>("NodeShaderTangent");
47  attr->axis = SHD_TANGENT_AXIS_Z;
48  node->storage = attr;
49 }
50 
52  bNode *node,
53  bNodeExecData *UNUSED(execdata),
54  GPUNodeStack *in,
56 {
57  NodeShaderTangent *attr = static_cast<NodeShaderTangent *>(node->storage);
58 
59  if (attr->direction_type == SHD_TANGENT_UVMAP) {
60  return GPU_stack_link(
61  mat, node, "node_tangentmap", in, out, GPU_attribute(mat, CD_TANGENT, attr->uv_map));
62  }
63 
64  GPUNodeLink *orco = GPU_attribute(mat, CD_ORCO, "");
65 
66  if (attr->axis == SHD_TANGENT_AXIS_X) {
67  GPU_link(mat, "tangent_orco_x", orco, &orco);
68  }
69  else if (attr->axis == SHD_TANGENT_AXIS_Y) {
70  GPU_link(mat, "tangent_orco_y", orco, &orco);
71  }
72  else {
73  GPU_link(mat, "tangent_orco_z", orco, &orco);
74  }
75 
76  return GPU_stack_link(mat, node, "node_tangent", in, out, orco);
77 }
78 
79 } // namespace blender::nodes::node_shader_tangent_cc
80 
81 /* node type definition */
83 {
84  namespace file_ns = blender::nodes::node_shader_tangent_cc;
85 
86  static bNodeType ntype;
87 
95  &ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage);
96 
97  nodeRegisterType(&ntype);
98 }
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
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
#define SH_NODE_TANGENT
Definition: BKE_node.h:1145
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_TANGENT
#define SHD_TANGENT_AXIS_Z
#define SHD_TANGENT_AXIS_X
#define SHD_TANGENT_UVMAP
#define SHD_TANGENT_AXIS_Y
@ OB_MESH
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
bool GPU_link(GPUMaterial *mat, 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
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
uiLayout * uiLayoutSplit(uiLayout *layout, float percentage, bool align)
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
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition: abc_util.cc:92
static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_tangent(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node)
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_tangent()
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
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5167
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