Blender  V3.3
node_shader_mix_rgb.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "node_shader_util.hh"
9 
11 
13 {
14  b.is_function_node();
15  b.add_input<decl::Float>(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
16  b.add_input<decl::Color>(N_("Color1")).default_value({0.5f, 0.5f, 0.5f, 1.0f});
17  b.add_input<decl::Color>(N_("Color2")).default_value({0.5f, 0.5f, 0.5f, 1.0f});
18  b.add_output<decl::Color>(N_("Color"));
19 }
20 
21 static const char *gpu_shader_get_name(int mode)
22 {
23  switch (mode) {
24  case MA_RAMP_BLEND:
25  return "mix_blend";
26  case MA_RAMP_ADD:
27  return "mix_add";
28  case MA_RAMP_MULT:
29  return "mix_mult";
30  case MA_RAMP_SUB:
31  return "mix_sub";
32  case MA_RAMP_SCREEN:
33  return "mix_screen";
34  case MA_RAMP_DIV:
35  return "mix_div";
36  case MA_RAMP_DIFF:
37  return "mix_diff";
38  case MA_RAMP_DARK:
39  return "mix_dark";
40  case MA_RAMP_LIGHT:
41  return "mix_light";
42  case MA_RAMP_OVERLAY:
43  return "mix_overlay";
44  case MA_RAMP_DODGE:
45  return "mix_dodge";
46  case MA_RAMP_BURN:
47  return "mix_burn";
48  case MA_RAMP_HUE:
49  return "mix_hue";
50  case MA_RAMP_SAT:
51  return "mix_sat";
52  case MA_RAMP_VAL:
53  return "mix_val";
54  case MA_RAMP_COLOR:
55  return "mix_color";
56  case MA_RAMP_SOFT:
57  return "mix_soft";
58  case MA_RAMP_LINEAR:
59  return "mix_linear";
60  }
61 
62  return nullptr;
63 }
64 
66  bNode *node,
67  bNodeExecData *UNUSED(execdata),
68  GPUNodeStack *in,
70 {
71  const char *name = gpu_shader_get_name(node->custom1);
72 
73  if (name != nullptr) {
74  int ret = GPU_stack_link(mat, node, name, in, out);
75  if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
76  const float min[3] = {0.0f, 0.0f, 0.0f};
77  const float max[3] = {1.0f, 1.0f, 1.0f};
78  GPU_link(
79  mat, "clamp_color", out[0].link, GPU_constant(min), GPU_constant(max), &out[0].link);
80  }
81  return ret;
82  }
83 
84  return 0;
85 }
86 
88  private:
89  bool clamp_;
90  int type_;
91 
92  public:
93  MixRGBFunction(bool clamp, int type) : clamp_(clamp), type_(type)
94  {
96  this->set_signature(&signature);
97  }
98 
100  {
102  signature.single_input<float>("Fac");
103  signature.single_input<ColorGeometry4f>("Color1");
104  signature.single_input<ColorGeometry4f>("Color2");
105  signature.single_output<ColorGeometry4f>("Color");
106  return signature.build();
107  }
108 
110  {
111  const VArray<float> &fac = params.readonly_single_input<float>(0, "Fac");
112  const VArray<ColorGeometry4f> &col1 = params.readonly_single_input<ColorGeometry4f>(1,
113  "Color1");
114  const VArray<ColorGeometry4f> &col2 = params.readonly_single_input<ColorGeometry4f>(2,
115  "Color2");
116  MutableSpan<ColorGeometry4f> results = params.uninitialized_single_output<ColorGeometry4f>(
117  3, "Color");
118 
119  for (int64_t i : mask) {
120  results[i] = col1[i];
121  ramp_blend(type_, results[i], clamp_f(fac[i], 0.0f, 1.0f), col2[i]);
122  }
123 
124  if (clamp_) {
125  for (int64_t i : mask) {
126  clamp_v3(results[i], 0.0f, 1.0f);
127  }
128  }
129  }
130 };
131 
133 {
134  bNode &node = builder.node();
135  bool clamp = node.custom2 & SHD_MIXRGB_CLAMP;
136  int mix_type = node.custom1;
138 }
139 
140 } // namespace blender::nodes::node_shader_mix_rgb_cc
141 
143 {
144  namespace file_ns = blender::nodes::node_shader_mix_rgb_cc;
145 
146  static bNodeType ntype;
147 
150  ntype.labelfunc = node_blend_label;
153 
154  nodeRegisterType(&ntype);
155 }
void ramp_blend(int type, float r_col[3], float fac, const float col[3])
Definition: material.c:1611
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:347
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
MINLINE float clamp_f(float value, float min, float max)
MINLINE void clamp_v3(float vec[3], float min, float max)
#define UNUSED(x)
#define MA_RAMP_SUB
#define MA_RAMP_VAL
#define MA_RAMP_DIFF
#define MA_RAMP_DARK
#define MA_RAMP_BURN
#define MA_RAMP_LIGHT
#define MA_RAMP_SOFT
#define MA_RAMP_LINEAR
#define MA_RAMP_OVERLAY
#define MA_RAMP_MULT
#define MA_RAMP_SAT
#define MA_RAMP_DIV
#define MA_RAMP_DODGE
#define MA_RAMP_SCREEN
#define MA_RAMP_HUE
#define MA_RAMP_BLEND
#define MA_RAMP_ADD
#define MA_RAMP_COLOR
#define SHD_MIXRGB_CLAMP
_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 type
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 Output data from inside of a node group A color picker SH_NODE_MIX_RGB
@ PROP_FACTOR
Definition: RNA_types.h:144
void set_signature(const MFSignature *signature)
const MFSignature & signature() const
void call(IndexMask mask, fn::MFParams params, fn::MFContext UNUSED(context)) const override
OperationNode * node
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
T clamp(const T &a, const T &min, const T &max)
static void sh_node_mix_rgb_build_multi_function(NodeMultiFunctionBuilder &builder)
static void sh_node_mix_rgb_declare(NodeDeclarationBuilder &b)
static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static const char * gpu_shader_get_name(int mode)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_mix_rgb()
void sh_fn_node_type_base(bNodeType *ntype, int type, const char *name, short nclass)
void node_blend_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
Definition: node_util.c:179
return ret
#define min(a, b)
Definition: sort.c:35
__int64 int64_t
Definition: stdint.h:89
Defines a node type.
Definition: BKE_node.h:226
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
NodeMultiFunctionBuildFunction build_multi_function
Definition: BKE_node.h:313
NodeDeclareFunction declare
Definition: BKE_node.h:324
float max
#define N_(msgid)