Blender  V2.93
node_shader_invert.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 /* **************** INVERT ******************** */
28  {SOCK_FLOAT, N_("Fac"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
29  {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
30  {-1, ""}};
31 
32 static bNodeSocketTemplate sh_node_invert_out[] = {{SOCK_RGBA, N_("Color")}, {-1, ""}};
33 
34 static void node_shader_exec_invert(void *UNUSED(data),
35  int UNUSED(thread),
36  bNode *UNUSED(node),
37  bNodeExecData *UNUSED(execdata),
38  bNodeStack **in,
39  bNodeStack **out)
40 {
41  float col[3], icol[3], fac;
42 
43  nodestack_get_vec(&fac, SOCK_FLOAT, in[0]);
45 
46  icol[0] = 1.0f - col[0];
47  icol[1] = 1.0f - col[1];
48  icol[2] = 1.0f - col[2];
49 
50  /* if fac, blend result against original input */
51  if (fac < 1.0f) {
52  interp_v3_v3v3(out[0]->vec, col, icol, fac);
53  }
54  else {
55  copy_v3_v3(out[0]->vec, icol);
56  }
57 }
58 
60  bNode *node,
61  bNodeExecData *UNUSED(execdata),
62  GPUNodeStack *in,
63  GPUNodeStack *out)
64 {
65  return GPU_stack_link(mat, node, "invert", in, out);
66 }
67 
69 {
70  static bNodeType ntype;
71 
76 
77  nodeRegisterType(&ntype);
78 }
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_COLOR
Definition: BKE_node.h:336
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
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], const float t)
Definition: math_vector.c:49
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera Vector SH_NODE_INVERT
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
uint col
static int gpu_shader_invert(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_invert_out[]
static bNodeSocketTemplate sh_node_invert_in[]
static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
void register_node_type_sh_invert(void)
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
Defines a node type.
Definition: BKE_node.h:221