Blender V4.3
node_composite_mixrgb.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_assert.h"
10
11#include "DNA_material_types.h"
12
13#include "GPU_material.hh"
14
15#include "COM_shader_node.hh"
16
18
19#include "RNA_enum_types.hh"
20
22
23/* **************** MIX RGB ******************** */
24
26
28{
29 b.add_input<decl::Float>("Fac")
30 .default_value(1.0f)
31 .min(0.0f)
32 .max(1.0f)
34 .compositor_domain_priority(2);
35 b.add_input<decl::Color>("Image")
36 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
37 .compositor_domain_priority(0);
38 b.add_input<decl::Color>("Image", "Image_001")
39 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
40 .compositor_domain_priority(1);
41 b.add_output<decl::Color>("Image");
42}
43
45 public:
46 std::string socket_name;
47 int mode = MA_RAMP_BLEND;
49 {
50 bNode &node = params.add_node("CompositorNodeMixRGB");
51 node.custom1 = mode;
52 params.update_and_connect_available_socket(node, socket_name);
53 }
54};
55
57{
58 const int weight = ELEM(params.other_socket().type, SOCK_RGBA) ? 0 : -1;
59
60 for (const EnumPropertyItem *item = rna_enum_ramp_blend_items; item->identifier != nullptr;
61 item++)
62 {
63 if (item->name != nullptr && item->identifier[0] != '\0') {
64 params.add_item(IFACE_(item->name), SocketSearchOp{"Image", item->value}, weight);
65 }
66 }
67}
68
69using namespace blender::realtime_compositor;
70
72 public:
74
75 void compile(GPUMaterial *material) override
76 {
79
80 if (get_use_alpha()) {
81 GPU_link(material,
82 "multiply_by_alpha",
83 get_input_link("Fac"),
84 get_input_link("Image_001"),
85 &get_input("Fac").link);
86 }
87
88 GPU_stack_link(material, &bnode(), get_shader_function_name(), inputs, outputs);
89
90 if (!get_should_clamp()) {
91 return;
92 }
93
94 const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f};
95 const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f};
96 GPU_link(material,
97 "clamp_color",
98 get_output("Image").link,
100 GPU_constant(max),
101 &get_output("Image").link);
102 }
103
105 {
106 return bnode().custom1;
107 }
108
110 {
111 switch (get_mode()) {
112 case MA_RAMP_BLEND:
113 return "mix_blend";
114 case MA_RAMP_ADD:
115 return "mix_add";
116 case MA_RAMP_MULT:
117 return "mix_mult";
118 case MA_RAMP_SUB:
119 return "mix_sub";
120 case MA_RAMP_SCREEN:
121 return "mix_screen";
122 case MA_RAMP_DIV:
123 return "mix_div";
124 case MA_RAMP_DIFF:
125 return "mix_diff";
127 return "mix_exclusion";
128 case MA_RAMP_DARK:
129 return "mix_dark";
130 case MA_RAMP_LIGHT:
131 return "mix_light";
132 case MA_RAMP_OVERLAY:
133 return "mix_overlay";
134 case MA_RAMP_DODGE:
135 return "mix_dodge";
136 case MA_RAMP_BURN:
137 return "mix_burn";
138 case MA_RAMP_HUE:
139 return "mix_hue";
140 case MA_RAMP_SAT:
141 return "mix_sat";
142 case MA_RAMP_VAL:
143 return "mix_val";
144 case MA_RAMP_COLOR:
145 return "mix_color";
146 case MA_RAMP_SOFT:
147 return "mix_soft";
148 case MA_RAMP_LINEAR:
149 return "mix_linear";
150 }
151
153 return nullptr;
154 }
155
157 {
159 }
160
162 {
163 return bnode().custom2 & SHD_MIXRGB_CLAMP;
164 }
165};
166
168{
169 return new MixRGBShaderNode(node);
170}
171
172} // namespace blender::nodes::node_composite_mixrgb_cc
173
175{
177
178 static blender::bke::bNodeType ntype;
179
180 cmp_node_type_base(&ntype, CMP_NODE_MIX_RGB, "Mix", NODE_CLASS_OP_COLOR);
181 ntype.flag |= NODE_PREVIEW;
182 ntype.declare = file_ns::cmp_node_mixrgb_declare;
184 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
185 ntype.gather_link_search_ops = file_ns::node_gather_link_searches;
186
188}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define ELEM(...)
#define IFACE_(msgid)
@ MA_RAMP_LIGHT
@ MA_RAMP_COLOR
@ MA_RAMP_SAT
@ MA_RAMP_HUE
@ MA_RAMP_LINEAR
@ MA_RAMP_DIV
@ MA_RAMP_EXCLUSION
@ MA_RAMP_ADD
@ MA_RAMP_DODGE
@ MA_RAMP_SUB
@ MA_RAMP_SCREEN
@ MA_RAMP_SOFT
@ MA_RAMP_DARK
@ MA_RAMP_BURN
@ MA_RAMP_BLEND
@ MA_RAMP_VAL
@ MA_RAMP_OVERLAY
@ MA_RAMP_MULT
@ MA_RAMP_DIFF
@ NODE_PREVIEW
@ SHD_MIXRGB_USE_ALPHA
@ SHD_MIXRGB_CLAMP
@ SOCK_RGBA
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:154
GPUNodeLink * get_input_link(StringRef identifier)
GPUNodeStack & get_input(StringRef identifier)
GPUNodeStack & get_output(StringRef identifier)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
static void cmp_node_mixrgb_declare(NodeDeclarationBuilder &b)
static ShaderNode * get_compositor_shader_node(DNode node)
void register_node_type_cmp_mix_rgb()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_blend_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
Definition node_util.cc:180
const EnumPropertyItem rna_enum_ramp_blend_items[]
#define min(a, b)
Definition sort.c:32
const char * identifier
Definition RNA_types.hh:506
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328