31 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
32 .compositor_domain_priority(0);
39 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
40 .compositor_domain_priority(1);
49 "Use the alpha of the first input as mixing factor and return the more opaque alpha of "
51 .compositor_expects_single_value();
55 "Anti-alias the generated mask before combining for smoother boundaries at the cost of "
56 "more expensive processing")
57 .compositor_expects_single_value();
71 if (this->
get_input(
"Image").is_single_value() &&
72 this->
get_input(
"Image_001").is_single_value() && this->
get_input(
"Z").is_single_value() &&
73 this->
get_input(
"Z_001").is_single_value())
97 const float z_combine_factor = float(first_z_value < second_z_value);
98 const float alpha_factor =
use_alpha() ? first_color.w : 1.0f;
99 const float mix_factor = z_combine_factor * alpha_factor;
105 combined_color.w =
use_alpha() ?
math::max(second_color.w, first_color.w) : combined_color.w;
113 const float combined_z_value =
math::interpolate(second_z_value, first_z_value, mix_factor);
121 if (this->
context().use_gpu()) {
131 if (this->
get_result(
"Image").should_compute()) {
142 GPUShader *shader = this->
context().
get_shader(
"compositor_z_combine_simple_image");
173 GPUShader *shader = this->
context().
get_shader(
"compositor_z_combine_simple_depth");
208 float4 first_color = first.load_pixel<float4, true>(texel);
209 float4 second_color = second.load_pixel<float4, true>(texel);
210 float first_z_value = first_z.load_pixel<float, true>(texel);
211 float second_z_value = second_z.load_pixel<float, true>(texel);
216 float4 foreground_color = first_z_value < second_z_value ? first_color : second_color;
217 float4 background_color = first_z_value < second_z_value ? second_color : first_color;
218 float mix_factor = use_alpha ? foreground_color.w : 1.0f;
219 float4 combined_color = math::interpolate(background_color, foreground_color, mix_factor);
222 combined_color.w = use_alpha ? math::max(second_color.w, first_color.w) : combined_color.w;
223 combined.store_pixel(texel, combined_color);
231 float first_z_value = first_z.load_pixel<float, true>(texel);
232 float second_z_value = second_z.load_pixel<float, true>(texel);
233 float combined_z = math::min(first_z_value, second_z_value);
234 combined_z_output.store_pixel(texel, combined_z);
247 if (this->
context().use_gpu()) {
259 if (this->
get_result(
"Image").should_compute()) {
270 GPUShader *shader = this->
context().
get_shader(
"compositor_z_combine_from_mask_image");
279 mask.bind_as_texture(shader,
"mask_tx");
290 mask.unbind_as_texture();
297 GPUShader *shader = this->
context().
get_shader(
"compositor_z_combine_from_mask_depth");
332 float4 first_color = first.load_pixel<float4, true>(texel);
333 float4 second_color = second.load_pixel<float4, true>(texel);
334 float mask_value = mask.load_pixel<float>(texel);
339 float4 foreground_color = math::interpolate(second_color, first_color, mask_value);
340 float4 background_color = math::interpolate(first_color, second_color, mask_value);
341 float mix_factor = use_alpha ? foreground_color.w : 1.0f;
342 float4 combined_color = math::interpolate(background_color, foreground_color, mix_factor);
345 combined_color.w = use_alpha ? math::max(second_color.w, first_color.w) : combined_color.w;
346 combined.store_pixel(texel, combined_color);
354 float first_z_value = first_z.load_pixel<float, true>(texel);
355 float second_z_value = second_z.load_pixel<float, true>(texel);
356 float combined_z = math::min(first_z_value, second_z_value);
357 combined_z_output.store_pixel(texel, combined_z);
364 if (this->
context().use_gpu()) {
383 mask.allocate_texture(domain);
384 mask.bind_as_image(shader,
"mask_img");
390 mask.unbind_as_image();
403 mask.allocate_texture(domain);
406 float first_z_value = first_z.load_pixel<float, true>(texel);
407 float second_z_value = second_z.load_pixel<float, true>(texel);
408 float z_combine_factor = float(first_z_value < second_z_value);
409 mask.store_pixel(texel, z_combine_factor);
444 ntype.
declare = file_ns::cmp_node_zcombine_declare;
#define NODE_CLASS_OP_COLOR
#define CMP_NODE_ZCOMBINE
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
Result create_result(ResultType type, ResultPrecision precision)
GPUShader * 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(Domain domain, bool from_pool=true)
void unbind_as_texture() const
void bind_as_texture(GPUShader *shader, const char *texture_name) const
void set_single_value(const T &value)
void bind_as_image(GPUShader *shader, const char *image_name, bool read=false) const
void unbind_as_image() const
void allocate_single_value()
const T & get_single_value() const
int compositor_domain_priority() const
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(GPUShader *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
void cmp_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
static void register_node_type_cmp_zcombine()
std::string ui_description
NodeGetCompositorOperationFunction get_compositor_operation
const char * enum_name_legacy
NodeDeclareFunction declare