34 .compositor_domain_priority(2);
36 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
37 .compositor_domain_priority(0);
39 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
40 .compositor_domain_priority(1);
44 "Defines whether the foreground is in straight alpha form, which is necessary to know "
45 "for proper alpha compositing. Images in the compositor are in premultiplied alpha form "
46 "by default, so this should be false in most cases. But if, and only if, the foreground "
47 "was converted to straight alpha form for some reason, this should be set to true");
67 const bool straight_alpha)
70 const float alpha =
math::clamp(foreground.w, 0.0f, 1.0f);
71 const float4 premultiplied_foreground =
float4(foreground.
xyz() * alpha, alpha);
72 const float4 foreground_color = straight_alpha ? premultiplied_foreground : foreground;
74 const float4 mix_result = background * (1.0f - alpha) + foreground_color;
80 static auto function = mf::build::SI4_SO<float, float4, float4, bool, float4>(
82 [=](
const float factor,
85 const bool straight_alpha) ->
float4 {
86 return alpha_over(factor, background, foreground, straight_alpha);
88 mf::build::exec_presets::SomeSpanOrSingle<1, 2>());
102 ntype.
ui_description =
"Overlay a foreground image onto a background image";
105 ntype.
declare = file_ns::cmp_node_alphaover_declare;
106 ntype.
gpu_fn = file_ns::node_gpu_material;
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ALPHAOVER
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 interpolate(const T &a, const T &b, const FactorT &t)
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
static int node_gpu_material(GPUMaterial *material, bNode *node, bNodeExecData *, GPUNodeStack *inputs, GPUNodeStack *outputs)
static float4 alpha_over(const float factor, const float4 &background, const float4 &foreground, const bool straight_alpha)
static void cmp_node_alphaover_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
static void register_node_type_cmp_alphaover()
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