diff options
author | Hallam Roberts <MysteryPancake> | 2022-05-04 19:44:03 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-05-04 19:44:03 +0300 |
commit | 82df48227bb7742466d429a5b465e0ada95d959d (patch) | |
tree | 59a44fc91b211beac52fb50002b51012f41931ed /source/blender/compositor/operations | |
parent | 7d41e1ed40ad74368a1019db554e47c6ab1baedb (diff) |
Nodes: Add general Combine/Separate Color nodes
Inspired by D12936 and D12929, this patch adds general purpose
"Combine Color" and "Separate Color" nodes to Geometry, Compositor,
Shader and Texture nodes.
- Within Geometry Nodes, it replaces the existing "Combine RGB" and
"Separate RGB" nodes.
- Within Compositor Nodes, it replaces the existing
"Combine RGBA/HSVA/YCbCrA/YUVA" and "Separate RGBA/HSVA/YCbCrA/YUVA"
nodes.
- Within Texture Nodes, it replaces the existing "Combine RGBA" and
"Separate RGBA" nodes.
- Within Shader Nodes, it replaces the existing "Combine RGB/HSV" and
"Separate RGB/HSV" nodes.
Python addons have not been updated to the new nodes yet.
**New shader code**
In node_color.h, color.h and gpu_shader_material_color_util.glsl,
missing methods hsl_to_rgb and rgb_to_hsl are added by directly
converting existing C code. They always produce the same result.
**Old code**
As requested by T96219, old nodes still exist but are not displayed in
the add menu. This means Python scripts can still create them as usual.
Otherwise, versioning replaces the old nodes with the new nodes when
opening .blend files.
Differential Revision: https://developer.blender.org/D14034
Diffstat (limited to 'source/blender/compositor/operations')
-rw-r--r-- | source/blender/compositor/operations/COM_ConvertOperation.cc | 62 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_ConvertOperation.h | 20 |
2 files changed, 82 insertions, 0 deletions
diff --git a/source/blender/compositor/operations/COM_ConvertOperation.cc b/source/blender/compositor/operations/COM_ConvertOperation.cc index 7579abf792a..24c0c577ac7 100644 --- a/source/blender/compositor/operations/COM_ConvertOperation.cc +++ b/source/blender/compositor/operations/COM_ConvertOperation.cc @@ -464,6 +464,68 @@ void ConvertHSVToRGBOperation::update_memory_buffer_partial(BuffersIterator<floa } } +/* ******** RGB to HSL ******** */ + +ConvertRGBToHSLOperation::ConvertRGBToHSLOperation() : ConvertBaseOperation() +{ + this->add_input_socket(DataType::Color); + this->add_output_socket(DataType::Color); +} + +void ConvertRGBToHSLOperation::execute_pixel_sampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + float input_color[4]; + input_operation_->read_sampled(input_color, x, y, sampler); + rgb_to_hsl_v(input_color, output); + output[3] = input_color[3]; +} + +void ConvertRGBToHSLOperation::update_memory_buffer_partial(BuffersIterator<float> &it) +{ + for (; !it.is_end(); ++it) { + const float *in = it.in(0); + rgb_to_hsl_v(in, it.out); + it.out[3] = in[3]; + } +} + +/* ******** HSL to RGB ******** */ + +ConvertHSLToRGBOperation::ConvertHSLToRGBOperation() : ConvertBaseOperation() +{ + this->add_input_socket(DataType::Color); + this->add_output_socket(DataType::Color); +} + +void ConvertHSLToRGBOperation::execute_pixel_sampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + float input_color[4]; + input_operation_->read_sampled(input_color, x, y, sampler); + hsl_to_rgb_v(input_color, output); + output[0] = max_ff(output[0], 0.0f); + output[1] = max_ff(output[1], 0.0f); + output[2] = max_ff(output[2], 0.0f); + output[3] = input_color[3]; +} + +void ConvertHSLToRGBOperation::update_memory_buffer_partial(BuffersIterator<float> &it) +{ + for (; !it.is_end(); ++it) { + const float *in = it.in(0); + hsl_to_rgb_v(in, it.out); + it.out[0] = max_ff(it.out[0], 0.0f); + it.out[1] = max_ff(it.out[1], 0.0f); + it.out[2] = max_ff(it.out[2], 0.0f); + it.out[3] = in[3]; + } +} + /* ******** Premul to Straight ******** */ ConvertPremulToStraightOperation::ConvertPremulToStraightOperation() : ConvertBaseOperation() diff --git a/source/blender/compositor/operations/COM_ConvertOperation.h b/source/blender/compositor/operations/COM_ConvertOperation.h index e1904d61d46..16d1e2e6bb5 100644 --- a/source/blender/compositor/operations/COM_ConvertOperation.h +++ b/source/blender/compositor/operations/COM_ConvertOperation.h @@ -172,6 +172,26 @@ class ConvertHSVToRGBOperation : public ConvertBaseOperation { void update_memory_buffer_partial(BuffersIterator<float> &it) override; }; +class ConvertRGBToHSLOperation : public ConvertBaseOperation { + public: + ConvertRGBToHSLOperation(); + + void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; + + protected: + void update_memory_buffer_partial(BuffersIterator<float> &it) override; +}; + +class ConvertHSLToRGBOperation : public ConvertBaseOperation { + public: + ConvertHSLToRGBOperation(); + + void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override; + + protected: + void update_memory_buffer_partial(BuffersIterator<float> &it) override; +}; + class ConvertPremulToStraightOperation : public ConvertBaseOperation { public: ConvertPremulToStraightOperation(); |