Blender  V2.93
node_shader_vector_math.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) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 #include "NOD_math_functions.hh"
27 
28 /* **************** VECTOR MATH ******************** */
30  {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
31  {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
32  {SOCK_VECTOR, N_("Vector"), 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
33  {SOCK_FLOAT, N_("Scale"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
34  {-1, ""}};
35 
37  {SOCK_VECTOR, N_("Vector")}, {SOCK_FLOAT, N_("Value")}, {-1, ""}};
38 
39 static const char *gpu_shader_get_name(int mode)
40 {
41  switch (mode) {
43  return "vector_math_add";
45  return "vector_math_subtract";
47  return "vector_math_multiply";
49  return "vector_math_divide";
50 
52  return "vector_math_cross";
54  return "vector_math_project";
56  return "vector_math_reflect";
58  return "vector_math_dot";
59 
61  return "vector_math_distance";
63  return "vector_math_length";
65  return "vector_math_scale";
67  return "vector_math_normalize";
68 
70  return "vector_math_snap";
72  return "vector_math_floor";
74  return "vector_math_ceil";
76  return "vector_math_modulo";
78  return "vector_math_fraction";
80  return "vector_math_absolute";
82  return "vector_math_minimum";
84  return "vector_math_maximum";
86  return "vector_math_wrap";
88  return "vector_math_sine";
90  return "vector_math_cosine";
92  return "vector_math_tangent";
94  return "vector_math_refract";
96  return "vector_math_faceforward";
97  }
98 
99  return nullptr;
100 }
101 
103  bNode *node,
104  bNodeExecData *UNUSED(execdata),
105  GPUNodeStack *in,
106  GPUNodeStack *out)
107 {
108  const char *name = gpu_shader_get_name(node->custom1);
109  if (name != nullptr) {
110  return GPU_stack_link(mat, node, name, in, out);
111  }
112 
113  return 0;
114 }
115 
117 {
118  bNodeSocket *sockB = (bNodeSocket *)BLI_findlink(&node->inputs, 1);
119  bNodeSocket *sockC = (bNodeSocket *)BLI_findlink(&node->inputs, 2);
120  bNodeSocket *sockScale = nodeFindSocket(node, SOCK_IN, "Scale");
121 
122  bNodeSocket *sockVector = nodeFindSocket(node, SOCK_OUT, "Vector");
123  bNodeSocket *sockValue = nodeFindSocket(node, SOCK_OUT, "Value");
124 
126  !ELEM(node->custom1,
139  nodeSetSocketAvailability(sockScale,
141  nodeSetSocketAvailability(sockVector,
142  !ELEM(node->custom1,
146  nodeSetSocketAvailability(sockValue,
147  ELEM(node->custom1,
151 
152  /* Labels */
153  node_sock_label_clear(sockB);
154  node_sock_label_clear(sockC);
155  node_sock_label_clear(sockScale);
156  switch (node->custom1) {
158  node_sock_label(sockB, "Incident");
159  node_sock_label(sockC, "Reference");
160  break;
162  node_sock_label(sockB, "Max");
163  node_sock_label(sockC, "Min");
164  break;
166  node_sock_label(sockB, "Increment");
167  break;
169  node_sock_label(sockScale, "Ior");
170  break;
172  node_sock_label(sockScale, "Scale");
173  break;
174  }
175 }
176 
179 {
180  using blender::float3;
181 
183 
184  const blender::fn::MultiFunction *multi_fn = nullptr;
185 
187  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
189  function};
190  multi_fn = &fn;
191  });
192  if (multi_fn != nullptr) {
193  return *multi_fn;
194  }
195 
197  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
199  info.title_case_name, function};
200  multi_fn = &fn;
201  });
202  if (multi_fn != nullptr) {
203  return *multi_fn;
204  }
205 
207  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
209  info.title_case_name, function};
210  multi_fn = &fn;
211  });
212  if (multi_fn != nullptr) {
213  return *multi_fn;
214  }
215 
217  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
219  function};
220  multi_fn = &fn;
221  });
222  if (multi_fn != nullptr) {
223  return *multi_fn;
224  }
225 
227  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
229  function};
230  multi_fn = &fn;
231  });
232  if (multi_fn != nullptr) {
233  return *multi_fn;
234  }
235 
237  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
239  multi_fn = &fn;
240  });
241  if (multi_fn != nullptr) {
242  return *multi_fn;
243  }
244 
246  operation, [&](auto function, const blender::nodes::FloatMathOperationInfo &info) {
248  multi_fn = &fn;
249  });
250  if (multi_fn != nullptr) {
251  return *multi_fn;
252  }
253 
254  return builder.get_not_implemented_fn();
255 }
256 
258 {
259  const blender::fn::MultiFunction &fn = get_multi_function(builder);
260  builder.set_matching_fn(fn);
261 }
262 
264 {
265  static bNodeType ntype;
266 
273 
274  nodeRegisterType(&ntype);
275 }
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
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
void node_type_label(struct bNodeType *ntype, void(*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen))
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
#define ELEM(...)
#define N_(msgid)
NodeVectorMathOperation
@ NODE_VECTOR_MATH_NORMALIZE
@ NODE_VECTOR_MATH_LENGTH
@ NODE_VECTOR_MATH_CROSS_PRODUCT
@ NODE_VECTOR_MATH_CEIL
@ NODE_VECTOR_MATH_MODULO
@ NODE_VECTOR_MATH_ADD
@ NODE_VECTOR_MATH_COSINE
@ NODE_VECTOR_MATH_REFLECT
@ NODE_VECTOR_MATH_WRAP
@ NODE_VECTOR_MATH_REFRACT
@ NODE_VECTOR_MATH_DOT_PRODUCT
@ NODE_VECTOR_MATH_ABSOLUTE
@ NODE_VECTOR_MATH_DIVIDE
@ NODE_VECTOR_MATH_TANGENT
@ NODE_VECTOR_MATH_DISTANCE
@ NODE_VECTOR_MATH_FLOOR
@ NODE_VECTOR_MATH_SNAP
@ NODE_VECTOR_MATH_SINE
@ NODE_VECTOR_MATH_FRACTION
@ NODE_VECTOR_MATH_PROJECT
@ NODE_VECTOR_MATH_MULTIPLY
@ NODE_VECTOR_MATH_SCALE
@ NODE_VECTOR_MATH_MAXIMUM
@ NODE_VECTOR_MATH_FACEFORWARD
@ NODE_VECTOR_MATH_SUBTRACT
@ NODE_VECTOR_MATH_MINIMUM
@ SOCK_OUT
@ SOCK_IN
@ SOCK_VECTOR
@ SOCK_FLOAT
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera SH_NODE_VECTOR_MATH
@ PROP_NONE
Definition: RNA_types.h:113
void set_matching_fn(const fn::MultiFunction &function)
OperationNode * node
bNodeTree * ntree
bool try_dispatch_float_math_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_to_fl(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_fl_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
bool try_dispatch_float_math_fl3_fl3_fl3_to_fl3(const NodeVectorMathOperation operation, Callback &&callback)
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
static const char * gpu_shader_get_name(int mode)
static int gpu_shader_vector_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_update_vector_math(bNodeTree *UNUSED(ntree), bNode *node)
static void sh_node_vector_math_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
static bNodeSocketTemplate sh_node_vector_math_out[]
void register_node_type_sh_vect_math(void)
static const blender::fn::MultiFunction & get_multi_function(blender::nodes::NodeMFNetworkBuilder &builder)
static bNodeSocketTemplate sh_node_vector_math_in[]
void node_sock_label_clear(bNodeSocket *sock)
Definition: node_util.c:93
void node_sock_label(bNodeSocket *sock, const char *name)
Definition: node_util.c:88
void node_vector_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
Definition: node_util.c:216
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