26 b.use_custom_socket_order();
27 b.allow_any_socket_order();
29 b.add_input<
decl::Color>(
"Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
30 b.add_output<
decl::Color>(
"Image"_ustr).align_with_previous();
32 b.add_input<
decl::Float>(
"Mask"_ustr).default_value(1.0f).min(0.0f).max(1.0f);
40 .description(
"Controls the saturation of the entire image");
46 .description(
"Controls the contrast of the entire image");
52 .description(
"Controls the gamma of the entire image");
58 .description(
"Controls the gain of the entire image");
64 .description(
"Controls the offset of the entire image");
72 .description(
"Controls the saturation of the highlights");
78 .description(
"Controls the contrast of the highlights");
84 .description(
"Controls the gamma of the highlights");
90 .description(
"Controls the gain of the highlights");
96 .description(
"Controls the offset of the highlights");
104 .description(
"Controls the saturation of the midtones");
110 .description(
"Controls the contrast of the midtones");
116 .description(
"Controls the gamma of the midtones");
122 .description(
"Controls the gain of the midtones");
128 .description(
"Controls the offset of the midtones");
136 .description(
"Controls the saturation of the shadows");
142 .description(
"Controls the contrast of the shadows");
148 .description(
"Controls the gamma of the shadows");
154 .description(
"Controls the gain of the shadows");
160 .description(
"Controls the offset of the shadows");
163 b.add_panel(
"Tonal Range"_ustr).default_closed(
true);
170 "Specifies the luminance at which the midtones of the image start and the shadows end");
177 "Specifies the luminance at which the midtones of the image end and the highlights "
183 .
description(
"If true, the correction will be applied on the red channel");
186 .
description(
"If true, the correction will be applied on the green channel");
189 .
description(
"If true, the correction will be applied on the blue channel");
200 float luminance_coefficients[3];
205 "node_composite_color_correction",
213 const float &master_saturation,
214 const float &master_contrast,
215 const float &master_gamma,
216 const float &master_gain,
217 const float &master_offset,
218 const float &highlights_saturation,
219 const float &highlights_contrast,
220 const float &highlights_gamma,
221 const float &highlights_gain,
222 const float &highlights_offset,
223 const float &midtones_saturation,
224 const float &midtones_contrast,
225 const float &midtones_gamma,
226 const float &midtones_gain,
227 const float &midtones_offset,
228 const float &shadows_saturation,
229 const float &shadows_contrast,
230 const float &shadows_gamma,
231 const float &shadows_gain,
232 const float &shadows_offset,
233 const float &start_midtones,
234 const float &end_midtones,
235 const bool &apply_on_red,
236 const bool &apply_on_green,
237 const bool &apply_on_blue,
238 const float3 &luminance_coefficients)
240 const float margin = 0.10f;
241 const float margin_divider = 0.5f / margin;
243 float level_shadows = 0.0f;
244 float level_midtones = 0.0f;
245 float level_highlights = 0.0f;
246 if (level < (start_midtones - margin)) {
247 level_shadows = 1.0f;
249 else if (level < (start_midtones + margin)) {
250 level_midtones = ((level - start_midtones) * margin_divider) + 0.5f;
251 level_shadows = 1.0f - level_midtones;
253 else if (level < (end_midtones - margin)) {
254 level_midtones = 1.0f;
256 else if (level < (end_midtones + margin)) {
257 level_highlights = ((level - end_midtones) * margin_divider) + 0.5f;
258 level_midtones = 1.0f - level_highlights;
261 level_highlights = 1.0f;
264 float contrast = level_shadows * shadows_contrast;
265 contrast += level_midtones * midtones_contrast;
266 contrast += level_highlights * highlights_contrast;
267 contrast *= master_contrast;
268 float saturation = level_shadows * shadows_saturation;
269 saturation += level_midtones * midtones_saturation;
270 saturation += level_highlights * highlights_saturation;
271 saturation *= master_saturation;
272 float gamma = level_shadows * shadows_gamma;
273 gamma += level_midtones * midtones_gamma;
274 gamma += level_highlights * highlights_gamma;
275 gamma *= master_gamma;
276 float gain = level_shadows * shadows_gain;
277 gain += level_midtones * midtones_gain;
278 gain += level_highlights * highlights_gain;
280 float offset = level_shadows * shadows_offset;
281 offset += level_midtones * midtones_offset;
282 offset += level_highlights * highlights_offset;
283 offset += master_offset;
285 float inverse_gamma = 1.0f / gamma;
288 float3 corrected = luma + saturation * (
color.xyz() - luma);
289 corrected = 0.5f + (corrected - 0.5f) * contrast;
290 corrected = corrected * gain + offset;
298 return float4(apply_on_red ? corrected.x :
color.x,
299 apply_on_green ? corrected.y :
color.y,
300 apply_on_blue ? corrected.z :
color.z,
308 float3 luminance_coefficients;
312 return mf::build::detail::build_multi_function_with_n_inputs_one_output<Color>(
316 const float &master_saturation,
317 const float &master_contrast,
318 const float &master_gamma,
319 const float &master_gain,
320 const float &master_offset,
321 const float &highlights_saturation,
322 const float &highlights_contrast,
323 const float &highlights_gamma,
324 const float &highlights_gain,
325 const float &highlights_offset,
326 const float &midtones_saturation,
327 const float &midtones_contrast,
328 const float &midtones_gamma,
329 const float &midtones_gain,
330 const float &midtones_offset,
331 const float &shadows_saturation,
332 const float &shadows_contrast,
333 const float &shadows_gamma,
334 const float &shadows_gain,
335 const float &shadows_offset,
336 const float &start_midtones,
337 const float &end_midtones,
338 const bool &apply_on_red,
339 const bool &apply_on_green,
340 const bool &apply_on_blue) ->
Color {
348 highlights_saturation,
368 luminance_coefficients));
370 mf::build::exec_presets::SomeSpanOrSingle<0>(),
406 ntype.
ui_name =
"Color Correction";
408 "Adjust the color of an image, separately in several tonal ranges (highlights, midtones and "
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_COLORCORRECTION
#define NOD_REGISTER_NODE(REGISTER_FUNC)
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
void construct_and_set_matching_fn_cb(Fn &&create_multi_function)
void node_register_type(bNodeType &ntype)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
T fallback_pow(const T &x, const T &power, const T &fallback)
T max(const T &a, const T &b)
static float4 color_correction(const float4 &color, const float &mask, const float &master_saturation, const float &master_contrast, const float &master_gamma, const float &master_gain, const float &master_offset, const float &highlights_saturation, const float &highlights_contrast, const float &highlights_gamma, const float &highlights_gain, const float &highlights_offset, const float &midtones_saturation, const float &midtones_contrast, const float &midtones_gamma, const float &midtones_gain, const float &midtones_offset, const float &shadows_saturation, const float &shadows_contrast, const float &shadows_gamma, const float &shadows_gain, const float &shadows_offset, const float &start_midtones, const float &end_midtones, const bool &apply_on_red, const bool &apply_on_green, const bool &apply_on_blue, const float3 &luminance_coefficients)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
GPUNodeLink * GPU_constant(const float *num)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare