Blender V5.0
node_shader_mapping.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
12#include "UI_resources.hh"
13
15
17{
18 b.add_input<decl::Vector>("Vector")
19 .default_value({0.0f, 0.0f, 0.0f})
20 .min(-FLT_MAX)
21 .max(FLT_MAX)
22 .description("The vector to be transformed");
23 b.add_input<decl::Vector>("Location")
24 .default_value({0.0f, 0.0f, 0.0f})
25 .min(-FLT_MAX)
26 .max(FLT_MAX)
28 .description("The amount of translation along each axis");
29 b.add_input<decl::Vector>("Rotation")
30 .default_value({0.0f, 0.0f, 0.0f})
31 .min(-FLT_MAX)
32 .max(FLT_MAX)
34 .description("The amount of rotation along each axis, XYZ order");
35 b.add_input<decl::Vector>("Scale")
36 .default_value({1.0f, 1.0f, 1.0f})
37 .min(-FLT_MAX)
38 .max(FLT_MAX)
40 .description("The amount of scaling along each axis");
41 b.add_output<decl::Vector>("Vector");
42}
43
45{
46 layout->prop(ptr, "vector_type", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
47}
48
49static const char *gpu_shader_get_name(int mode)
50{
51 switch (mode) {
53 return "mapping_point";
55 return "mapping_texture";
57 return "mapping_vector";
59 return "mapping_normal";
60 }
61 return nullptr;
62}
63
65 bNode *node,
66 bNodeExecData * /*execdata*/,
69{
70 if (gpu_shader_get_name(node->custom1)) {
71 return GPU_stack_link(mat, node, gpu_shader_get_name(node->custom1), in, out);
72 }
73
74 return 0;
75}
76
83
85#ifdef WITH_MATERIALX
86{
87 NodeItem vector = get_input_value("Vector", NodeItem::Type::Vector3);
88 NodeItem scale = get_input_value("Scale", NodeItem::Type::Vector3);
89 NodeItem rotation = get_input_value("Rotation", NodeItem::Type::Vector3) *
90 val(float(180.0f / M_PI));
91
92 int type = node_->custom1;
93 switch (type) {
95 NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
96 return (vector * scale).rotate(rotation) + location;
97 }
99 NodeItem location = get_input_value("Location", NodeItem::Type::Vector3);
100 return (vector - location).rotate(rotation, true) / scale;
101 }
103 return (vector * scale).rotate(rotation * val(MaterialX::Vector3(1.0f, 1.0f, -1.0f)));
104 }
106 return (vector / scale).rotate(rotation).normalize();
107 }
108 default:
110 }
111 return empty();
112}
113#endif
115
116} // namespace blender::nodes::node_shader_mapping_cc
117
119{
120 namespace file_ns = blender::nodes::node_shader_mapping_cc;
121
122 static blender::bke::bNodeType ntype;
123
124 sh_node_type_base(&ntype, "ShaderNodeMapping", SH_NODE_MAPPING);
125 ntype.ui_name = "Mapping";
126 ntype.ui_description = "Transform the input vector by applying translation, rotation, and scale";
127 ntype.enum_name_legacy = "MAPPING";
129 ntype.declare = file_ns::node_declare;
130 ntype.draw_buttons = file_ns::node_shader_buts_mapping;
131 ntype.gpu_fn = file_ns::gpu_shader_mapping;
132 ntype.updatefunc = file_ns::node_shader_update_mapping;
133 ntype.materialx_fn = file_ns::node_shader_materialx;
134
136}
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:450
#define SH_NODE_MAPPING
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define M_PI
#define ELEM(...)
@ SOCK_IN
@ NODE_MAPPING_TYPE_POINT
@ NODE_MAPPING_TYPE_VECTOR
@ NODE_MAPPING_TYPE_TEXTURE
@ NODE_MAPPING_TYPE_NORMAL
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_XYZ
Definition RNA_types.hh:269
@ PROP_EULER
Definition RNA_types.hh:266
@ PROP_TRANSLATION
Definition RNA_types.hh:261
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
Definition node.cc:2532
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
Definition node.cc:4739
static const char * gpu_shader_get_name(int mode)
static void node_shader_buts_mapping(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_shader_update_mapping(bNodeTree *ntree, bNode *node)
static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_mapping()
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
#define FLT_MAX
Definition stdcycles.h:14
int16_t custom1
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
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(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:281
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