Blender V5.0
node_composite_invert.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_vector.hh"
11
13
14#include "NOD_multi_function.hh"
15
16#include "UI_resources.hh"
17
18#include "GPU_material.hh"
19
21
22/* **************** INVERT ******************** */
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>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f}).hide_value();
32 b.add_output<decl::Color>("Color").align_with_previous();
33
34 b.add_input<decl::Float>("Factor", "Fac")
35 .default_value(1.0f)
36 .min(0.0f)
37 .max(1.0f)
39 b.add_input<decl::Bool>("Invert Color").default_value(true);
40 b.add_input<decl::Bool>("Invert Alpha").default_value(false);
41}
42
43using namespace blender::compositor;
44
45static int node_gpu_material(GPUMaterial *material,
46 bNode *node,
47 bNodeExecData * /*execdata*/,
50{
51 return GPU_stack_link(material, node, "node_composite_invert", inputs, outputs);
52}
53
55{
56 static auto function = mf::build::SI4_SO<float4, float, bool, bool, float4>(
57 "Invert Color",
58 [](const float4 &color, const float factor, const bool invert_color, const bool invert_alpha)
59 -> float4 {
61 if (invert_color) {
62 result = float4(1.0f - result.xyz(), result.w);
63 }
64 if (invert_alpha) {
65 result = float4(result.xyz(), 1.0f - result.w);
66 }
67 return math::interpolate(color, result, factor);
68 },
69 mf::build::exec_presets::SomeSpanOrSingle<0>());
70 builder.set_matching_fn(function);
71}
72
73} // namespace blender::nodes::node_composite_invert_cc
74
76{
78
79 static blender::bke::bNodeType ntype;
80
81 cmp_node_type_base(&ntype, "CompositorNodeInvert", CMP_NODE_INVERT);
82 ntype.ui_name = "Invert Color";
83 ntype.ui_description = "Invert colors, producing a negative";
84 ntype.enum_name_legacy = "INVERT";
86 ntype.declare = file_ns::cmp_node_invert_declare;
87 ntype.gpu_fn = file_ns::node_gpu_material;
88 ntype.build_multi_function = file_ns::node_build_multi_function;
89
91}
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define CMP_NODE_INVERT
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)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static void cmp_node_invert_declare(NodeDeclarationBuilder &b)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
VecBase< float, 4 > float4
static void register_node_type_cmp_invert()
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