30 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
31 .structure_type(StructureType::Dynamic);
33 StructureType::Dynamic);
35 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
36 .structure_type(StructureType::Dynamic);
38 StructureType::Dynamic);
42 "Use the alpha of the first input as mixing factor and return the more opaque alpha of "
47 "Anti-alias the generated mask before combining for smoother boundaries at the cost of "
48 "more expensive processing");
50 b.add_output<
decl::Color>(
"Result").structure_type(StructureType::Dynamic);
51 b.add_output<
decl::Float>(
"Depth").structure_type(StructureType::Dynamic);
62 if (this->
get_input(
"A").is_single_value() && this->
get_input(
"B").is_single_value() &&
63 this->
get_input(
"Depth A").is_single_value() &&
64 this->
get_input(
"Depth B").is_single_value())
89 const float z_combine_factor =
float(first_z_value < second_z_value);
90 const float alpha_factor =
use_alpha() ? first_color.w : 1.0f;
91 const float mix_factor = z_combine_factor * alpha_factor;
97 combined_color.w =
use_alpha() ?
math::max(second_color.w, first_color.w) : combined_color.w;
105 const float combined_z_value =
math::interpolate(second_z_value, first_z_value, mix_factor);
113 if (this->
context().use_gpu()) {
123 if (this->
get_result(
"Result").should_compute()) {
127 if (this->
get_result(
"Depth").should_compute()) {
200 float4 first_color = first.load_pixel<float4, true>(texel);
201 float4 second_color = second.load_pixel<float4, 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, 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()) {
271 mask.bind_as_texture(shader,
"mask_tx");
282 mask.unbind_as_texture();
324 float4 first_color = first.load_pixel<float4, true>(texel);
325 float4 second_color = second.load_pixel<float4, true>(texel);
326 float mask_value = mask.load_pixel<float>(texel);
331 float4 foreground_color = math::interpolate(second_color, first_color, mask_value);
332 float4 background_color = math::interpolate(first_color, second_color, mask_value);
333 float mix_factor = use_alpha ? foreground_color.w : 1.0f;
334 float4 combined_color = math::interpolate(background_color, foreground_color, mix_factor);
337 combined_color.w = use_alpha ? math::max(second_color.w, first_color.w) : combined_color.w;
338 combined.store_pixel(texel, combined_color);
346 float first_z_value = first_z.load_pixel<float, true>(texel);
347 float second_z_value = second_z.load_pixel<float, true>(texel);
348 float combined_z = math::min(first_z_value, second_z_value);
349 combined_z_output.store_pixel(texel, combined_z);
356 if (this->
context().use_gpu()) {
375 mask.allocate_texture(domain);
376 mask.bind_as_image(shader,
"mask_img");
382 mask.unbind_as_image();
395 mask.allocate_texture(domain);
398 float first_z_value = first_z.load_pixel<float, true>(texel);
399 float second_z_value = second_z.load_pixel<float, true>(texel);
400 float z_combine_factor = float(first_z_value < second_z_value);
401 mask.store_pixel(texel, z_combine_factor);
432 ntype.
ui_name =
"Depth Combine";
436 ntype.
declare = file_ns::cmp_node_zcombine_declare;
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ZCOMBINE
void GPU_shader_uniform_1b(blender::gpu::Shader *sh, const char *name, bool value)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
#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, DNode node)
Result & get_result(StringRef identifier)
Context & context() const
Result & get_input(StringRef identifier) const
virtual Domain compute_domain()
T get_single_value_default(const T &default_value) const
void allocate_texture(const Domain domain, const bool from_pool=true, const std::optional< ResultStorageType > storage_type=std::nullopt)
void unbind_as_texture() const
void set_single_value(const T &value)
void bind_as_texture(gpu::Shader *shader, const char *texture_name) 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
const T & get_single_value() const
StructureType structure_type
void execute_anti_aliased()
void execute_anti_aliased_gpu(const Result &mask)
void execute_simple_cpu()
Result compute_mask_cpu()
void execute_single_value()
void execute_anti_aliased_image_gpu(const Result &mask)
Result compute_mask_gpu()
void execute_anti_aliased_cpu(const Result &mask)
void execute_simple_depth_gpu()
void execute_simple_image_gpu()
void execute_simple_gpu()
void execute_anti_aliased_depth_gpu()
NodeOperation(Context &context, DNode node)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void node_register_type(bNodeType &ntype)
void compute_dispatch_threads_at_least(gpu::Shader *shader, int2 threads_range, int2 local_size=int2(16))
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 NodeOperation * get_compositor_operation(Context &context, DNode node)
static void cmp_node_zcombine_declare(NodeDeclarationBuilder &b)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
static void register_node_type_cmp_zcombine()
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare