Blender V5.0
node_composite_hue_sat_val.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
8
9#include "BLI_math_base.hh"
10#include "BLI_math_color.h"
11#include "BLI_math_vector.hh"
13
15
16#include "NOD_multi_function.hh"
17
18#include "GPU_material.hh"
19
21
22/* **************** Hue/Saturation/Value ******************** */
23
25
27{
28 b.use_custom_socket_order();
29 b.allow_any_socket_order();
30 b.is_function_node();
31 b.add_input<decl::Color>("Image").default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
32 b.add_output<decl::Color>("Image").align_with_previous();
33
34 b.add_input<decl::Float>("Hue").default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR);
35 b.add_input<decl::Float>("Saturation")
36 .default_value(1.0f)
37 .min(0.0f)
38 .max(2.0f)
40 b.add_input<decl::Float>("Value")
41 .default_value(1.0f)
42 .min(0.0f)
43 .max(2.0f)
45 .translation_context(BLT_I18NCONTEXT_COLOR);
46 b.add_input<decl::Float>("Factor", "Fac")
47 .default_value(1.0f)
48 .min(0.0f)
49 .max(1.0f)
51}
52
53using namespace blender::compositor;
54
55static int node_gpu_material(GPUMaterial *material,
56 bNode *node,
57 bNodeExecData * /*execdata*/,
60{
61 return GPU_stack_link(material, node, "node_composite_hue_saturation_value", inputs, outputs);
62}
63
65{
66 static auto function = mf::build::SI5_SO<float4, float, float, float, float, float4>(
67 "Hue Saturation Value",
68 [](const float4 &color,
69 const float hue,
70 const float saturation,
71 const float value,
72 const float factor) -> float4 {
73 float3 hsv;
74 rgb_to_hsv_v(color, hsv);
75
76 hsv.x = math::fract(hsv.x + hue + 0.5f);
77 hsv.y = hsv.y * saturation;
78 hsv.z = hsv.z * value;
79
80 float3 rgb_result;
81 hsv_to_rgb_v(hsv, rgb_result);
82 rgb_result = math::max(rgb_result, float3(0.0f));
83
84 return float4(math::interpolate(color.xyz(), rgb_result, factor), color.w);
85 },
86 mf::build::exec_presets::SomeSpanOrSingle<0>());
87 builder.set_matching_fn(function);
88}
89
90} // namespace blender::nodes::node_composite_hue_sat_val_cc
91
93{
95
96 static blender::bke::bNodeType ntype;
97
98 cmp_node_type_base(&ntype, "CompositorNodeHueSat", CMP_NODE_HUE_SAT);
99 ntype.ui_name = "Hue/Saturation/Value";
100 ntype.ui_description = "Apply a color transformation in the HSV color model";
101 ntype.enum_name_legacy = "HUE_SAT";
103 ntype.declare = file_ns::cmp_node_huesatval_declare;
104 ntype.gpu_fn = file_ns::node_gpu_material;
105 ntype.build_multi_function = file_ns::node_build_multi_function;
106
108}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define CMP_NODE_HUE_SAT
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
#define BLT_I18NCONTEXT_COLOR
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FACTOR
Definition RNA_types.hh:251
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
T interpolate(const T &a, const T &b, const FactorT &t)
T fract(const T &a)
T max(const T &a, const T &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static void cmp_node_huesatval_declare(NodeDeclarationBuilder &b)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
VecBase< float, 4 > float4
VecBase< float, 3 > float3
static void register_node_type_cmp_hue_sat()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
NodeMultiFunctionBuildFunction build_multi_function
Definition BKE_node.hh:351
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362