25 N_(
"The foreground goes over the background according to the alpha of the foreground")},
30 N_(
"The foreground goes over the background according to the alpha of the foreground while "
31 "assuming the background is being held out by the foreground")},
36 N_(
"The foreground goes over the background according to the alpha of the foreground but the "
37 "foreground completely covers the background if it is more opaque")},
38 {0,
nullptr, 0,
nullptr,
nullptr},
44 b.add_input<
decl::Color>(
"Background").default_value({1.0f, 1.0f, 1.0f, 1.0f});
45 b.add_input<
decl::Color>(
"Foreground").default_value({1.0f, 1.0f, 1.0f, 1.0f});
58 "Defines whether the foreground is in straight alpha form, which is necessary to know "
59 "for proper alpha compositing. Images in the compositor are in premultiplied alpha form "
60 "by default, so this should be false in most cases. But if, and only if, the foreground "
61 "was converted to straight alpha form for some reason, this should be set to true");
78 const float alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
79 const float4 premultiplied_foreground =
float4(foreground.
xyz() * alpha, alpha);
80 return straight_alpha ? premultiplied_foreground : foreground;
87 const bool straight_alpha)
91 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
92 const float4 mix_result = foreground_color + background * (1.0f - foreground_alpha);
104 const bool straight_alpha)
108 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
109 const float background_alpha =
math::clamp(background.w, 0.0f, 1.0f);
111 if (foreground_alpha + background_alpha < 1.0f) {
112 const float4 mix_result = foreground_color + background;
117 const float4 mix_result = foreground_color + straight_background * (1.0f - foreground_alpha);
129 const bool straight_alpha)
133 const float foreground_alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
134 const float background_alpha =
math::clamp(background.w, 0.0f, 1.0f);
136 if (foreground_alpha > background_alpha) {
137 const float4 mix_result = foreground_color;
142 const float4 mix_result = foreground_color + background * (1.0f - alpha_ratio);
149 static auto function = mf::build::SI5_SO<float4, float4, float, MenuValue, bool, float4>(
151 [=](
const float4 &background,
155 const bool straight_alpha) ->
float4 {
158 return alpha_over(background, foreground, factor, straight_alpha);
166 mf::build::exec_presets::SomeSpanOrSingle<0, 1>());
177 ntype.
ui_description =
"Overlay a foreground image onto a background image";
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ALPHAOVER
CMPNodeAlphaOverOperationType
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_OVER
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_CONJOINT_OVER
@ CMP_NODE_ALPHA_OVER_OPERATION_TYPE_DISJOINT_OVER
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
void set_matching_fn(const mf::MultiFunction *fn)
void node_register_type(bNodeType &ntype)
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_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
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 register_node_type_cmp_alphaover()
static void node_declare(NodeDeclarationBuilder &b)
static float4 alpha_over_disjoint(const float4 &background, const float4 &foreground, const float factor, const bool straight_alpha)
VecBase< float, 4 > float4
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[]
VecBase< T, 3 > xyz() const
std::string ui_description
NodeGPUExecFunction gpu_fn
NodeMultiFunctionBuildFunction build_multi_function
const char * enum_name_legacy
NodeDeclareFunction declare