Blender  V2.93
node_shader_vector_rotate.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "../node_shader_util.h"
25 
26 /* **************** Vector Rotate ******************** */
28  {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
29  {SOCK_VECTOR, N_("Center"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_NONE},
30  {SOCK_VECTOR, N_("Axis"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_NONE, PROP_NONE},
31  {SOCK_FLOAT, N_("Angle"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_ANGLE, PROP_NONE},
32  {SOCK_VECTOR, N_("Rotation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_EULER},
33  {-1, ""}};
34 
36  {SOCK_VECTOR, N_("Vector")},
37  {-1, ""},
38 };
39 
40 static const char *gpu_shader_get_name(int mode)
41 {
42  switch (mode) {
44  return "node_vector_rotate_axis_angle";
46  return "node_vector_rotate_axis_x";
48  return "node_vector_rotate_axis_y";
50  return "node_vector_rotate_axis_z";
52  return "node_vector_rotate_euler_xyz";
53  }
54 
55  return nullptr;
56 }
57 
59  bNode *node,
60  bNodeExecData *UNUSED(execdata),
61  GPUNodeStack *in,
62  GPUNodeStack *out)
63 {
64  const char *name = gpu_shader_get_name(node->custom1);
65 
66  if (name != nullptr) {
67  float invert = (node->custom2) ? -1.0 : 1.0;
68  return GPU_stack_link(mat, node, name, in, out, GPU_constant(&invert));
69  }
70 
71  return 0;
72 }
73 
74 using blender::float3;
75 
77  const float3 center,
78  const float3 axis,
79  const float angle)
80 {
82  float mat[3][3];
83  axis_angle_to_mat3(mat, axis, angle);
84  mul_m3_v3(mat, result);
85  return result + center;
86 }
87 
89  const float3 center,
90  const float3 rotation,
91  const bool invert)
92 {
93  float mat[3][3];
95  eul_to_mat3(mat, rotation);
96  if (invert) {
97  invert_m3(mat);
98  }
99  mul_m3_v3(mat, result);
100  return result + center;
101 }
102 
105 {
106  bool invert = builder.bnode().custom2;
107  const int mode = builder.bnode().custom1;
108 
109  switch (mode) {
111  if (invert) {
113  "Rotate Axis", [](float3 in, float3 center, float3 axis, float angle) {
114  return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
115  }};
116  return fn;
117  }
119  "Rotate Axis", [](float3 in, float3 center, float3 axis, float angle) {
121  }};
122  return fn;
123  }
125  float3 axis = float3(1.0f, 0.0f, 0.0f);
126  if (invert) {
128  "Rotate X-Axis", [=](float3 in, float3 center, float angle) {
129  return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
130  }};
131  return fn;
132  }
134  "Rotate X-Axis", [=](float3 in, float3 center, float angle) {
136  }};
137  return fn;
138  }
140  float3 axis = float3(0.0f, 1.0f, 0.0f);
141  if (invert) {
143  "Rotate Y-Axis", [=](float3 in, float3 center, float angle) {
144  return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
145  }};
146  return fn;
147  }
149  "Rotate Y-Axis", [=](float3 in, float3 center, float angle) {
151  }};
152  return fn;
153  }
155  float3 axis = float3(0.0f, 0.0f, 1.0f);
156  if (invert) {
158  "Rotate Z-Axis", [=](float3 in, float3 center, float angle) {
159  return sh_node_vector_rotate_around_axis(in, center, axis, -angle);
160  }};
161  return fn;
162  }
164  "Rotate Z-Axis", [=](float3 in, float3 center, float angle) {
166  }};
167  return fn;
168  }
170  if (invert) {
172  "Rotate Euler", [](float3 in, float3 center, float3 rotation) {
173  return sh_node_vector_rotate_euler(in, center, rotation, true);
174  }};
175  return fn;
176  }
178  "Rotate Euler", [](float3 in, float3 center, float3 rotation) {
179  return sh_node_vector_rotate_euler(in, center, rotation, false);
180  }};
181  return fn;
182  }
183  default:
185  return builder.get_not_implemented_fn();
186  }
187 }
188 
191 {
192  const blender::fn::MultiFunction &fn = get_multi_function(builder);
193  builder.set_matching_fn(fn);
194 }
195 
197 {
198  bNodeSocket *sock_rotation = nodeFindSocket(node, SOCK_IN, "Rotation");
200  bNodeSocket *sock_axis = nodeFindSocket(node, SOCK_IN, "Axis");
202  bNodeSocket *sock_angle = nodeFindSocket(node, SOCK_IN, "Angle");
204 }
205 
207 {
208  static bNodeType ntype;
209 
215 
216  nodeRegisterType(&ntype);
217 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3726
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
#define SH_NODE_VECTOR_ROTATE
Definition: BKE_node.h:1073
struct bNodeSocket * nodeFindSocket(const struct bNode *node, eNodeSocketInOut in_out, const char *identifier)
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:337
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define BLI_assert_unreachable()
Definition: BLI_assert.h:96
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1152
void eul_to_mat3(float mat[3][3], const float eul[3])
void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle)
#define UNUSED(x)
#define ELEM(...)
#define N_(msgid)
@ NODE_VECTOR_ROTATE_TYPE_AXIS
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ NODE_VECTOR_ROTATE_TYPE_EULER_XYZ
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Y
@ SOCK_IN
@ SOCK_HIDE_VALUE
@ SOCK_VECTOR
@ SOCK_FLOAT
NSNotificationCenter * center
GPUNodeLink * GPU_constant(const float *num)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_ANGLE
Definition: RNA_types.h:132
@ PROP_EULER
Definition: RNA_types.h:145
@ PROP_NONE
Definition: RNA_types.h:113
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
void set_matching_fn(const fn::MultiFunction &function)
OperationNode * node
bNodeTree * ntree
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
void register_node_type_sh_vector_rotate(void)
static const char * gpu_shader_get_name(int mode)
static void node_shader_update_vector_rotate(bNodeTree *UNUSED(ntree), bNode *node)
static float3 sh_node_vector_rotate_euler(const float3 vector, const float3 center, const float3 rotation, const bool invert)
static bNodeSocketTemplate sh_node_vector_rotate_in[]
static void sh_node_vector_rotate_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
static bNodeSocketTemplate sh_node_vector_rotate_out[]
static int gpu_shader_vector_rotate(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static float3 sh_node_vector_rotate_around_axis(const float3 vector, const float3 center, const float3 axis, const float angle)
static const blender::fn::MultiFunction & get_multi_function(blender::nodes::NodeMFNetworkBuilder &builder)
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
NodeExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:324
short custom1
short custom2
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19