Blender  V3.3
node_fn_separate_color.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include "node_function_util.hh"
4 
5 #include "UI_interface.h"
6 #include "UI_resources.h"
7 
8 namespace blender::nodes {
9 
11 
13 {
14  b.is_function_node();
15  b.add_input<decl::Color>(N_("Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
16  b.add_output<decl::Float>(N_("Red"));
17  b.add_output<decl::Float>(N_("Green"));
18  b.add_output<decl::Float>(N_("Blue"));
19  b.add_output<decl::Float>(N_("Alpha"));
20 };
21 
23 {
24  uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
25 }
26 
28 {
29  const NodeCombSepColor &storage = node_storage(*node);
31 }
32 
34 {
35  NodeCombSepColor *data = MEM_cnew<NodeCombSepColor>(__func__);
37  node->storage = data;
38 }
39 
41  public:
43  {
45  this->set_signature(&signature);
46  }
47 
49  {
50  fn::MFSignatureBuilder signature{"Separate Color"};
51  signature.single_input<ColorGeometry4f>("Color");
52  signature.single_output<float>("Red");
53  signature.single_output<float>("Green");
54  signature.single_output<float>("Blue");
55  signature.single_output<float>("Alpha");
56  return signature.build();
57  }
58 
60  {
61  const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
62  "Color");
63 
64  MutableSpan<float> red = params.uninitialized_single_output_if_required<float>(1, "Red");
65  MutableSpan<float> green = params.uninitialized_single_output_if_required<float>(2, "Green");
66  MutableSpan<float> blue = params.uninitialized_single_output_if_required<float>(3, "Blue");
67  MutableSpan<float> alpha = params.uninitialized_single_output_if_required<float>(4, "Alpha");
68 
69  std::array<MutableSpan<float>, 4> outputs = {red, green, blue, alpha};
70  Vector<int> used_outputs;
71  if (!red.is_empty()) {
72  used_outputs.append(0);
73  }
74  if (!green.is_empty()) {
75  used_outputs.append(1);
76  }
77  if (!blue.is_empty()) {
78  used_outputs.append(2);
79  }
80  if (!alpha.is_empty()) {
81  used_outputs.append(3);
82  }
83 
84  devirtualize_varray(colors, [&](auto colors) {
85  mask.to_best_mask_type([&](auto mask) {
86  const int used_outputs_num = used_outputs.size();
87  const int *used_outputs_data = used_outputs.data();
88 
89  for (const int64_t i : mask) {
90  const ColorGeometry4f &color = colors[i];
91  for (const int out_i : IndexRange(used_outputs_num)) {
92  const int channel = used_outputs_data[out_i];
93  outputs[channel][i] = color[channel];
94  }
95  }
96  });
97  });
98  }
99 };
100 
102  public:
104  {
106  this->set_signature(&signature);
107  }
108 
110  {
111  fn::MFSignatureBuilder signature{"Separate Color"};
112  signature.single_input<ColorGeometry4f>("Color");
113  signature.single_output<float>("Hue");
114  signature.single_output<float>("Saturation");
115  signature.single_output<float>("Value");
116  signature.single_output<float>("Alpha");
117  return signature.build();
118  }
119 
121  {
122  const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
123  "Color");
124  MutableSpan<float> hue = params.uninitialized_single_output<float>(1, "Hue");
125  MutableSpan<float> saturation = params.uninitialized_single_output<float>(2, "Saturation");
126  MutableSpan<float> value = params.uninitialized_single_output<float>(3, "Value");
127  MutableSpan<float> alpha = params.uninitialized_single_output_if_required<float>(4, "Alpha");
128 
129  for (int64_t i : mask) {
130  rgb_to_hsv(colors[i].r, colors[i].g, colors[i].b, &hue[i], &saturation[i], &value[i]);
131  }
132 
133  if (!alpha.is_empty()) {
134  for (int64_t i : mask) {
135  alpha[i] = colors[i].a;
136  }
137  }
138  }
139 };
140 
142  public:
144  {
146  this->set_signature(&signature);
147  }
148 
150  {
151  fn::MFSignatureBuilder signature{"Separate Color"};
152  signature.single_input<ColorGeometry4f>("Color");
153  signature.single_output<float>("Hue");
154  signature.single_output<float>("Saturation");
155  signature.single_output<float>("Lightness");
156  signature.single_output<float>("Alpha");
157  return signature.build();
158  }
159 
161  {
162  const VArray<ColorGeometry4f> &colors = params.readonly_single_input<ColorGeometry4f>(0,
163  "Color");
164  MutableSpan<float> hue = params.uninitialized_single_output<float>(1, "Hue");
165  MutableSpan<float> saturation = params.uninitialized_single_output<float>(2, "Saturation");
166  MutableSpan<float> lightness = params.uninitialized_single_output<float>(3, "Lightness");
167  MutableSpan<float> alpha = params.uninitialized_single_output_if_required<float>(4, "Alpha");
168 
169  for (int64_t i : mask) {
170  rgb_to_hsl(colors[i].r, colors[i].g, colors[i].b, &hue[i], &saturation[i], &lightness[i]);
171  }
172 
173  if (!alpha.is_empty()) {
174  for (int64_t i : mask) {
175  alpha[i] = colors[i].a;
176  }
177  }
178  }
179 };
180 
182 {
183  const NodeCombSepColor &storage = node_storage(builder.node());
184 
185  switch (storage.mode) {
186  case NODE_COMBSEP_COLOR_RGB: {
187  static SeparateRGBAFunction fn;
188  builder.set_matching_fn(fn);
189  break;
190  }
191  case NODE_COMBSEP_COLOR_HSV: {
192  static SeparateHSVAFunction fn;
193  builder.set_matching_fn(fn);
194  break;
195  }
196  case NODE_COMBSEP_COLOR_HSL: {
197  static SeparateHSLAFunction fn;
198  builder.set_matching_fn(fn);
199  break;
200  }
201  default: {
203  break;
204  }
205  }
206 }
207 
208 } // namespace blender::nodes
209 
211 {
212  static bNodeType ntype;
213 
219  &ntype, "NodeCombSepColor", node_free_standard_storage, node_copy_standard_storage);
222 
223  nodeRegisterType(&ntype);
224 }
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
#define NODE_STORAGE_FUNCS(StorageT)
Definition: BKE_node.h:1563
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
#define FN_NODE_SEPARATE_COLOR
Definition: BKE_node.h:1536
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l)
Definition: math_color.c:237
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
Definition: math_color.c:208
#define UNUSED(x)
NodeCombSepColorMode
@ NODE_COMBSEP_COLOR_RGB
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_HSL
_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
_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 blue
_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 green
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its hue
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its red
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its saturation
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
int64_t size() const
Definition: BLI_vector.hh:694
void append(const T &value)
Definition: BLI_vector.hh:433
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
void set_matching_fn(const MultiFunction *fn)
void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static void fn_node_separate_color_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void fn_node_separate_color_init(bNodeTree *UNUSED(tree), bNode *node)
static void fn_node_separate_color_declare(NodeDeclarationBuilder &b)
static void fn_node_separate_color_build_multi_function(NodeMultiFunctionBuilder &builder)
static void fn_node_separate_color_update(bNodeTree *UNUSED(ntree), bNode *node)
void devirtualize_varray(const VArray< T > &varray, const Func &func, bool enable=true)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
void register_node_type_fn_separate_color(void)
void fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
static bNodeSocketTemplate outputs[]
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:55
void node_free_standard_storage(bNode *node)
Definition: node_util.c:43
void node_combsep_color_label(const ListBase *sockets, NodeCombSepColorMode mode)
Definition: node_util.c:229
__int64 int64_t
Definition: stdint.h:89
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480