37 N_(
"Offset/Power/Slope (ASC-CDL)"),
38 N_(
"ASC-CDL standard color correction")},
43 N_(
"Chromatic adaption from a different white point")},
44 {0,
nullptr, 0,
nullptr,
nullptr},
50 b.use_custom_socket_order();
51 b.allow_any_socket_order();
53 b.add_input<
decl::Color>(
"Image"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
54 b.add_output<
decl::Color>(
"Image"_ustr).align_with_previous();
73 .description(
"Correction for shadows");
75 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
78 b.add_input<
decl::Float>(
"Gamma"_ustr,
"Base Gamma"_ustr)
84 .description(
"Correction for midtones");
85 b.add_input<
decl::Color>(
"Gamma"_ustr,
"Color Gamma"_ustr)
86 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
95 .description(
"Correction for highlights");
97 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
101 b.add_input<
decl::Float>(
"Offset"_ustr,
"Base Offset"_ustr)
107 .description(
"Correction for shadows");
108 b.add_input<
decl::Color>(
"Offset"_ustr,
"Color Offset"_ustr)
109 .default_value({0.0f, 0.0f, 0.0f, 1.0f})
112 b.add_input<
decl::Float>(
"Power"_ustr,
"Base Power"_ustr)
118 .description(
"Correction for midtones");
119 b.add_input<
decl::Color>(
"Power"_ustr,
"Color Power"_ustr)
120 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
123 b.add_input<
decl::Float>(
"Slope"_ustr,
"Base Slope"_ustr)
129 .description(
"Correction for highlights");
130 b.add_input<
decl::Color>(
"Slope"_ustr,
"Color Slope"_ustr)
131 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
137 .default_value(6500.0f)
142 .description(
"Color temperature of the input's white point");
144 .default_value(10.0f)
149 .description(
"Color tint of the input's white point (the default of 10 matches daylight)");
152 template_crypto_picker(&
split, ptr,
"input_whitepoint", ICON_EYEDROPPER);
157 .default_value(6500.0f)
162 .description(
"Color temperature of the output's white point");
164 .default_value(10.0f)
169 .description(
"Color tint of the output's white point (the default of 10 matches daylight)");
172 template_crypto_picker(&
split, ptr,
"output_whitepoint", ICON_EYEDROPPER);
177 const float input_tint,
178 const float output_temperature,
179 const float output_tint)
186 return xyz_to_scene * adaption * scene_to_xyz;
196 const bool is_white_point = !type.is_directly_linked() &&
200 const bNodeSocket &input_temperature = *
node->input_by_identifier(
"Input Temperature"_ustr);
201 const bNodeSocket &input_tint = *
node->input_by_identifier(
"Input Tint"_ustr);
202 const bNodeSocket &output_temperature = *
node->input_by_identifier(
"Output Temperature"_ustr);
203 const bNodeSocket &output_tint = *
node->input_by_identifier(
"Output Tint"_ustr);
207 if (is_white_point && !input_temperature.is_directly_linked() &&
208 !input_tint.is_directly_linked() && !output_temperature.is_directly_linked() &&
209 !output_tint.is_directly_linked())
219 "node_composite_color_balance_white_point_constant",
229 "node_composite_color_balance",
237 const float base_lift,
239 const float base_gamma,
241 const float base_gain,
244 const float3 lift = base_lift + color_lift.xyz();
245 const float3 lift_balanced = ((
color.xyz() - 1.0f) * (2.0f - lift)) + 1.0f;
247 const float3 gain = base_gain * color_gain.xyz();
250 const float3 gamma = base_gamma * color_gamma.xyz();
257 const float base_offset,
258 const float4 color_offset,
259 const float base_power,
261 const float base_slope,
264 const float3 slope = base_slope * color_slope.xyz();
267 const float3 offset = base_offset + color_offset.xyz();
268 const float3 offset_balanced = slope_balanced + offset;
270 const float3 power = base_power * color_power.xyz();
280 const float3 balanced = white_point_matrix *
color.xyz();
285 const float input_temperature,
286 const float input_tint,
287 const float output_temperature,
288 const float output_tint,
295 const float3x3 white_point_matrix = xyz_to_scene * adaption * scene_to_xyz;
297 const float3 balanced = white_point_matrix *
color.xyz();
304 const float base_lift,
306 const float base_gamma,
308 const float base_gain,
310 const float base_offset,
311 const float4 color_offset,
312 const float base_power,
314 const float base_slope,
316 const float input_temperature,
317 const float input_tint,
318 const float output_temperature,
319 const float output_tint,
327 color, base_lift, color_lift, base_gamma, color_gamma, base_gain, color_gain);
331 color, base_offset, color_offset, base_power, color_power, base_slope, color_slope);
353 static const mf::Signature
signature = []() {
355 mf::SignatureBuilder builder{
"Color Balance",
signature};
356 builder.single_input<
Color>(
"Color");
357 builder.single_input<
float>(
"Factor");
360 builder.single_input<
float>(
"Base Lift");
361 builder.single_input<
Color>(
"Color Lift");
362 builder.single_input<
float>(
"Base Gamma");
363 builder.single_input<
Color>(
"Color Gamma");
364 builder.single_input<
float>(
"Base Gain");
365 builder.single_input<
Color>(
"Color Gain");
367 builder.single_input<
float>(
"Base Offset");
368 builder.single_input<
Color>(
"Color Offset");
369 builder.single_input<
float>(
"Base Power");
370 builder.single_input<
Color>(
"Color Power");
371 builder.single_input<
float>(
"Base Slope");
372 builder.single_input<
Color>(
"Color Slope");
374 builder.single_input<
float>(
"Input Temperature");
375 builder.single_input<
float>(
"Input Tint");
376 builder.single_input<
float>(
"Output Temperature");
377 builder.single_input<
float>(
"Output Tint");
379 builder.single_output<
Color>(
"Result");
388 const VArray<float> factor_array = params.readonly_single_input<
float>(1,
"Factor");
391 const VArray<float> base_lift_array = params.readonly_single_input<
float>(3,
"Base Lift");
392 const VArray<Color> color_lift_array = params.readonly_single_input<
Color>(4,
"Color Lift");
393 const VArray<float> base_gamma_array = params.readonly_single_input<
float>(5,
"Base Gamma");
394 const VArray<Color> color_gamma_array = params.readonly_single_input<
Color>(6,
"Color Gamma");
395 const VArray<float> base_gain_array = params.readonly_single_input<
float>(7,
"Base Gain");
396 const VArray<Color> color_gain_array = params.readonly_single_input<
Color>(8,
"Color Gain");
398 const VArray<float> base_offset_array = params.readonly_single_input<
float>(9,
"Base Offset");
401 const VArray<float> base_power_array = params.readonly_single_input<
float>(11,
"Base Power");
402 const VArray<Color> color_power_array = params.readonly_single_input<
Color>(12,
"Color Power");
403 const VArray<float> base_slope_array = params.readonly_single_input<
float>(13,
"Base Slope");
404 const VArray<Color> color_slope_array = params.readonly_single_input<
Color>(14,
"Color Slope");
406 const VArray<float> input_temperature_array = params.readonly_single_input<
float>(
407 15,
"Input Temperature");
408 const VArray<float> input_tint_array = params.readonly_single_input<
float>(16,
"Input Tint");
409 const VArray<float> output_temperature_array = params.readonly_single_input<
float>(
410 17,
"Output Temperature");
411 const VArray<float> output_tint_array = params.readonly_single_input<
float>(18,
"Output Tint");
415 const std::optional<MenuValue> type_single = type_array.get_if_single();
416 const std::optional<float> input_temperature_single = input_temperature_array.get_if_single();
417 const std::optional<float> input_tint_single = input_tint_array.get_if_single();
418 const std::optional<float> output_temperature_single =
419 output_temperature_array.get_if_single();
420 const std::optional<float> output_tint_single = output_tint_array.get_if_single();
422 const bool is_white_point = type_single.has_value() &&
427 if (is_white_point && input_temperature_single.has_value() && input_tint_single.has_value() &&
428 output_temperature_single.has_value() && output_tint_single.has_value())
431 input_tint_single.value(),
432 output_temperature_single.value(),
433 output_tint_single.value());
443 bool all_but_color_single_value =
true;
444 for (
int i = 0; i < 19; i++) {
448 if (!params.readonly_single_input(i).is_single()) {
449 all_but_color_single_value =
false;
454 if (all_but_color_single_value) {
455 const float factor = factor_array.get_internal_single();
457 const float base_lift = base_lift_array.get_internal_single();
458 const float4 color_lift =
float4(color_lift_array.get_internal_single());
459 const float base_gamma = base_gamma_array.get_internal_single();
460 const float4 color_gamma =
float4(color_gamma_array.get_internal_single());
461 const float base_gain = base_gain_array.get_internal_single();
462 const float4 color_gain =
float4(color_gain_array.get_internal_single());
463 const float base_offset = base_offset_array.get_internal_single();
464 const float4 color_offset =
float4(color_offset_array.get_internal_single());
465 const float base_power = base_power_array.get_internal_single();
466 const float4 color_power =
float4(color_power_array.get_internal_single());
467 const float base_slope = base_slope_array.get_internal_single();
468 const float4 color_slope =
float4(color_slope_array.get_internal_single());
469 const float input_temperature = input_temperature_array.get_internal_single();
470 const float input_tint = input_tint_array.get_internal_single();
471 const float output_temperature = output_temperature_array.get_internal_single();
472 const float output_tint = output_tint_array.get_internal_single();
504 float4(color_lift_array[i]),
506 float4(color_gamma_array[i]),
508 float4(color_gain_array[i]),
509 base_offset_array[i],
510 float4(color_offset_array[i]),
512 float4(color_power_array[i]),
514 float4(color_slope_array[i]),
515 input_temperature_array[i],
517 output_temperature_array[i],
518 output_tint_array[i],
538 ntype.
ui_name =
"Color Balance";
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_COLORBALANCE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
const Signature & signature() const
void set_signature(const Signature *signature)
DeclType::Builder & add_input(UString name, UString identifier=""_ustr)
void add_layout(std::function< void(ui::Layout &, bContext *, PointerRNA *)> draw)
void set_matching_fn(const mf::MultiFunction *fn)
void call(const IndexMask &mask, mf::Params params, mf::Context) const override
ccl_device_inline float2 power(const float2 v, const float e)
void node_register_type(bNodeType &ntype)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
T pow(const T &x, const T &power)
float3 whitepoint_from_temp_tint(float temperature, float tint)
T min(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
float3x3 chromatic_adaption_matrix(const float3 &from_XYZ, const float3 &to_XYZ)
T max(const T &a, const T &b)
static const EnumPropertyItem type_items[]
static float3x3 get_white_point_matrix(const float input_temperature, const float input_tint, const float output_temperature, const float output_tint)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
static void node_declare(NodeDeclarationBuilder &b)
static float4 offset_power_slope(const float4 color, const float base_offset, const float4 color_offset, const float base_power, const float4 color_power, const float base_slope, const float4 color_slope)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static float4 white_point_constant(const float4 color, const float factor, const float3x3 white_point_matrix)
static float4 white_point_variable(const float4 color, const float input_temperature, const float input_tint, const float output_temperature, const float output_tint, const float3x3 &scene_to_xyz, const float3x3 &xyz_to_scene)
static float4 color_balance(const float4 color, const float factor, const CMPNodeColorBalanceMethod type, const float base_lift, const float4 color_lift, const float base_gamma, const float4 color_gamma, const float base_gain, const float4 color_gain, const float base_offset, const float4 color_offset, const float base_power, const float4 color_power, const float base_slope, const float4 color_slope, const float input_temperature, const float input_tint, const float output_temperature, const float output_tint, const float3x3 scene_to_xyz, const float3x3 xyz_to_scene)
static float4 lift_gamma_gain(const float4 color, const float base_lift, const float4 color_lift, const float base_gamma, const float4 color_gamma, const float base_gain, const float4 color_gain)
static void node_register()
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
MatBase< float, 4, 4 > float4x4
GPUNodeLink * GPU_uniform(const float *num)
VecBase< float, 4 > float4
MatBase< float, 3, 3 > float3x3
float3x3 IMB_colormanagement_get_scene_linear_to_xyz()
float3x3 IMB_colormanagement_get_xyz_to_scene_linear()
CMPNodeColorBalanceMethod
@ CMP_NODE_COLOR_BALANCE_WHITEPOINT
@ CMP_NODE_COLOR_BALANCE_LGG
@ CMP_NODE_COLOR_BALANCE_ASC_CDL
VecBase< float, 3 > float3
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const T * base_ptr() const
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare
Layout & split(float percentage, bool align)