Blender V5.3
node_shader_tangent.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
8
9#include "node_shader_util.hh"
10#include "node_util.hh"
11
12#include "BKE_context.hh"
13
15
16#include "ED_node.hh"
17
18#include "RNA_access.hh"
19
21#include "UI_resources.hh"
22
23namespace blender {
24
26
28{
29 b.add_output<decl::Vector>("Tangent"_ustr);
30}
31
33{
34 layout.prop(ptr, "direction_type", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35
36 if (RNA_enum_get(ptr, "direction_type") == SHD_TANGENT_UVMAP) {
38
39 if (object && object->type == OB_MESH) {
40 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
41
42 if (depsgraph) {
43 Object *object_eval = DEG_get_evaluated(depsgraph, object);
44 PointerRNA dataptr = RNA_id_pointer_create(object_eval->data);
45 layout.prop_search(ptr, "uv_map", &dataptr, "uv_layers", "", ICON_GROUP_UVS);
46 return;
47 }
48 }
49
50 layout.prop(ptr, "uv_map", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_GROUP_UVS);
51 }
52 else {
53 layout.prop(
54 ptr, "axis", ui::ITEM_R_SPLIT_EMPTY_NAME | ui::ITEM_R_EXPAND, std::nullopt, ICON_NONE);
55 }
56}
57
58static void node_shader_init_tangent(bNodeTree * /*ntree*/, bNode *node)
59{
60 NodeShaderTangent *attr = MEM_new<NodeShaderTangent>("NodeShaderTangent");
62 node->storage = attr;
63}
64
66 bNode *node,
67 bNodeExecData * /*execdata*/,
70{
71 NodeShaderTangent *attr = static_cast<NodeShaderTangent *>(node->storage);
72
73 if (attr->direction_type == SHD_TANGENT_UVMAP) {
74 return GPU_stack_link(
75 mat, node, "node_tangentmap", in, out, GPU_attribute(mat, CD_TANGENT, attr->uv_map));
76 }
77
78 GPUNodeLink *orco = GPU_attribute(mat, CD_ORCO, "");
79
80 if (attr->axis == SHD_TANGENT_AXIS_X) {
81 GPU_link(mat, "tangent_orco_x", orco, &orco);
82 }
83 else if (attr->axis == SHD_TANGENT_AXIS_Y) {
84 GPU_link(mat, "tangent_orco_y", orco, &orco);
85 }
86 else {
87 GPU_link(mat, "tangent_orco_z", orco, &orco);
88 }
89
90 return GPU_stack_link(
91 mat, node, "node_tangent", in, out, orco, GPU_kernel_globals(), GPU_shading_data());
92}
93
95#ifdef WITH_MATERIALX
96{
97 /* TODO: implement other features */
98 return create_node("tangent", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
99}
100#endif
102
103} // namespace nodes::node_shader_tangent_cc
104
105/* node type definition */
107{
108 namespace file_ns = nodes::node_shader_tangent_cc;
109
110 static bke::bNodeType ntype;
111
112 sh_node_type_base(&ntype, "ShaderNodeTangent"_ustr, SH_NODE_TANGENT);
113 ntype.ui_name = "Tangent";
114 ntype.ui_description = "Generate a tangent direction for the Anisotropic BSDF";
115 ntype.enum_name_legacy = "TANGENT";
116 ntype.nclass = NODE_CLASS_INPUT;
117 ntype.declare = file_ns::node_declare;
118 ntype.draw_buttons = file_ns::node_shader_buts_tangent;
120 ntype.initfunc = file_ns::node_shader_init_tangent;
121 ntype.gpu_fn = file_ns::node_shader_gpu_tangent;
123 ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage);
124 ntype.materialx_fn = file_ns::node_shader_materialx;
125
127}
128
129} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_TANGENT
#define C
Definition RandGen.cpp:29
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
Object * get_space_editor_object(const bContext *C)
static void node_shader_buts_tangent(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_tangent(bNodeTree *, bNode *node)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_tangent()
bool GPU_link(GPUMaterial *mat, const char *name,...)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
GPUNodeLink * GPU_shading_data()
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
GPUNodeLink * GPU_kernel_globals()
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)