34 b.add_input<
decl::Color>(
"Image").default_value({0.0f, 0.0f, 0.0f, 1.0f});
35 b.add_input<
decl::Float>(
"Alpha").default_value(1.0f).min(0.0f).max(1.0f);
40 ImageUser *iuser = MEM_cnew<ImageUser>(__func__);
41 node->storage = iuser;
61 if (!
context().use_composite_output() && !
context().is_valid_compositing_region()) {
67 if (image.is_single_value() && alpha.is_single_value()) {
73 else if (!
node().input_by_identifier(
"Alpha")->is_logically_linked()) {
88 float4 color = image.get_color_value();
92 else if (
node().input_by_identifier(
"Alpha")->is_logically_linked()) {
93 color.w = alpha.get_float_value();
98 domain, image.meta_data.is_non_color_data, image.precision());
99 if (this->
context().use_gpu()) {
103 parallel_for(domain.size, [&](
const int2 texel) { output.store_pixel(texel, color); });
123 domain, image.meta_data.is_non_color_data, image.precision());
132 image.bind_as_texture(shader,
"input_tx");
134 output.bind_as_image(shader,
"output_img");
138 image.unbind_as_texture();
139 output.unbind_as_image();
148 domain, image.meta_data.is_non_color_data, image.precision());
152 const int2 output_texel = texel + bounds.min;
153 if (output_texel.x > bounds.max.x || output_texel.y > bounds.max.y) {
156 output.store_pixel(texel + bounds.
min,
float4(image.load_pixel(texel).xyz(), 1.0f));
164 if (context().use_gpu()) {
165 this->execute_copy_gpu();
168 this->execute_copy_cpu();
175 const Domain domain = compute_domain();
176 Result output = context().get_viewer_output_result(
177 domain, image.meta_data.is_non_color_data, image.precision());
179 GPUShader *shader = context().get_shader(
"compositor_write_output", output.precision());
186 image.bind_as_texture(shader,
"input_tx");
188 output.bind_as_image(shader,
"output_img");
192 image.unbind_as_texture();
193 output.unbind_as_image();
199 const Domain domain = compute_domain();
201 Result output = context().get_viewer_output_result(
202 domain, image.meta_data.is_non_color_data, image.precision());
206 const int2 output_texel = texel + bounds.min;
207 if (output_texel.x > bounds.max.x || output_texel.y > bounds.max.y) {
210 output.store_pixel(texel + bounds.
min, image.load_pixel(texel));
217 if (context().use_gpu()) {
218 execute_set_alpha_gpu();
221 execute_set_alpha_cpu();
228 const Domain domain = compute_domain();
229 Result output = context().get_viewer_output_result(
230 domain, image.meta_data.is_non_color_data, image.precision());
232 GPUShader *shader = context().get_shader(
"compositor_write_output_alpha", output.precision());
239 image.bind_as_texture(shader,
"input_tx");
242 alpha.bind_as_texture(shader,
"alpha_tx");
244 output.bind_as_image(shader,
"output_img");
248 image.unbind_as_texture();
249 alpha.unbind_as_texture();
250 output.unbind_as_image();
256 const Domain domain = compute_domain();
259 Result output = context().get_viewer_output_result(
260 domain, image.meta_data.is_non_color_data, image.precision());
263 parallel_for(domain.size, [&](
const int2 texel) {
264 const int2 output_texel = texel + bounds.min;
265 if (output_texel.x > bounds.max.x || output_texel.y > bounds.max.y) {
268 output.store_pixel(texel +
bounds.min,
269 float4(image.load_pixel(texel).xyz(), alpha.load_pixel(texel).x));
279 if (context().use_composite_output()) {
283 const rcti compositing_region = context().get_compositing_region();
285 int2(compositing_region.
xmax, compositing_region.
ymax));
301 if (context().use_composite_output()) {
302 const Domain domain = NodeOperation::compute_domain();
304 return domain.size ==
int2(1) ?
Domain(context().get_compositing_region_size()) : domain;
307 return Domain(context().get_compositing_region_size());
326 ntype.
declare = file_ns::cmp_node_viewer_declare;
327 ntype.
draw_buttons = file_ns::node_composit_buts_viewer;
328 ntype.
initfunc = file_ns::node_composit_init_viewer;
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
#define NODE_CLASS_OUTPUT
@ CMP_NODE_OUTPUT_IGNORE_ALPHA
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
void GPU_shader_bind(GPUShader *shader)
void GPU_texture_clear(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
struct GPUShader GPUShader
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
void execute_ignore_alpha_gpu()
void execute_ignore_alpha_cpu()
void execute_set_alpha_gpu()
void execute_set_alpha_cpu()
Domain compute_domain() override
Bounds< int2 > get_output_bounds()
void execute_ignore_alpha()
virtual Result get_viewer_output_result(Domain domain, bool is_data, ResultPrecision precision)=0
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
NodeOperation(Context &context, DNode node)
const DNode & node() const
Result & get_input(StringRef identifier) const
Context & context() const
local_group_size(16, 16) .push_constant(Type b
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
void node_register_type(bNodeType *ntype)
static NodeOperation * get_compositor_operation(Context &context, DNode node)
static void node_composit_buts_viewer(uiLayout *layout, bContext *, PointerRNA *ptr)
static void cmp_node_viewer_declare(NodeDeclarationBuilder &b)
static void node_composit_init_viewer(bNodeTree *, bNode *node)
void parallel_for(const int2 range, FunctionRef< void(int2)> function)
void compute_dispatch_threads_at_least(GPUShader *shader, int2 threads_range, int2 local_size=int2(16))
void cmp_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void register_node_type_cmp_viewer()
void node_free_standard_storage(bNode *node)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
NodeGetCompositorOperationFunction get_compositor_operation
void(* initfunc)(bNodeTree *ntree, bNode *node)
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeDeclareFunction declare
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)