Compositor: Implement RGB Curves for new CPU compositor
Reference #125968.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "BLI_math_base.h"
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
|
||||
#include "FN_multi_function_builder.hh"
|
||||
@@ -141,6 +142,11 @@ static void node_buts_curvevec(uiLayout *layout, bContext * /*C*/, PointerRNA *p
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static CurveMapping *get_curve_mapping(const bNode &node)
|
||||
{
|
||||
return static_cast<CurveMapping *>(node.storage);
|
||||
}
|
||||
|
||||
class VectorCurvesShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -150,7 +156,7 @@ class VectorCurvesShaderNode : public ShaderNode {
|
||||
GPUNodeStack *inputs = get_inputs_array();
|
||||
GPUNodeStack *outputs = get_outputs_array();
|
||||
|
||||
CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
|
||||
CurveMapping *curve_mapping = get_curve_mapping(bnode());
|
||||
|
||||
BKE_curvemapping_init(curve_mapping);
|
||||
float *band_values;
|
||||
@@ -179,11 +185,6 @@ class VectorCurvesShaderNode : public ShaderNode {
|
||||
GPU_uniform(start_slopes),
|
||||
GPU_uniform(end_slopes));
|
||||
}
|
||||
|
||||
const CurveMapping *get_curve_mapping()
|
||||
{
|
||||
return static_cast<const CurveMapping *>(bnode().storage);
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -193,7 +194,7 @@ static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
|
||||
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
CurveMapping *curve_mapping = static_cast<CurveMapping *>(builder.node().storage);
|
||||
CurveMapping *curve_mapping = get_curve_mapping(builder.node());
|
||||
BKE_curvemapping_init(curve_mapping);
|
||||
|
||||
builder.construct_and_set_matching_fn_cb([=]() {
|
||||
@@ -261,6 +262,11 @@ static void node_composit_init_curve_rgb(bNodeTree * /*ntree*/, bNode *node)
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static CurveMapping *get_curve_mapping(const bNode &node)
|
||||
{
|
||||
return static_cast<CurveMapping *>(node.storage);
|
||||
}
|
||||
|
||||
class RGBCurvesShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -270,7 +276,7 @@ class RGBCurvesShaderNode : public ShaderNode {
|
||||
GPUNodeStack *inputs = get_inputs_array();
|
||||
GPUNodeStack *outputs = get_outputs_array();
|
||||
|
||||
CurveMapping *curve_mapping = const_cast<CurveMapping *>(get_curve_mapping());
|
||||
CurveMapping *curve_mapping = get_curve_mapping(bnode());
|
||||
|
||||
BKE_curvemapping_init(curve_mapping);
|
||||
float *band_values;
|
||||
@@ -342,11 +348,6 @@ class RGBCurvesShaderNode : public ShaderNode {
|
||||
GPU_uniform(start_slopes),
|
||||
GPU_uniform(end_slopes));
|
||||
}
|
||||
|
||||
const CurveMapping *get_curve_mapping()
|
||||
{
|
||||
return static_cast<const CurveMapping *>(bnode().storage);
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -356,15 +357,26 @@ static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
|
||||
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
/* Not yet implemented. Return zero. */
|
||||
static auto function = mf::build::SI4_SO<float, float4, float4, float4, float4>(
|
||||
"RGB Curves",
|
||||
[](const float /*factor*/,
|
||||
const float4 & /*color*/,
|
||||
const float4 & /*black*/,
|
||||
const float4 & /*white*/) -> float4 { return float4(0.0f); },
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
builder.set_matching_fn(function);
|
||||
CurveMapping *curve_mapping = get_curve_mapping(builder.node());
|
||||
BKE_curvemapping_init(curve_mapping);
|
||||
BKE_curvemapping_premultiply(curve_mapping, false);
|
||||
|
||||
builder.construct_and_set_matching_fn_cb([=]() {
|
||||
return mf::build::SI4_SO<float, float4, float4, float4, float4>(
|
||||
"RGB Curves",
|
||||
[=](const float factor, const float4 &color, const float4 &black, const float4 &white)
|
||||
-> float4 {
|
||||
float3 black_white_scale;
|
||||
BKE_curvemapping_set_black_white_ex(black, white, black_white_scale);
|
||||
|
||||
float3 result;
|
||||
BKE_curvemapping_evaluate_premulRGBF_ex(
|
||||
curve_mapping, result, color, black, black_white_scale);
|
||||
return float4(math::interpolate(color.xyz(), result, math::clamp(factor, 0.0f, 1.0f)),
|
||||
color.w);
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_composite_rgb_curves_cc
|
||||
|
||||
Reference in New Issue
Block a user