Blender  V3.3
node_texture_valToNor.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "NOD_texture.h"
9 #include "node_texture_util.h"
10 
12  {SOCK_FLOAT, N_("Val"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
13  {SOCK_FLOAT, N_("Nabla"), 0.025f, 0.0f, 0.0f, 0.0f, 0.001f, 0.1f, PROP_UNSIGNED},
14  {-1, ""},
15 };
16 
18  {SOCK_VECTOR, N_("Normal")},
19  {-1, ""},
20 };
21 
22 static void normalfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
23 {
24  float new_co[3];
25  const float *co = p->co;
26 
27  float nabla = tex_input_value(in[1], p, thread);
28  float val;
29  float nor[3];
30 
31  TexParams np = *p;
32  np.co = new_co;
33 
34  val = tex_input_value(in[0], p, thread);
35 
36  new_co[0] = co[0] + nabla;
37  new_co[1] = co[1];
38  new_co[2] = co[2];
39  nor[0] = tex_input_value(in[0], &np, thread);
40 
41  new_co[0] = co[0];
42  new_co[1] = co[1] + nabla;
43  nor[1] = tex_input_value(in[0], &np, thread);
44 
45  new_co[1] = co[1];
46  new_co[2] = co[2] + nabla;
47  nor[2] = tex_input_value(in[0], &np, thread);
48 
49  out[0] = val - nor[0];
50  out[1] = val - nor[1];
51  out[2] = val - nor[2];
52 }
53 static void exec(void *data,
54  int UNUSED(thread),
55  bNode *node,
56  bNodeExecData *execdata,
57  bNodeStack **in,
58  bNodeStack **out)
59 {
60  tex_output(node, execdata, in, out[0], &normalfn, data);
61 }
62 
64 {
65  static bNodeType ntype;
66 
67  tex_node_type_base(&ntype, TEX_NODE_VALTONOR, "Value to Normal", NODE_CLASS_CONVERTER);
69  node_type_exec(&ntype, NULL, NULL, exec);
70 
71  nodeRegisterType(&ntype);
72 }
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4358
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
#define TEX_NODE_VALTONOR
Definition: BKE_node.h:1367
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ PROP_NONE
Definition: RNA_types.h:126
@ PROP_UNSIGNED
Definition: RNA_types.h:142
Definition: thread.h:34
OperationNode * node
uint nor
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
float tex_input_value(bNodeStack *in, TexParams *params, short thread)
void tex_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
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:84
Defines a node type.
Definition: BKE_node.h:226
#define N_(msgid)