Blender  V2.93
node_shader_mixRgb.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 /* **************** MIX RGB ******************** */
28  {SOCK_FLOAT, N_("Fac"), 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
29  {SOCK_RGBA, N_("Color1"), 0.5f, 0.5f, 0.5f, 1.0f},
30  {SOCK_RGBA, N_("Color2"), 0.5f, 0.5f, 0.5f, 1.0f},
31  {-1, ""},
32 };
34  {SOCK_RGBA, N_("Color")},
35  {-1, ""},
36 };
37 
39  int UNUSED(thread),
40  bNode *node,
41  bNodeExecData *UNUSED(execdata),
42  bNodeStack **in,
43  bNodeStack **out)
44 {
45  /* stack order in: fac, col1, col2 */
46  /* stack order out: col */
47  float col[3];
48  float fac;
49  float vec[3];
50 
51  nodestack_get_vec(&fac, SOCK_FLOAT, in[0]);
52  CLAMP(fac, 0.0f, 1.0f);
53 
55  nodestack_get_vec(vec, SOCK_VECTOR, in[2]);
56 
57  ramp_blend(node->custom1, col, fac, vec);
58  if (node->custom2 & SHD_MIXRGB_CLAMP) {
59  CLAMP3(col, 0.0f, 1.0f);
60  }
61  copy_v3_v3(out[0]->vec, col);
62 }
63 
65  bNode *node,
66  bNodeExecData *UNUSED(execdata),
67  GPUNodeStack *in,
68  GPUNodeStack *out)
69 {
70  static const char *names[] = {
71  "mix_blend",
72  "mix_add",
73  "mix_mult",
74  "mix_sub",
75  "mix_screen",
76  "mix_div",
77  "mix_diff",
78  "mix_dark",
79  "mix_light",
80  "mix_overlay",
81  "mix_dodge",
82  "mix_burn",
83  "mix_hue",
84  "mix_sat",
85  "mix_val",
86  "mix_color",
87  "mix_soft",
88  "mix_linear",
89  };
90 
91  if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) {
92  int ret = GPU_stack_link(mat, node, names[node->custom1], in, out);
93  if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
94  const float min[3] = {0.0f, 0.0f, 0.0f};
95  const float max[3] = {1.0f, 1.0f, 1.0f};
96  GPU_link(
97  mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link);
98  }
99  return ret;
100  }
101 
102  return 0;
103 }
104 
106 {
107  static bNodeType ntype;
108 
114 
115  nodeRegisterType(&ntype);
116 }
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
Definition: material.c:1395
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 node_type_label(struct bNodeType *ntype, void(*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen))
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ARRAY_SIZE(arr)
#define UNUSED(x)
#define CLAMP3(vec, b, c)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
#define SHD_MIXRGB_CLAMP
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
Group RGB to Bright Vector Camera CLAMP
Group SH_NODE_MIX_RGB
@ PROP_FACTOR
Definition: RNA_types.h:131
OperationNode * node
uint col
static char ** names
Definition: makesdna.c:162
static void node_shader_exec_mix_rgb(void *UNUSED(data), int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void register_node_type_sh_mix_rgb(void)
static bNodeSocketTemplate sh_node_mix_rgb_in[]
static bNodeSocketTemplate sh_node_mix_rgb_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)
void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
Definition: node_util.c:189
return ret
#define min(a, b)
Definition: sort.c:51
Compact definition of a node socket.
Definition: BKE_node.h:95
Defines a node type.
Definition: BKE_node.h:221
float max