Blender V4.3
node_composite_colorcorrection.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
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "GPU_material.hh"
15
16#include "COM_shader_node.hh"
17
19
20/* ******************* Color Correction ********************************* */
21
23
25
27{
28 b.add_input<decl::Color>("Image")
29 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
30 .compositor_domain_priority(0);
31 b.add_input<decl::Float>("Mask")
32 .default_value(1.0f)
33 .min(0.0f)
34 .max(1.0f)
36 b.add_output<decl::Color>("Image");
37}
38
39static void node_composit_init_colorcorrection(bNodeTree * /*ntree*/, bNode *node)
40{
41 NodeColorCorrection *n = MEM_cnew<NodeColorCorrection>(__func__);
42 n->startmidtones = 0.2f;
43 n->endmidtones = 0.7f;
44 n->master.contrast = 1.0f;
45 n->master.gain = 1.0f;
46 n->master.gamma = 1.0f;
47 n->master.lift = 0.0f;
48 n->master.saturation = 1.0f;
49 n->midtones.contrast = 1.0f;
50 n->midtones.gain = 1.0f;
51 n->midtones.gamma = 1.0f;
52 n->midtones.lift = 0.0f;
53 n->midtones.saturation = 1.0f;
54 n->shadows.contrast = 1.0f;
55 n->shadows.gain = 1.0f;
56 n->shadows.gamma = 1.0f;
57 n->shadows.lift = 0.0f;
58 n->shadows.saturation = 1.0f;
59 n->highlights.contrast = 1.0f;
60 n->highlights.gain = 1.0f;
61 n->highlights.gamma = 1.0f;
62 n->highlights.lift = 0.0f;
63 n->highlights.saturation = 1.0f;
64 node->custom1 = 7; // red + green + blue enabled
65 node->storage = n;
66}
67
69{
70 uiLayout *row;
71
72 row = uiLayoutRow(layout, false);
73 uiItemR(row, ptr, "red", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
74 uiItemR(row, ptr, "green", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
75 uiItemR(row, ptr, "blue", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
76
77 row = uiLayoutRow(layout, false);
78 uiItemL(row, "", ICON_NONE);
79 uiItemL(row, IFACE_("Saturation"), ICON_NONE);
80 uiItemL(row, IFACE_("Contrast"), ICON_NONE);
81 uiItemL(row, IFACE_("Gamma"), ICON_NONE);
82 uiItemL(row, IFACE_("Gain"), ICON_NONE);
83 uiItemL(row, IFACE_("Lift"), ICON_NONE);
84
85 row = uiLayoutRow(layout, false);
86 uiItemL(row, IFACE_("Master"), ICON_NONE);
87 uiItemR(
88 row, ptr, "master_saturation", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
89 uiItemR(
90 row, ptr, "master_contrast", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
91 uiItemR(row, ptr, "master_gamma", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
92 uiItemR(row, ptr, "master_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
93 uiItemR(row, ptr, "master_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
94
95 row = uiLayoutRow(layout, false);
96 uiItemL(row, IFACE_("Highlights"), ICON_NONE);
97 uiItemR(row,
98 ptr,
99 "highlights_saturation",
101 "",
102 ICON_NONE);
103 uiItemR(row,
104 ptr,
105 "highlights_contrast",
107 "",
108 ICON_NONE);
109 uiItemR(
110 row, ptr, "highlights_gamma", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
111 uiItemR(
112 row, ptr, "highlights_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
113 uiItemR(
114 row, ptr, "highlights_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
115
116 row = uiLayoutRow(layout, false);
117 uiItemL(row, IFACE_("Midtones"), ICON_NONE);
118 uiItemR(row,
119 ptr,
120 "midtones_saturation",
122 "",
123 ICON_NONE);
124 uiItemR(
125 row, ptr, "midtones_contrast", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
126 uiItemR(
127 row, ptr, "midtones_gamma", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
128 uiItemR(row, ptr, "midtones_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
129 uiItemR(row, ptr, "midtones_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
130
131 row = uiLayoutRow(layout, false);
132 uiItemL(row, IFACE_("Shadows"), ICON_NONE);
133 uiItemR(row,
134 ptr,
135 "shadows_saturation",
137 "",
138 ICON_NONE);
139 uiItemR(
140 row, ptr, "shadows_contrast", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
141 uiItemR(row, ptr, "shadows_gamma", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
142 uiItemR(row, ptr, "shadows_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
143 uiItemR(row, ptr, "shadows_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, "", ICON_NONE);
144
145 row = uiLayoutRow(layout, false);
146 uiItemR(row,
147 ptr,
148 "midtones_start",
150 nullptr,
151 ICON_NONE);
152 uiItemR(
153 row, ptr, "midtones_end", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
154}
155
157 bContext * /*C*/,
159{
160 uiLayout *row;
161
162 row = uiLayoutRow(layout, false);
163 uiItemR(row, ptr, "red", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
164 uiItemR(row, ptr, "green", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
165 uiItemR(row, ptr, "blue", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
166 row = layout;
167 uiItemL(row, IFACE_("Saturation"), ICON_NONE);
168 uiItemR(row,
169 ptr,
170 "master_saturation",
172 nullptr,
173 ICON_NONE);
174 uiItemR(row,
175 ptr,
176 "highlights_saturation",
178 nullptr,
179 ICON_NONE);
180 uiItemR(row,
181 ptr,
182 "midtones_saturation",
184 nullptr,
185 ICON_NONE);
186 uiItemR(row,
187 ptr,
188 "shadows_saturation",
190 nullptr,
191 ICON_NONE);
192
193 uiItemL(row, IFACE_("Contrast"), ICON_NONE);
194 uiItemR(row,
195 ptr,
196 "master_contrast",
198 nullptr,
199 ICON_NONE);
200 uiItemR(row,
201 ptr,
202 "highlights_contrast",
204 nullptr,
205 ICON_NONE);
206 uiItemR(row,
207 ptr,
208 "midtones_contrast",
210 nullptr,
211 ICON_NONE);
212 uiItemR(row,
213 ptr,
214 "shadows_contrast",
216 nullptr,
217 ICON_NONE);
218
219 uiItemL(row, IFACE_("Gamma"), ICON_NONE);
220 uiItemR(
221 row, ptr, "master_gamma", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
222 uiItemR(row,
223 ptr,
224 "highlights_gamma",
226 nullptr,
227 ICON_NONE);
228 uiItemR(row,
229 ptr,
230 "midtones_gamma",
232 nullptr,
233 ICON_NONE);
234 uiItemR(row,
235 ptr,
236 "shadows_gamma",
238 nullptr,
239 ICON_NONE);
240
241 uiItemL(row, IFACE_("Gain"), ICON_NONE);
242 uiItemR(
243 row, ptr, "master_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
244 uiItemR(row,
245 ptr,
246 "highlights_gain",
248 nullptr,
249 ICON_NONE);
250 uiItemR(row,
251 ptr,
252 "midtones_gain",
254 nullptr,
255 ICON_NONE);
256 uiItemR(
257 row, ptr, "shadows_gain", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
258
259 uiItemL(row, IFACE_("Lift"), ICON_NONE);
260 uiItemR(
261 row, ptr, "master_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
262 uiItemR(row,
263 ptr,
264 "highlights_lift",
266 nullptr,
267 ICON_NONE);
268 uiItemR(row,
269 ptr,
270 "midtones_lift",
272 nullptr,
273 ICON_NONE);
274 uiItemR(
275 row, ptr, "shadows_lift", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
276
277 row = uiLayoutRow(layout, false);
278 uiItemR(row, ptr, "midtones_start", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
279 uiItemR(row, ptr, "midtones_end", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
280}
281
282using namespace blender::realtime_compositor;
283
285 public:
287
288 void compile(GPUMaterial *material) override
289 {
290 GPUNodeStack *inputs = get_inputs_array();
291 GPUNodeStack *outputs = get_outputs_array();
292
293 float enabled_channels[3];
294 get_enabled_channels(enabled_channels);
295 float luminance_coefficients[3];
297
298 const NodeColorCorrection &node_color_correction = node_storage(bnode());
299
300 GPU_stack_link(material,
301 &bnode(),
302 "node_composite_color_correction",
303 inputs,
304 outputs,
305 GPU_constant(enabled_channels),
306 GPU_uniform(&node_color_correction.startmidtones),
307 GPU_uniform(&node_color_correction.endmidtones),
308 GPU_uniform(&node_color_correction.master.saturation),
309 GPU_uniform(&node_color_correction.master.contrast),
310 GPU_uniform(&node_color_correction.master.gamma),
311 GPU_uniform(&node_color_correction.master.gain),
312 GPU_uniform(&node_color_correction.master.lift),
313 GPU_uniform(&node_color_correction.shadows.saturation),
314 GPU_uniform(&node_color_correction.shadows.contrast),
315 GPU_uniform(&node_color_correction.shadows.gamma),
316 GPU_uniform(&node_color_correction.shadows.gain),
317 GPU_uniform(&node_color_correction.shadows.lift),
318 GPU_uniform(&node_color_correction.midtones.saturation),
319 GPU_uniform(&node_color_correction.midtones.contrast),
320 GPU_uniform(&node_color_correction.midtones.gamma),
321 GPU_uniform(&node_color_correction.midtones.gain),
322 GPU_uniform(&node_color_correction.midtones.lift),
323 GPU_uniform(&node_color_correction.highlights.saturation),
324 GPU_uniform(&node_color_correction.highlights.contrast),
325 GPU_uniform(&node_color_correction.highlights.gamma),
326 GPU_uniform(&node_color_correction.highlights.gain),
327 GPU_uniform(&node_color_correction.highlights.lift),
328 GPU_constant(luminance_coefficients));
329 }
330
331 void get_enabled_channels(float enabled_channels[3])
332 {
333 for (int i = 0; i < 3; i++) {
334 enabled_channels[i] = (bnode().custom1 & (1 << i)) ? 1.0f : 0.0f;
335 }
336 }
337};
338
340{
341 return new ColorCorrectionShaderNode(node);
342}
343
344} // namespace blender::nodes::node_composite_colorcorrection_cc
345
347{
349
350 static blender::bke::bNodeType ntype;
351
352 cmp_node_type_base(&ntype, CMP_NODE_COLORCORRECTION, "Color Correction", NODE_CLASS_OP_COLOR);
353 ntype.declare = file_ns::cmp_node_colorcorrection_declare;
354 ntype.draw_buttons = file_ns::node_composit_buts_colorcorrection;
355 ntype.draw_buttons_ex = file_ns::node_composit_buts_colorcorrection_ex;
356 blender::bke::node_type_size(&ntype, 400, 200, 600);
357 ntype.initfunc = file_ns::node_composit_init_colorcorrection;
359 &ntype, "NodeColorCorrection", node_free_standard_storage, node_copy_standard_storage);
360 ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
361
363}
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define IFACE_(msgid)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
GPUNodeLink * GPU_uniform(const float *num)
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_SLIDER
local_group_size(16, 16) .push_constant(Type b
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition node.cc:4602
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_composit_buts_colorcorrection_ex(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_composit_buts_colorcorrection(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_colorcorrection_declare(NodeDeclarationBuilder &b)
static void node_composit_init_colorcorrection(bNodeTree *, bNode *node)
void register_node_type_cmp_colorcorrection()
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
ColorCorrectionData shadows
ColorCorrectionData midtones
ColorCorrectionData master
ColorCorrectionData highlights
int16_t custom1
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:240
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeGetCompositorShaderNodeFunction get_compositor_shader_node
Definition BKE_node.hh:328
PointerRNA * ptr
Definition wm_files.cc:4126