Blender V4.3
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
9#include "node_shader_util.hh"
10
11#include "UI_interface.hh"
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 uiItemR(layout, ptr, "vector_type", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 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*/,
67 GPUNodeStack *in,
68 GPUNodeStack *out)
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
77static void node_shader_update_mapping(bNodeTree *ntree, bNode *node)
78{
79 bNodeSocket *sock = bke::node_find_socket(node, SOCK_IN, "Location");
81 ntree, sock, ELEM(node->custom1, NODE_MAPPING_TYPE_POINT, NODE_MAPPING_TYPE_TEXTURE));
82}
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
125 ntype.declare = file_ns::node_declare;
126 ntype.draw_buttons = file_ns::node_shader_buts_mapping;
127 ntype.gpu_fn = file_ns::gpu_shader_mapping;
128 ntype.updatefunc = file_ns::node_shader_update_mapping;
129 ntype.materialx_fn = file_ns::node_shader_materialx;
130
132}
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:407
#define SH_NODE_MAPPING
Definition BKE_node.hh:900
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#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:172
@ PROP_EULER
Definition RNA_types.hh:169
@ PROP_TRANSLATION
Definition RNA_types.hh:164
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
void node_set_socket_availability(bNodeTree *ntree, bNodeSocket *sock, bool is_available)
Definition node.cc:3911
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
bNodeSocket * node_find_socket(bNode *node, eNodeSocketInOut in_out, StringRef identifier)
Definition node.cc:1829
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, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
#define FLT_MAX
Definition stdcycles.h:14
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
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
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
PointerRNA * ptr
Definition wm_files.cc:4126