Files
test2/source/blender/compositor/operations/COM_ViewerOperation.h
Sergey Sharybin 1b18e07232 Fix #121480: Cryptomatte shows some objects as black
The issue originates to the change in default view transform from Filmic
to AgX, which does slightly different clipping, and clips color to black
if there is any negative values.

This change implements an idea of skipping view transform for viewer
node when it is connected to the Pick output of the cryptomatte node.
It actually goes a bit deeper than this and any operation can tag its
result as a non-color data, and the viewer node will respect that.
It is achieved by passing some extra meta-data along the evaluation
pipeline. For the CPU compositor it is done via MetaData, and for the
GPU compositor it is done as part of Result.

Connecting any other node in-between of viewer and Cryptomatte's Pick
will treat the result as color values, and apply color management.

Connecting Pick to the Composite output will also consider it as color,
since there is no concept of non-color-managed render result.

An alternative approaches were tested, including:

- Doing negative value clamping at the viewer node.
  It does not work for legacy cryptomatte node, as it needs to have
  access to original non-modified Pick result.

- Change the order of components, and store ID in another channel.

  Using one of other of Green or Blue channels might work for some view
  transforms, but it does not work for AgX.

  Using Alpha channel seemingly works better, but it is has different
  issues caused by the fact that display transform de-associates alpha,
  leading to over-exposed regions which are hard to see in the file from
  the report. And might lead to the similar issues as the initial report
  with other objects or view transforms.

- Use positive values in the Pick channel.

  It does make things visible, but they are all white due to the nature
  of how AgX works, making it not so useful as a result.

Pull Request: https://projects.blender.org/blender/blender/pulls/122177
2024-05-24 17:25:57 +02:00

97 lines
2.3 KiB
C++

/* SPDX-FileCopyrightText: 2011 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BKE_global.hh"
#include "BLI_rect.h"
#include "COM_MultiThreadedOperation.h"
#include "DNA_image_types.h"
namespace blender::compositor {
class ViewerOperation : public MultiThreadedOperation {
private:
/* TODO(manzanilla): To be removed together with tiled implementation. */
float *output_buffer_;
Image *image_;
ImageUser *image_user_;
bool active_;
ImBuf *ibuf_;
bool use_alpha_input_;
const RenderData *rd_;
const char *view_name_;
const ColorManagedViewSettings *view_settings_;
const ColorManagedDisplaySettings *display_settings_;
public:
ViewerOperation();
void init_execution() override;
void deinit_execution() override;
void determine_canvas(const rcti &preferred_area, rcti &r_area) override;
bool is_output_operation(bool /*rendering*/) const override
{
if (G.background) {
return false;
}
return is_active_viewer_output();
}
void set_image(Image *image)
{
image_ = image;
}
void set_image_user(ImageUser *image_user)
{
image_user_ = image_user;
}
bool is_active_viewer_output() const override
{
return active_;
}
void set_active(bool active)
{
active_ = active;
}
eCompositorPriority get_render_priority() const override;
void set_use_alpha_input(bool value)
{
use_alpha_input_ = value;
}
void set_render_data(const RenderData *rd)
{
rd_ = rd;
}
void set_view_name(const char *view_name)
{
view_name_ = view_name;
}
void set_view_settings(const ColorManagedViewSettings *view_settings)
{
view_settings_ = view_settings;
}
void set_display_settings(const ColorManagedDisplaySettings *display_settings)
{
display_settings_ = display_settings;
}
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
void update_memory_buffer_finished(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
void clear_display_buffer();
private:
void update_image(const rcti *rect);
void init_image();
};
} // namespace blender::compositor