Blender  V2.93
node_shader_sepcombRGB.cc
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) 2006 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 /* **************** SEPARATE RGBA ******************** */
28  {SOCK_RGBA, N_("Image"), 0.8f, 0.8f, 0.8f, 1.0f},
29  {-1, ""},
30 };
32  {SOCK_FLOAT, N_("R")},
33  {SOCK_FLOAT, N_("G")},
34  {SOCK_FLOAT, N_("B")},
35  {-1, ""},
36 };
37 
38 static void node_shader_exec_seprgb(void *UNUSED(data),
39  int UNUSED(thread),
40  bNode *UNUSED(node),
41  bNodeExecData *UNUSED(execdata),
42  bNodeStack **in,
43  bNodeStack **out)
44 {
45  float col[3];
47 
48  out[0]->vec[0] = col[0];
49  out[1]->vec[0] = col[1];
50  out[2]->vec[0] = col[2];
51 }
52 
54  bNode *node,
55  bNodeExecData *UNUSED(execdata),
56  GPUNodeStack *in,
57  GPUNodeStack *out)
58 {
59  return GPU_stack_link(mat, node, "separate_rgb", in, out);
60 }
61 
63  public:
65  {
67  this->set_signature(&signature);
68  }
69 
71  {
73  signature.single_input<blender::Color4f>("Color");
74  signature.single_output<float>("R");
75  signature.single_output<float>("G");
76  signature.single_output<float>("B");
77  return signature.build();
78  }
79 
82  blender::fn::MFContext UNUSED(context)) const override
83  {
84  const blender::VArray<blender::Color4f> &colors =
85  params.readonly_single_input<blender::Color4f>(0, "Color");
86  blender::MutableSpan<float> rs = params.uninitialized_single_output<float>(1, "R");
87  blender::MutableSpan<float> gs = params.uninitialized_single_output<float>(2, "G");
88  blender::MutableSpan<float> bs = params.uninitialized_single_output<float>(3, "B");
89 
90  for (int64_t i : mask) {
91  blender::Color4f color = colors[i];
92  rs[i] = color.r;
93  gs[i] = color.g;
94  bs[i] = color.b;
95  }
96  }
97 };
98 
100 {
101  static SeparateRGBFunction fn;
102  builder.set_matching_fn(fn);
103 }
104 
106 {
107  static bNodeType ntype;
108 
109  sh_fn_node_type_base(&ntype, SH_NODE_SEPRGB, "Separate RGB", NODE_CLASS_CONVERTOR, 0);
111  node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_seprgb);
114 
115  nodeRegisterType(&ntype);
116 }
117 
118 /* **************** COMBINE RGB ******************** */
120  {SOCK_FLOAT, N_("R"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
121  {SOCK_FLOAT, N_("G"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
122  {SOCK_FLOAT, N_("B"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
123  {-1, ""},
124 };
126  {SOCK_RGBA, N_("Image")},
127  {-1, ""},
128 };
129 
131  int UNUSED(thread),
132  bNode *UNUSED(node),
133  bNodeExecData *UNUSED(execdata),
134  bNodeStack **in,
135  bNodeStack **out)
136 {
137  float r, g, b;
138  nodestack_get_vec(&r, SOCK_FLOAT, in[0]);
139  nodestack_get_vec(&g, SOCK_FLOAT, in[1]);
140  nodestack_get_vec(&b, SOCK_FLOAT, in[2]);
141 
142  out[0]->vec[0] = r;
143  out[0]->vec[1] = g;
144  out[0]->vec[2] = b;
145 }
146 
148  bNode *node,
149  bNodeExecData *UNUSED(execdata),
150  GPUNodeStack *in,
151  GPUNodeStack *out)
152 {
153  return GPU_stack_link(mat, node, "combine_rgb", in, out);
154 }
155 
157 {
159  "Combine RGB", [](float r, float g, float b) { return blender::Color4f(r, g, b, 1.0f); }};
160  builder.set_matching_fn(fn);
161 }
162 
164 {
165  static bNodeType ntype;
166 
167  sh_fn_node_type_base(&ntype, SH_NODE_COMBRGB, "Combine RGB", NODE_CLASS_CONVERTOR, 0);
169  node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_combrgb);
172 
173  nodeRegisterType(&ntype);
174 }
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_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 SH_NODE_SEPRGB
Definition: BKE_node.h:990
#define UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_RGBA
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
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_COMBRGB
@ PROP_UNSIGNED
Definition: RNA_types.h:129
void call(blender::IndexMask mask, blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override
static blender::fn::MFSignature create_signature()
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
void set_matching_fn(const fn::MultiFunction &function)
OperationNode * node
uint col
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void register_node_type_sh_combrgb(void)
static bNodeSocketTemplate sh_node_seprgb_in[]
static bNodeSocketTemplate sh_node_seprgb_out[]
static bNodeSocketTemplate sh_node_combrgb_in[]
static void sh_node_combrgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
static bNodeSocketTemplate sh_node_combrgb_out[]
static int gpu_shader_combrgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void register_node_type_sh_seprgb(void)
static void sh_node_seprgb_expand_in_mf_network(blender::nodes::NodeMFNetworkBuilder &builder)
static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
struct SELECTID_Context context
Definition: select_engine.c:47
__int64 int64_t
Definition: stdint.h:92
Compact definition of a node socket.
Definition: BKE_node.h:95
float vec[4]
Defines a node type.
Definition: BKE_node.h:221
NodeExpandInMFNetworkFunction expand_in_mf_network
Definition: BKE_node.h:324
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)