Blender  V2.93
node_texture_valToNor.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 "NOD_texture.h"
25 #include "node_texture_util.h"
26 
28  {SOCK_FLOAT, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
29  {SOCK_FLOAT, N_("Nabla"), 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f, PROP_UNSIGNED},
30  {-1, ""},
31 };
32 
34  {SOCK_VECTOR, N_("Normal")},
35  {-1, ""},
36 };
37 
38 static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
39 {
40  float new_co[3];
41  const float *co = p->co;
42 
43  float nabla = tex_input_value(in[1], p, thread);
44  float val;
45  float nor[3];
46 
47  TexParams np = *p;
48  np.co = new_co;
49 
50  val = tex_input_value(in[0], p, thread);
51 
52  new_co[0] = co[0] + nabla;
53  new_co[1] = co[1];
54  new_co[2] = co[2];
55  nor[0] = tex_input_value(in[0], &np, thread);
56 
57  new_co[0] = co[0];
58  new_co[1] = co[1] + nabla;
59  nor[1] = tex_input_value(in[0], &np, thread);
60 
61  new_co[1] = co[1];
62  new_co[2] = co[2] + nabla;
63  nor[2] = tex_input_value(in[0], &np, thread);
64 
65  out[0] = val - nor[0];
66  out[1] = val - nor[1];
67  out[2] = val - nor[2];
68 }
69 static void exec(void *data,
70  int UNUSED(thread),
71  bNode *node,
72  bNodeExecData *execdata,
73  bNodeStack **in,
74  bNodeStack **out)
75 {
76  tex_output(node, execdata, in, out[0], &normalfn, data);
77 }
78 
80 {
81  static bNodeType ntype;
82 
83  tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTOR, 0);
85  node_type_exec(&ntype, NULL, NULL, exec);
86 
87  nodeRegisterType(&ntype);
88 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define TEX_NODE_VALTONOR
Definition: BKE_node.h:1345
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
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 UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ PROP_NONE
Definition: RNA_types.h:113
@ PROP_UNSIGNED
Definition: RNA_types.h:129
OperationNode * node
uint nor
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_output(bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack *out, TexFn texfn, TexCallData *cdata)
void register_node_type_tex_valtonor(void)
static bNodeSocketTemplate outputs[]
static bNodeSocketTemplate inputs[]
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
const float * co
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221