27 N_(
"The foreground goes over the background according to the alpha of the foreground")},
32 N_(
"The foreground goes over the background according to the alpha of the foreground while "
33 "assuming the background is being held out by the foreground")},
38 N_(
"The foreground goes over the background according to the alpha of the foreground but the "
39 "foreground completely covers the background if it is more opaque")},
40 {0,
nullptr, 0,
nullptr,
nullptr},
46 b.add_input<
decl::Color>(
"Background"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
47 b.add_input<
decl::Color>(
"Foreground"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
60 "Defines whether the foreground is in straight alpha form, which is necessary to know "
61 "for proper alpha compositing. Images in the compositor are in premultiplied alpha form "
62 "by default, so this should be false in most cases. But if, and only if, the foreground "
63 "was converted to straight alpha form for some reason, this should be set to true");
80 const float alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
81 const float4 premultiplied_foreground =
float4(foreground.xyz() * alpha, alpha);
82 return straight_alpha ? premultiplied_foreground : foreground;
89 const bool straight_alpha)
93 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
94 const float4 mix_result = foreground_color + background * (1.0f - foreground_alpha);
106 const bool straight_alpha)
110 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
111 const float background_alpha =
math::clamp(background.w, 0.0f, 1.0f);
113 if (foreground_alpha + background_alpha < 1.0f) {
114 const float4 mix_result = foreground_color + background;
119 const float4 mix_result = foreground_color + straight_background * (1.0f - foreground_alpha);
131 const bool straight_alpha)
135 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
136 const float background_alpha =
math::clamp(background.w, 0.0f, 1.0f);
138 if (foreground_alpha > background_alpha) {
139 const float4 mix_result = foreground_color;
144 const float4 mix_result = foreground_color + background * (1.0f - alpha_ratio);
153 static auto function = mf::build::SI5_SO<Color, Color, float, MenuValue, bool, Color>(
155 [=](
const Color &background,
156 const Color &foreground,
159 const bool straight_alpha) ->
Color {
166 float4(background),
float4(foreground), factor, straight_alpha));
169 float4(background),
float4(foreground), factor, straight_alpha));
173 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
184 ntype.
ui_description =
"Overlay a foreground image onto a background image";
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ALPHAOVER
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
ColorSceneLinear4f< eAlpha::Premultiplied > Color
T clamp(const T &a, const T &min, const T &max)
T safe_divide(const T &a, const T &b)
T interpolate(const T &a, const T &b, const FactorT &t)
static float4 preprocess_foreground(const float4 &foreground, const bool straight_alpha)
static void node_register()
static float4 alpha_over_conjoint(const float4 &background, const float4 &foreground, const float factor, const bool straight_alpha)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static float4 alpha_over(const float4 &background, const float4 &foreground, const float factor, const bool straight_alpha)
static const EnumPropertyItem type_items[]
static void node_declare(NodeDeclarationBuilder &b)
static float4 alpha_over_disjoint(const float4 &background, const float4 &foreground, const float factor, const bool straight_alpha)
static void node_build_multi_function(nodes::NodeMultiFunctionBuilder &builder)
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
VecBase< float, 4 > float4
CMPNodeAlphaOverOperationType
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_CONJOINT_OVER
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_DISJOINT_OVER
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_OVER
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare