Blender V5.0
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
5#include "node_shader_util.hh"
6#include "node_util.hh"
7
8#include "BKE_context.hh"
9
11
12#include "RNA_access.hh"
13
15#include "UI_resources.hh"
16
18
20{
21 b.add_output<decl::Vector>("Tangent");
22}
23
25{
26 layout->prop(ptr, "direction_type", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
27
28 if (RNA_enum_get(ptr, "direction_type") == SHD_TANGENT_UVMAP) {
29 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
30 Object *object = static_cast<Object *>(obptr.data);
31
32 if (object && object->type == OB_MESH) {
34
35 if (depsgraph) {
36 Object *object_eval = DEG_get_evaluated(depsgraph, object);
37 PointerRNA dataptr = RNA_id_pointer_create(static_cast<ID *>(object_eval->data));
38 layout->prop_search(ptr, "uv_map", &dataptr, "uv_layers", "", ICON_GROUP_UVS);
39 return;
40 }
41 }
42
43 layout->prop(ptr, "uv_map", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_GROUP_UVS);
44 }
45 else {
46 layout->prop(
47 ptr, "axis", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
48 }
49}
50
51static void node_shader_init_tangent(bNodeTree * /*ntree*/, bNode *node)
52{
53 NodeShaderTangent *attr = MEM_callocN<NodeShaderTangent>("NodeShaderTangent");
55 node->storage = attr;
56}
57
59 bNode *node,
60 bNodeExecData * /*execdata*/,
63{
64 NodeShaderTangent *attr = static_cast<NodeShaderTangent *>(node->storage);
65
66 if (attr->direction_type == SHD_TANGENT_UVMAP) {
67 return GPU_stack_link(
68 mat, node, "node_tangentmap", in, out, GPU_attribute(mat, CD_TANGENT, attr->uv_map));
69 }
70
71 GPUNodeLink *orco = GPU_attribute(mat, CD_ORCO, "");
72
73 if (attr->axis == SHD_TANGENT_AXIS_X) {
74 GPU_link(mat, "tangent_orco_x", orco, &orco);
75 }
76 else if (attr->axis == SHD_TANGENT_AXIS_Y) {
77 GPU_link(mat, "tangent_orco_y", orco, &orco);
78 }
79 else {
80 GPU_link(mat, "tangent_orco_z", orco, &orco);
81 }
82
83 return GPU_stack_link(mat, node, "node_tangent", in, out, orco);
84}
85
87#ifdef WITH_MATERIALX
88{
89 /* TODO: implement other features */
90 return create_node("tangent", NodeItem::Type::Vector3, {{"space", val(std::string("world"))}});
91}
92#endif
94
95} // namespace blender::nodes::node_shader_tangent_cc
96
97/* node type definition */
99{
100 namespace file_ns = blender::nodes::node_shader_tangent_cc;
101
102 static blender::bke::bNodeType ntype;
103
104 sh_node_type_base(&ntype, "ShaderNodeTangent", SH_NODE_TANGENT);
105 ntype.ui_name = "Tangent";
106 ntype.ui_description = "Generate a tangent direction for the Anisotropic BSDF";
107 ntype.enum_name_legacy = "TANGENT";
108 ntype.nclass = NODE_CLASS_INPUT;
109 ntype.declare = file_ns::node_declare;
110 ntype.draw_buttons = file_ns::node_shader_buts_tangent;
112 ntype.initfunc = file_ns::node_shader_init_tangent;
113 ntype.gpu_fn = file_ns::node_shader_gpu_tangent;
115 ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage);
116 ntype.materialx_fn = file_ns::node_shader_materialx;
117
119}
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_TANGENT
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ SHD_TANGENT_UVMAP
@ SHD_TANGENT_AXIS_Y
@ SHD_TANGENT_AXIS_X
@ SHD_TANGENT_AXIS_Z
@ 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)
bool GPU_link(GPUMaterial *mat, const char *name,...)
#define C
Definition RandGen.cpp:29
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
BPy_StructRNA * depsgraph
#define in
#define out
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void node_shader_buts_tangent(uiLayout *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)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_tangent()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
Definition DNA_ID.h:414
void * data
Definition RNA_types.hh:53
void * storage
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< blender::StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238