Files
test2/source/blender/nodes/composite/nodes/node_composite_premulkey.cc
Omar Emara 440dc61db2 Compositor: Add stub implemenetation for CPU pixel nodes
This patch adds stub implementation for CPU pixel nodes in order to stop
those nodes from crashing when used while also easing future
development.

Pull Request: https://projects.blender.org/blender/blender/pulls/129033
2024-10-15 09:32:13 +02:00

97 lines
2.6 KiB
C++

/* SPDX-FileCopyrightText: 2006 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup cmpnodes
*/
#include "BLI_math_vector_types.hh"
#include "FN_multi_function_builder.hh"
#include "NOD_multi_function.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "GPU_material.hh"
#include "COM_shader_node.hh"
#include "node_composite_util.hh"
/* **************** Pre-multiply and Key Alpha Convert ******************** */
namespace blender::nodes::node_composite_premulkey_cc {
static void cmp_node_premulkey_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Color>("Image")
.default_value({1.0f, 1.0f, 1.0f, 1.0f})
.compositor_domain_priority(0);
b.add_output<decl::Color>("Image");
}
static void node_composit_buts_premulkey(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "mapping", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
}
using namespace blender::realtime_compositor;
class AlphaConvertShaderNode : public ShaderNode {
public:
using ShaderNode::ShaderNode;
void compile(GPUMaterial *material) override
{
GPUNodeStack *inputs = get_inputs_array();
GPUNodeStack *outputs = get_outputs_array();
if (get_mode() == 0) {
GPU_stack_link(material, &bnode(), "color_alpha_premultiply", inputs, outputs);
return;
}
GPU_stack_link(material, &bnode(), "color_alpha_unpremultiply", inputs, outputs);
}
CMPNodeAlphaConvertMode get_mode()
{
return (CMPNodeAlphaConvertMode)bnode().custom1;
}
};
static ShaderNode *get_compositor_shader_node(DNode node)
{
return new AlphaConvertShaderNode(node);
}
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
/* Not yet implemented. Return zero. */
static auto function = mf::build::SI1_SO<float4, float4>(
"Alpha Convert",
[](const float4 & /*color*/) -> float4 { return float4(0.0f); },
mf::build::exec_presets::AllSpanOrSingle());
builder.set_matching_fn(function);
}
} // namespace blender::nodes::node_composite_premulkey_cc
void register_node_type_cmp_premulkey()
{
namespace file_ns = blender::nodes::node_composite_premulkey_cc;
static blender::bke::bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_PREMULKEY, "Alpha Convert", NODE_CLASS_CONVERTER);
ntype.declare = file_ns::cmp_node_premulkey_declare;
ntype.draw_buttons = file_ns::node_composit_buts_premulkey;
ntype.get_compositor_shader_node = file_ns::get_compositor_shader_node;
ntype.build_multi_function = file_ns::node_build_multi_function;
blender::bke::node_register_type(&ntype);
}