22 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
23 .structure_type(StructureType::Dynamic);
30 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
31 .structure_type(StructureType::Dynamic);
40 "Use the alpha of the first input as mixing factor and return the more opaque alpha of "
45 "Anti-alias the generated mask before combining for smoother boundaries at the cost of "
46 "more expensive processing");
48 b.add_output<
decl::Color>(
"Result"_ustr).structure_type(StructureType::Dynamic);
49 b.add_output<
decl::Float>(
"Depth"_ustr).structure_type(StructureType::Dynamic);
60 if (this->
get_input(
"A").is_single_value() && this->
get_input(
"B").is_single_value() &&
61 this->
get_input(
"Depth A").is_single_value() &&
62 this->
get_input(
"Depth B").is_single_value())
87 const float z_combine_factor =
float(first_z_value < second_z_value);
88 const float alpha_factor =
use_alpha() ? first_color.w : 1.0f;
89 const float mix_factor = z_combine_factor * alpha_factor;
95 combined_color.w =
use_alpha() ?
math::max(second_color.w, first_color.w) : combined_color.w;
103 const float combined_z_value =
math::interpolate(second_z_value, first_z_value, mix_factor);
111 if (this->
context().use_gpu()) {
121 if (this->
get_result(
"Result").should_compute()) {
125 if (this->
get_result(
"Depth").should_compute()) {
188 const bool use_alpha = this->use_alpha();
200 float4 first_color = float4(first.load_pixel<Color, true>(texel));
201 float4 second_color = float4(second.load_pixel<Color, true>(texel));
202 float first_z_value = first_z.load_pixel<float, true>(texel);
203 float second_z_value = second_z.load_pixel<float, true>(texel);
208 float4 foreground_color = first_z_value < second_z_value ? first_color : second_color;
209 float4 background_color = first_z_value < second_z_value ? second_color : first_color;
210 float mix_factor = use_alpha ? foreground_color.w : 1.0f;
211 float4 combined_color = math::interpolate(background_color, foreground_color, mix_factor);
214 combined_color.w = use_alpha ? math::max(second_color.w, first_color.w) : combined_color.w;
215 combined.store_pixel(texel, Color(combined_color));
223 float first_z_value = first_z.load_pixel<float, true>(texel);
224 float second_z_value = second_z.load_pixel<float, true>(texel);
225 float combined_z = math::min(first_z_value, second_z_value);
226 combined_z_output.store_pixel(texel, combined_z);
239 if (this->
context().use_gpu()) {
251 if (this->
get_result(
"Result").should_compute()) {
255 if (this->
get_result(
"Depth").should_compute()) {
282 mask.unbind_as_texture();
313 const bool use_alpha = this->use_alpha();
325 float4 first_color = float4(first.load_pixel<Color, true>(texel));
326 float4 second_color = float4(second.load_pixel<Color, true>(texel));
327 float mask_value = mask.load_pixel<float>(texel);
332 float4 foreground_color = math::interpolate(second_color, first_color, mask_value);
333 float4 background_color = math::interpolate(first_color, second_color, mask_value);
334 float mix_factor = use_alpha ? foreground_color.w : 1.0f;
335 float4 combined_color = math::interpolate(background_color, foreground_color, mix_factor);
338 combined_color.w = use_alpha ? math::max(second_color.w, first_color.w) : combined_color.w;
339 combined.store_pixel(texel, Color(combined_color));
347 float first_z_value = first_z.load_pixel<float, true>(texel);
348 float second_z_value = second_z.load_pixel<float, true>(texel);
349 float combined_z = math::min(first_z_value, second_z_value);
350 combined_z_output.store_pixel(texel, combined_z);
357 if (this->
context().use_gpu()) {
377 mask.allocate_texture(domain);
384 mask.unbind_as_image();
397 mask.allocate_texture(domain);
400 float first_z_value = first_z.load_pixel<float, true>(texel);
401 float second_z_value = second_z.load_pixel<float, true>(texel);
402 float z_combine_factor = float(first_z_value < second_z_value);
403 mask.store_pixel(texel, z_combine_factor);
430 ntype.
ui_name =
"Depth Combine";
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ZCOMBINE
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result create_result(ResultType type, ResultPrecision precision)
gpu::Shader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, const bNode &node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
void unbind_as_texture_or_single_value(gpu::Texture *single_value_texture) const
bool should_compute() const
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void set_single_value(const T &value)
T get_single_value_default() const
void unbind_as_image() const
void allocate_single_value()
void bind_as_image(gpu::Shader *shader, const char *image_name, bool read=false) const
gpu::Texture * bind_as_texture_or_single_value(gpu::Shader *shader, const char *texture_name) const
const T & get_single_value() const
StructureType structure_type
NodeOperation(Context &context, const bNode &node)
void execute_anti_aliased_image_gpu(const Result &mask)
void execute_anti_aliased_cpu(const Result &mask)
void execute_anti_aliased()
void execute_single_value()
void execute_simple_gpu()
Result compute_mask_cpu()
void execute_anti_aliased_gpu(const Result &mask)
void execute_simple_depth_gpu()
Result compute_mask_gpu()
void execute_anti_aliased_depth_gpu()
void execute_simple_image_gpu()
void execute_simple_cpu()
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
ColorSceneLinear4f< eAlpha::Premultiplied > Color
void smaa(Context &context, const Result &input, Result &output, const float threshold=0.1f, const float local_contrast_adaptation_factor=2.0f, const int corner_rounding=25)
void parallel_for(const int2 range, const Function &function)
T interpolate(const T &a, const T &b, const FactorT &t)
T max(const T &a, const T &b)
static void node_register()
static void node_declare(NodeDeclarationBuilder &b)
static NodeOperation * get_compositor_operation(Context &context, const bNode &node)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void cmp_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare