@@ -6,6 +6,7 @@
|
||||
* \ingroup cmpnodes
|
||||
*/
|
||||
|
||||
#include "BLI_math_vector.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
|
||||
#include "FN_multi_function_builder.hh"
|
||||
@@ -55,6 +56,16 @@ static void node_composit_buts_invert(uiLayout *layout, bContext * /*C*/, Pointe
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static bool should_invert_rgb(const bNode &node)
|
||||
{
|
||||
return node.custom1 & CMP_CHAN_RGB;
|
||||
}
|
||||
|
||||
static bool should_invert_alpha(const bNode &node)
|
||||
{
|
||||
return node.custom1 & CMP_CHAN_A;
|
||||
}
|
||||
|
||||
class InvertShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -64,8 +75,8 @@ class InvertShaderNode : public ShaderNode {
|
||||
GPUNodeStack *inputs = get_inputs_array();
|
||||
GPUNodeStack *outputs = get_outputs_array();
|
||||
|
||||
const float do_rgb = get_do_rgb();
|
||||
const float do_alpha = get_do_alpha();
|
||||
const float do_rgb = should_invert_rgb(bnode());
|
||||
const float do_alpha = should_invert_alpha(bnode());
|
||||
|
||||
GPU_stack_link(material,
|
||||
&bnode(),
|
||||
@@ -75,16 +86,6 @@ class InvertShaderNode : public ShaderNode {
|
||||
GPU_constant(&do_rgb),
|
||||
GPU_constant(&do_alpha));
|
||||
}
|
||||
|
||||
bool get_do_rgb()
|
||||
{
|
||||
return bnode().custom1 & CMP_CHAN_RGB;
|
||||
}
|
||||
|
||||
bool get_do_alpha()
|
||||
{
|
||||
return bnode().custom1 & CMP_CHAN_A;
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -92,14 +93,63 @@ static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
return new InvertShaderNode(node);
|
||||
}
|
||||
|
||||
template<bool ShouldInvertRGB, bool ShouldInvertAlpha>
|
||||
static float4 invert(const float factor, const float4 &color)
|
||||
{
|
||||
float4 result = color;
|
||||
if constexpr (ShouldInvertRGB) {
|
||||
result = float4(1.0f - result.xyz(), result.w);
|
||||
}
|
||||
if constexpr (ShouldInvertAlpha) {
|
||||
result = float4(result.xyz(), 1.0f - result.w);
|
||||
}
|
||||
return math::interpolate(color, result, factor);
|
||||
}
|
||||
|
||||
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
/* Not yet implemented. Return zero. */
|
||||
static auto function = mf::build::SI2_SO<float, float4, float4>(
|
||||
"Invert",
|
||||
[](const float /*factor*/, const float4 & /*color*/) -> float4 { return float4(0.0f); },
|
||||
static auto rgb_alpha_function = mf::build::SI2_SO<float, float4, float4>(
|
||||
"Invert RGB Alpha",
|
||||
[](const float factor, const float4 &color) -> float4 {
|
||||
return invert<true, true>(factor, color);
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
builder.set_matching_fn(function);
|
||||
|
||||
static auto rgb_function = mf::build::SI2_SO<float, float4, float4>(
|
||||
"Invert RGB",
|
||||
[](const float factor, const float4 &color) -> float4 {
|
||||
return invert<true, false>(factor, color);
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
|
||||
static auto alpha_function = mf::build::SI2_SO<float, float4, float4>(
|
||||
"Invert Alpha",
|
||||
[](const float factor, const float4 &color) -> float4 {
|
||||
return invert<false, true>(factor, color);
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
|
||||
static auto identity_function = mf::build::SI2_SO<float, float4, float4>(
|
||||
"Identity",
|
||||
[](const float /*factor*/, const float4 &color) -> float4 { return color; },
|
||||
mf::build::exec_presets::SomeSpanOrSingle<1>());
|
||||
|
||||
if (should_invert_rgb(builder.node())) {
|
||||
if (should_invert_alpha(builder.node())) {
|
||||
builder.set_matching_fn(rgb_alpha_function);
|
||||
}
|
||||
else {
|
||||
builder.set_matching_fn(rgb_function);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (should_invert_alpha(builder.node())) {
|
||||
builder.set_matching_fn(alpha_function);
|
||||
}
|
||||
else {
|
||||
builder.set_matching_fn(identity_function);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_composite_invert_cc
|
||||
|
||||
Reference in New Issue
Block a user