Blender  V2.93
node_shader_normal.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 /* **************** NORMAL ******************** */
28  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
29  {-1, ""},
30 };
31 
33  {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 1.0f, PROP_DIRECTION},
34  {SOCK_FLOAT, N_("Dot")},
35  {-1, ""},
36 };
37 
38 /* generates normal, does dot product */
39 static void node_shader_exec_normal(void *UNUSED(data),
40  int UNUSED(thread),
41  bNode *UNUSED(node),
42  bNodeExecData *UNUSED(execdata),
43  bNodeStack **in,
44  bNodeStack **out)
45 {
46  float vec[3];
47 
48  /* stack order input: normal */
49  /* stack order output: normal, value */
50 
51  nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
52 
53  /* render normals point inside... the widget points outside */
54  out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec);
55 }
56 
58  bNode *node,
59  bNodeExecData *UNUSED(execdata),
60  GPUNodeStack *in,
61  GPUNodeStack *out)
62 {
63  GPUNodeLink *vec = GPU_uniform(out[0].vec);
64  return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec);
65 }
66 
68 {
69  static bNodeType ntype;
70 
75 
76  nodeRegisterType(&ntype);
77 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4645
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:337
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
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
#define UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to SH_NODE_NORMAL
@ PROP_DIRECTION
Definition: RNA_types.h:141
OperationNode * node
static bNodeSocketTemplate sh_node_normal_out[]
static bNodeSocketTemplate sh_node_normal_in[]
static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
void register_node_type_sh_normal(void)
static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *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