Blender  V2.93
node_shader_squeeze.c
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 /* **************** VALUE SQUEEZE ******************** */
28  {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
29  {SOCK_FLOAT, N_("Width"), 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
30  {SOCK_FLOAT, N_("Center"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE},
31  {-1, ""}};
32 
33 static bNodeSocketTemplate sh_node_squeeze_out[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}};
34 
36  int UNUSED(thread),
37  bNode *UNUSED(node),
38  bNodeExecData *UNUSED(execdata),
39  bNodeStack **in,
40  bNodeStack **out)
41 {
42  float vec[3];
43 
44  nodestack_get_vec(vec, SOCK_FLOAT, in[0]);
45  nodestack_get_vec(vec + 1, SOCK_FLOAT, in[1]);
46  nodestack_get_vec(vec + 2, SOCK_FLOAT, in[2]);
47 
48  out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1])));
49 }
50 
52  bNode *node,
53  bNodeExecData *UNUSED(execdata),
54  GPUNodeStack *in,
55  GPUNodeStack *out)
56 {
57  return GPU_stack_link(mat, node, "squeeze", in, out);
58 }
59 
61 {
62  static bNodeType ntype;
63 
64  sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTOR, 0);
66  node_type_storage(&ntype, "", NULL, NULL);
69 
70  nodeRegisterType(&ntype);
71 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
#define SH_NODE_SQUEEZE
Definition: BKE_node.h:987
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define M_E
Definition: BLI_math_base.h:62
#define UNUSED(x)
#define N_(msgid)
@ SOCK_FLOAT
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_NONE
Definition: RNA_types.h:113
OperationNode * node
#define powf(x, y)
static int gpu_shader_squeeze(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
static bNodeSocketTemplate sh_node_squeeze_in[]
void register_node_type_sh_squeeze(void)
static bNodeSocketTemplate sh_node_squeeze_out[]
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
Compact definition of a node socket.
Definition: BKE_node.h:95
float vec[4]
Defines a node type.
Definition: BKE_node.h:221